]> git.sesse.net Git - vlc/blob - modules/audio_filter/gain.c
Check for SSE2 at build-time if possible
[vlc] / modules / audio_filter / gain.c
1 /*****************************************************************************
2  * gain.c : gain control filter
3  *****************************************************************************
4  * Copyright © 2012 VLC authors and VideoLAN
5  *
6  * Authors: Ludovic Fauvet <etix@videolan.org>
7  *
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.
12  *
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.
17  *
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  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_aout.h>
33 #include <vlc_aout_volume.h>
34 #include <vlc_filter.h>
35 #include <vlc_modules.h>
36 #include <vlc_plugin.h>
37
38
39 /*****************************************************************************
40  * Local prototypes
41  *****************************************************************************/
42
43 static int      Open        ( vlc_object_t * );
44 static void     Close       ( vlc_object_t * );
45 static block_t  *Process    ( filter_t *, block_t * );
46
47 struct filter_sys_t
48 {
49     audio_volume_t volume;
50     float f_gain;
51     module_t *module;
52 };
53
54 /*****************************************************************************
55  * Module descriptor
56  *****************************************************************************/
57
58 #define GAIN_VALUE_TEXT N_( "Gain multiplier" )
59 #define GAIN_VALUE_LONGTEXT N_( "Increase or decrease the gain (default 1.0)" )
60
61 vlc_module_begin()
62     set_shortname( N_("Gain") )
63     set_description( N_("Gain control filter") )
64     set_category( CAT_AUDIO )
65     set_subcategory( SUBCAT_AUDIO_AFILTER )
66
67     add_float( "gain-value", 1.0, GAIN_VALUE_TEXT,
68                GAIN_VALUE_LONGTEXT, false )
69
70     set_capability( "audio filter", 0 )
71     set_callbacks( Open, Close )
72 vlc_module_end()
73
74
75 /*****************************************************************************
76  * Open: initialize filter
77  *****************************************************************************/
78
79 static int Open( vlc_object_t *p_this )
80 {
81     filter_t *p_filter = (filter_t *)p_this;
82     filter_sys_t *p_sys;
83
84     if ( !AOUT_FMTS_IDENTICAL( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
85     {
86         msg_Warn( p_filter, "bad input or output format" );
87         return VLC_EGENERIC;
88     }
89
90     p_sys = vlc_object_create( p_this, sizeof( *p_sys ) );
91     if( unlikely( p_sys == NULL ) )
92         return VLC_ENOMEM;
93
94     p_filter->p_sys = p_sys;
95     p_sys->volume.format = p_filter->fmt_in.audio.i_format;
96     p_sys->module = module_need( &p_sys->volume, "audio volume", NULL, false );
97     if( p_sys->module == NULL )
98     {
99         msg_Warn( p_filter, "unsupported format" );
100         vlc_object_release( &p_sys->volume );
101         return VLC_EGENERIC;
102     }
103
104     p_sys->f_gain = var_InheritFloat( p_filter->p_parent, "gain-value" );
105     msg_Dbg( p_filter, "gain multiplier sets to %.2fx", p_sys->f_gain );
106
107     p_filter->pf_audio_filter = Process;
108     return VLC_SUCCESS;
109 }
110
111
112 /*****************************************************************************
113  * Process: process samples buffer
114  *****************************************************************************/
115
116 static block_t *Process( filter_t *p_filter, block_t *p_block )
117 {
118     filter_sys_t *p_sys = p_filter->p_sys;
119
120     p_sys->volume.amplify( &p_sys->volume, p_block, p_sys->f_gain );
121     return p_block;
122 }
123
124
125 /*****************************************************************************
126  * Close: close filter
127  *****************************************************************************/
128
129 static void Close( vlc_object_t *p_this )
130 {
131     filter_t *p_filter = (filter_t*)p_this;
132     filter_sys_t *p_sys = p_filter->p_sys;
133
134     module_unneed( &p_sys->volume, p_sys->module );
135     vlc_object_release( &p_sys->volume );
136 }