2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* Copyright (C) 2009 Jonathan Moore Liles */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
|
/* Free Software Foundation; either version 2 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 General Public License for */
|
|
|
|
|
/* more details. */
|
|
|
|
|
/* */
|
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <dsp.h>
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include "Gain_Module.H"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
Gain_Module::Gain_Module ( )
|
|
|
|
|
: Module ( 50, 24, name() )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
|
|
|
|
add_port( Port( this, Port::INPUT, Port::AUDIO ) );
|
|
|
|
|
add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
|
|
|
|
|
|
2010-01-12 06:48:08 +01:00
|
|
|
|
Port p( this, Port::INPUT, Port::CONTROL, "Gain (dB)" );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
p.hints.type = Port::Hints::LOGARITHMIC;
|
|
|
|
|
p.hints.ranged = true;
|
2010-01-12 06:48:08 +01:00
|
|
|
|
p.hints.minimum = -70.0f;
|
|
|
|
|
p.hints.maximum = 6.0f;
|
|
|
|
|
p.hints.default_value = 0.0f;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
p.connect_to( new float );
|
2010-01-12 06:48:08 +01:00
|
|
|
|
p.control_value( p.hints.default_value );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
add_port( p );
|
|
|
|
|
|
|
|
|
|
end();
|
2009-12-28 06:25:28 +01:00
|
|
|
|
|
|
|
|
|
log_create();
|
2013-06-16 02:51:50 +02:00
|
|
|
|
|
|
|
|
|
smoothing.sample_rate( sample_rate() );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Gain_Module::~Gain_Module ( )
|
|
|
|
|
{
|
2010-01-12 03:31:15 +01:00
|
|
|
|
delete (float*)control_input[0].buffer();
|
2009-12-28 06:25:28 +01:00
|
|
|
|
log_destroy();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Gain_Module::configure_inputs ( int n )
|
|
|
|
|
{
|
|
|
|
|
audio_input.clear();
|
|
|
|
|
audio_output.clear();
|
|
|
|
|
// control_input.clear();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < n; ++i )
|
|
|
|
|
{
|
|
|
|
|
add_port( Port( this, Port::INPUT, Port::AUDIO ) );
|
|
|
|
|
add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 02:51:50 +02:00
|
|
|
|
void
|
|
|
|
|
Gain_Module::handle_sample_rate_change ( nframes_t n )
|
|
|
|
|
{
|
|
|
|
|
smoothing.sample_rate( n );
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
/**********/
|
|
|
|
|
/* Engine */
|
|
|
|
|
/**********/
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
void
|
2010-01-30 09:35:32 +01:00
|
|
|
|
Gain_Module::process ( nframes_t nframes )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2013-06-16 02:51:50 +02:00
|
|
|
|
const float gt = DB_CO( control_input[0].control_value() );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2013-06-27 08:49:29 +02:00
|
|
|
|
sample_t gainbuf[nframes];
|
|
|
|
|
|
|
|
|
|
bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt );
|
2013-06-16 02:51:50 +02:00
|
|
|
|
|
2013-06-27 08:49:29 +02:00
|
|
|
|
if ( use_gainbuf )
|
|
|
|
|
{
|
|
|
|
|
|
2013-06-16 02:51:50 +02:00
|
|
|
|
for ( int i = audio_input.size(); i--; )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2013-06-16 02:51:50 +02:00
|
|
|
|
if ( audio_input[i].connected() && audio_output[i].connected() )
|
|
|
|
|
{
|
|
|
|
|
sample_t *out = (sample_t*)audio_input[i].buffer();
|
|
|
|
|
|
|
|
|
|
buffer_apply_gain_buffer( out, gainbuf, nframes );
|
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-16 02:51:50 +02:00
|
|
|
|
else
|
|
|
|
|
for ( int i = audio_input.size(); i--; )
|
|
|
|
|
{
|
|
|
|
|
if ( audio_input[i].connected() && audio_output[i].connected() )
|
|
|
|
|
{
|
|
|
|
|
buffer_apply_gain( (sample_t*)audio_input[i].buffer(), nframes, gt );
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|