1 /*****************************************************************************
2 * gain.c : gain control filter
3 *****************************************************************************
4 * Copyright © 2012 VLC authors and VideoLAN
6 * Authors: Ludovic Fauvet <etix@videolan.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
31 #include <vlc_common.h>
33 #include <vlc_aout_volume.h>
34 #include <vlc_filter.h>
35 #include <vlc_modules.h>
36 #include <vlc_plugin.h>
39 /*****************************************************************************
41 *****************************************************************************/
43 static int Open ( vlc_object_t
* );
44 static void Close ( vlc_object_t
* );
45 static block_t
*Process ( filter_t
*, block_t
* );
49 audio_volume_t volume
;
54 /*****************************************************************************
56 *****************************************************************************/
58 #define GAIN_VALUE_TEXT N_( "Gain multiplier" )
59 #define GAIN_VALUE_LONGTEXT N_( "Increase or decrease the gain (default 1.0)" )
62 set_shortname( N_("Gain") )
63 set_description( N_("Gain control filter") )
64 set_category( CAT_AUDIO
)
65 set_subcategory( SUBCAT_AUDIO_AFILTER
)
67 add_float( "gain-value", 1.0, GAIN_VALUE_TEXT
,
68 GAIN_VALUE_LONGTEXT
, false )
70 set_capability( "audio filter", 0 )
71 set_callbacks( Open
, Close
)
75 /*****************************************************************************
76 * Open: initialize filter
77 *****************************************************************************/
79 static int Open( vlc_object_t
*p_this
)
81 filter_t
*p_filter
= (filter_t
*)p_this
;
82 filter_sys_t
*p_sys
= vlc_object_create( p_this
, sizeof( *p_sys
) );
83 if( unlikely( p_sys
== NULL
) )
86 p_filter
->p_sys
= p_sys
;
87 p_sys
->volume
.format
= p_filter
->fmt_in
.audio
.i_format
;
88 p_sys
->module
= module_need( &p_sys
->volume
, "audio volume", NULL
, false );
89 if( p_sys
->module
== NULL
)
91 msg_Warn( p_filter
, "unsupported format" );
92 vlc_object_release( &p_sys
->volume
);
96 p_sys
->f_gain
= var_InheritFloat( p_filter
->obj
.parent
, "gain-value" );
97 msg_Dbg( p_filter
, "gain multiplier sets to %.2fx", p_sys
->f_gain
);
99 p_filter
->fmt_out
.audio
= p_filter
->fmt_in
.audio
;
100 p_filter
->pf_audio_filter
= Process
;
105 /*****************************************************************************
106 * Process: process samples buffer
107 *****************************************************************************/
109 static block_t
*Process( filter_t
*p_filter
, block_t
*p_block
)
111 filter_sys_t
*p_sys
= p_filter
->p_sys
;
113 p_sys
->volume
.amplify( &p_sys
->volume
, p_block
, p_sys
->f_gain
);
118 /*****************************************************************************
119 * Close: close filter
120 *****************************************************************************/
122 static void Close( vlc_object_t
*p_this
)
124 filter_t
*p_filter
= (filter_t
*)p_this
;
125 filter_sys_t
*p_sys
= p_filter
->p_sys
;
127 module_unneed( &p_sys
->volume
, p_sys
->module
);
128 vlc_object_release( &p_sys
->volume
);