[vlc-devel] [PATCH 2/2] Add a trivial audio gain filter
Ludovic Fauvet
etix at videolan.org
Wed Mar 28 16:27:49 CEST 2012
2012/3/28 Rémi Denis-Courmont <remi at remlab.net>:
> On Wed, 28 Mar 2012 14:58:03 +0200, Ludovic Fauvet <etix at videolan.org>
> wrote:
>> This module is only a wrapper around an audio mixer (which is actually
>> more a volume plugin by now).
>
> Feel free to update the capability name.
This is not directly related to this module so if you don't mind I'll
submit a new patch later to cleanup the mixer/volume capability.
I'm not sure that modifying the capability name without changing all
the associated stuff (mostly the audio_mixer directory and function
names) is very clean.
>> ---
>> modules/LIST | 1 +
>> modules/audio_filter/Modules.am | 2 +
>> modules/audio_filter/gain.c | 134
>> +++++++++++++++++++++++++++++++++++++++
>> po/POTFILES.in | 1 +
>> 4 files changed, 138 insertions(+)
>> create mode 100644 modules/audio_filter/gain.c
>>
>> diff --git a/modules/LIST b/modules/LIST
>> index 2e14e13..4f4cda9 100644
>> --- a/modules/LIST
>> +++ b/modules/LIST
>> @@ -130,6 +130,7 @@ $Id$
>> * fluidsynth: Software MIDI synthetizer using libfluidsynth
>> * folder: folder meta data and art finder
>> * freetype: Utility to put text on video using freetype2
>> + * gain: Gain audio filter
>> * gaussianblur: gaussian blur video filter
>> * gestures: mouse gestures control plugin
>> * gl: OpenGL video output using the generic OpenGL provider
>> diff --git a/modules/audio_filter/Modules.am
>> b/modules/audio_filter/Modules.am
>> index 90e7661..0c9b145 100644
>> --- a/modules/audio_filter/Modules.am
>> +++ b/modules/audio_filter/Modules.am
>> @@ -2,6 +2,7 @@ SOURCES_equalizer = equalizer.c equalizer_presets.h
>> SOURCES_compressor = compressor.c
>> SOURCES_karaoke = karaoke.c
>> SOURCES_normvol = normvol.c
>> +SOURCES_gain = gain.c
>> SOURCES_audiobargraph_a = audiobargraph_a.c
>> SOURCES_param_eq = param_eq.c
>> SOURCES_scaletempo = scaletempo.c
>> @@ -22,6 +23,7 @@ libvlc_LTLIBRARIES += \
>> libequalizer_plugin.la \
>> libkaraoke_plugin.la \
>> libnormvol_plugin.la \
>> + libgain_plugin.la \
>
> Looks like inconsistent indentation.
Indeed, I messed up here.
>
>> libparam_eq_plugin.la \
>> libscaletempo_plugin.la \
>> libspatializer_plugin.la \
>> diff --git a/modules/audio_filter/gain.c b/modules/audio_filter/gain.c
>> new file mode 100644
>> index 0000000..cd31ee6
>> --- /dev/null
>> +++ b/modules/audio_filter/gain.c
>> @@ -0,0 +1,134 @@
>>
> +/*****************************************************************************
>> + * gain.c : gain control filter
>> +
>>
> *****************************************************************************
>> + * Copyright © 2012 VLC authors and VideoLAN
>> + *
>> + * Authors: Ludovic Fauvet <etix at videolan.org>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
> it
>> + * under the terms of the GNU Lesser General Public License as
> published
>> by
>> + * the Free Software Foundation; either version 2.1 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> License
>> + * along with this program; if not, write to the Free Software
> Foundation,
>> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
>> +
>>
> *****************************************************************************/
>> +
>>
> +/*****************************************************************************
>> + * Preamble
>> +
>>
> *****************************************************************************/
>> +
>> +#ifdef HAVE_CONFIG_H
>> +# include "config.h"
>> +#endif
>> +
>> +#include <vlc_common.h>
>> +#include <vlc_aout.h>
>> +#include <vlc_aout_mixer.h>
>> +#include <vlc_filter.h>
>> +#include <vlc_plugin.h>
>> +
>> +
>>
> +/*****************************************************************************
>> + * Local prototypes
>> +
>>
> *****************************************************************************/
>> +
>> +static int Open ( vlc_object_t * );
>> +static void Close ( vlc_object_t * );
>> +static block_t *Process ( filter_t *, block_t * );
>> +
>> +struct filter_sys_t
>> +{
>> + float f_gain;
>> + audio_mixer_t* p_mixer;
>> +};
>> +
>> +
>>
> +/*****************************************************************************
>> + * Module descriptor
>> +
>>
> *****************************************************************************/
>> +
>> +#define GAIN_VALUE_TEXT N_( "Gain multiplier" )
>> +#define GAIN_VALUE_LONGTEXT N_( "Increase or decrease the gain (default
>> 1.0)" )
>> +
>> +vlc_module_begin()
>> + set_shortname( _("Gain") )
>> + set_description( _("Gain control filter") )
>
> You cannot call gettext here. This will corrupt the cache.
Yes, same as above.
>
>> + set_category( CAT_AUDIO )
>> + set_subcategory( SUBCAT_AUDIO_AFILTER )
>> +
>> + add_float( "gain-value", 1.0, GAIN_VALUE_TEXT,
>> + GAIN_VALUE_LONGTEXT, false )
>> +
>> + set_capability( "audio filter", 0 )
>> + set_callbacks( Open, Close )
>> +vlc_module_end()
>> +
>> +
>>
> +/*****************************************************************************
>> + * Open: initialize filter
>> +
>>
> *****************************************************************************/
>> +
>> +static int Open( vlc_object_t *p_this )
>> +{
>> + filter_t *p_filter = (filter_t *)p_this;
>> + filter_sys_t *p_sys;
>> +
>> + if ( !AOUT_FMTS_IDENTICAL( &p_filter->fmt_in.audio,
>> &p_filter->fmt_out.audio ) )
>> + {
>> + msg_Warn( p_filter, "bad input or output format" );
>> + return VLC_EGENERIC;
>> + }
>> +
>> + p_sys = p_filter->p_sys = calloc( 1, sizeof( *p_sys ) );
>
> Please use malloc().
Ok.
>
>> + if( !p_sys )
>> + return VLC_ENOMEM;
>> +
>> + p_sys->p_mixer = aout_MixerNew( p_this,
>> p_filter->fmt_in.audio.i_format );
>> + if( !p_sys->p_mixer )
>> + {
>> + msg_Warn( p_filter, "can't construct a mixer" );
>
> "unsupported format" something is probably more clear.
Indeed.
>
>> + free( p_sys );
>> + return VLC_EGENERIC;
>> + }
>> +
>> + p_sys->f_gain = var_InheritFloat( p_filter->p_parent, "gain-value"
> );
>> + msg_Dbg( p_filter, "gain multiplier sets to %.2fx", p_sys->f_gain
> );
>> +
>> + p_filter->pf_audio_filter = Process;
>> + return VLC_SUCCESS;
>> +}
>> +
>> +
>>
> +/*****************************************************************************
>> + * Process: process samples buffer
>> +
>>
> *****************************************************************************/
>> +
>> +static block_t *Process( filter_t *p_filter, block_t *p_block )
>> +{
>> + filter_sys_t *p_sys = p_filter->p_sys;
>> +
>> + aout_MixerRun( p_sys->p_mixer, p_block, p_sys->f_gain );
>> +
>> + return p_block;
>> +}
>> +
>> +
>>
> +/*****************************************************************************
>> + * Close: close filter
>> +
>>
> *****************************************************************************/
>> +
>> +static void Close( vlc_object_t *p_this )
>> +{
>> + filter_t *p_filter = (filter_t*)p_this;
>> + filter_sys_t *p_sys = p_filter->p_sys;
>> +
>> + aout_MixerDelete( p_sys->p_mixer );
>> + free( p_sys );
>> +}
>> diff --git a/po/POTFILES.in b/po/POTFILES.in
>> index ba47415..3c74b16 100644
>> --- a/po/POTFILES.in
>> +++ b/po/POTFILES.in
>> @@ -308,6 +308,7 @@ modules/audio_filter/converter/format.c
>> modules/audio_filter/converter/mpgatofixed32.c
>> modules/audio_filter/equalizer.c
>> modules/audio_filter/equalizer_presets.h
>> +modules/audio_filter/gain.c
>> modules/audio_filter/karaoke.c
>> modules/audio_filter/normvol.c
>> modules/audio_filter/param_eq.c
>
> --
> Rémi Denis-Courmont
> Sent from my collocated server
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> http://mailman.videolan.org/listinfo/vlc-devel
--
Ludovic Fauvet
More information about the vlc-devel
mailing list