demux: libmp4: add and parse 3DDS uuid
[vlc.git] / modules / audio_filter / gain.c
blobb03ef4dc4019d453d35afde37562a9a8a2256c17
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 /*****************************************************************************
24 * Preamble
25 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
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>
39 /*****************************************************************************
40 * Local prototypes
41 *****************************************************************************/
43 static int Open ( vlc_object_t * );
44 static void Close ( vlc_object_t * );
45 static block_t *Process ( filter_t *, block_t * );
47 struct filter_sys_t
49 audio_volume_t volume;
50 float f_gain;
51 module_t *module;
54 /*****************************************************************************
55 * Module descriptor
56 *****************************************************************************/
58 #define GAIN_VALUE_TEXT N_( "Gain multiplier" )
59 #define GAIN_VALUE_LONGTEXT N_( "Increase or decrease the gain (default 1.0)" )
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 )
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 )
72 vlc_module_end()
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 ) )
84 return VLC_ENOMEM;
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 );
93 return VLC_EGENERIC;
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;
101 return VLC_SUCCESS;
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 );
114 return p_block;
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 );