Update NTK.
[nondaw.git] / mixer / src / Gain_Module.C
blobe83316ad5dd28ff19ead681c02c1cbde044740ea
2 /*******************************************************************************/
3 /* Copyright (C) 2009 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 #include <math.h>
21 #include <dsp.h>
23 #include "Gain_Module.H"
27 Gain_Module::Gain_Module ( )
28     : Module ( 50, 24, name() )
30     add_port( Port( this, Port::INPUT, Port::AUDIO ) );
31     add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
33     Port p( this, Port::INPUT, Port::CONTROL, "Gain (dB)" );
34     p.hints.type = Port::Hints::LOGARITHMIC;
35     p.hints.ranged = true;
36     p.hints.minimum = -70.0f;
37     p.hints.maximum = 6.0f;
38     p.hints.default_value = 0.0f;
40     p.connect_to( new float );
41     p.control_value( p.hints.default_value );
43     add_port( p );
45     end();
47     log_create();
50 Gain_Module::~Gain_Module ( )
52     delete (float*)control_input[0].buffer();
53     log_destroy();
58 bool
59 Gain_Module::configure_inputs ( int n )
61     audio_input.clear();
62     audio_output.clear();
63 //    control_input.clear();
65     for ( int i = 0; i < n; ++i )
66     {
67         add_port( Port( this, Port::INPUT, Port::AUDIO ) );
68         add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
69     }
71     return true;
76 /**********/
77 /* Engine */
78 /**********/
80 void
81 Gain_Module::process ( nframes_t nframes )
83     float g = DB_CO( control_input[0].control_value() );
85     for ( int i = audio_input.size(); i--; )
86     {
87         if ( audio_input[i].connected() && audio_output[i].connected() )
88         {
89             buffer_apply_gain( (sample_t*)audio_input[i].buffer(), nframes, g );
90         }
91     }