2010-01-18 04:16:31 +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. */
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include "const.h"
|
2010-01-18 04:16:31 +01:00
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <dsp.h>
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include "Mono_Pan_Module.H"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-18 04:16:31 +01:00
|
|
|
|
Mono_Pan_Module::Mono_Pan_Module ( )
|
|
|
|
|
: Module ( 50, 24, name() )
|
|
|
|
|
{
|
|
|
|
|
Port p( this, Port::INPUT, Port::CONTROL, "Pan" );
|
|
|
|
|
p.hints.ranged = true;
|
|
|
|
|
p.hints.minimum = -1.0f;
|
|
|
|
|
p.hints.maximum = 1.0f;
|
|
|
|
|
p.hints.default_value = 0.0f;
|
|
|
|
|
|
|
|
|
|
p.connect_to( new float );
|
|
|
|
|
p.control_value( p.hints.default_value );
|
|
|
|
|
|
|
|
|
|
add_port( p );
|
|
|
|
|
|
|
|
|
|
add_port( Port( this, Port::INPUT, Port::AUDIO ) );
|
|
|
|
|
add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
|
|
|
|
|
add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
|
|
|
|
|
|
|
|
|
|
end();
|
|
|
|
|
|
|
|
|
|
log_create();
|
2013-06-16 02:51:50 +02:00
|
|
|
|
|
|
|
|
|
smoothing.sample_rate( sample_rate() );
|
2010-01-18 04:16:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mono_Pan_Module::~Mono_Pan_Module ( )
|
|
|
|
|
{
|
|
|
|
|
delete (float*)control_input[0].buffer();
|
|
|
|
|
log_destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-16 02:51:50 +02:00
|
|
|
|
void
|
|
|
|
|
Mono_Pan_Module::handle_sample_rate_change ( nframes_t n )
|
|
|
|
|
{
|
|
|
|
|
smoothing.sample_rate( n );
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-18 04:16:31 +01:00
|
|
|
|
bool
|
2010-01-30 09:35:32 +01:00
|
|
|
|
Mono_Pan_Module::configure_inputs ( int )
|
2010-01-18 04:16:31 +01:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
/**********/
|
|
|
|
|
/* Engine */
|
|
|
|
|
/**********/
|
|
|
|
|
|
2010-01-18 04:16:31 +01:00
|
|
|
|
void
|
2010-01-30 09:35:32 +01:00
|
|
|
|
Mono_Pan_Module::process ( nframes_t nframes )
|
2010-01-18 04:16:31 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if ( audio_input[0].connected() &&
|
|
|
|
|
audio_output[0].connected() &&
|
|
|
|
|
audio_output[1].connected() )
|
|
|
|
|
{
|
2013-03-14 02:02:45 +01:00
|
|
|
|
if ( bypass() )
|
|
|
|
|
{
|
|
|
|
|
buffer_copy( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-16 02:51:50 +02:00
|
|
|
|
const float gt = (control_input[0].control_value() + 1.0f) * 0.5f;
|
|
|
|
|
|
|
|
|
|
if ( ! smoothing.target_reached( gt ) )
|
|
|
|
|
{
|
|
|
|
|
sample_t gainbuf[nframes];
|
2013-03-14 02:02:45 +01:00
|
|
|
|
|
2013-06-16 02:51:50 +02:00
|
|
|
|
smoothing.apply( gainbuf, nframes, gt );
|
|
|
|
|
|
|
|
|
|
/* right channel */
|
|
|
|
|
|
|
|
|
|
buffer_copy_and_apply_gain_buffer( (sample_t*)audio_output[1].buffer(),
|
|
|
|
|
(sample_t*)audio_input[0].buffer(),
|
|
|
|
|
gainbuf,
|
|
|
|
|
nframes );
|
|
|
|
|
|
|
|
|
|
/* left channel */
|
|
|
|
|
for ( nframes_t i = 0; i < nframes; i++ )
|
|
|
|
|
gainbuf[i] = 1.0f - gainbuf[i];
|
|
|
|
|
|
|
|
|
|
buffer_apply_gain_buffer( (sample_t*)audio_output[0].buffer(), gainbuf, nframes );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* right channel */
|
|
|
|
|
buffer_copy_and_apply_gain( (sample_t*)audio_output[1].buffer(),
|
|
|
|
|
(sample_t*)audio_input[0].buffer(),
|
|
|
|
|
nframes,
|
|
|
|
|
gt );
|
|
|
|
|
|
|
|
|
|
/* left channel */
|
|
|
|
|
buffer_apply_gain( (sample_t*)audio_output[0].buffer(), nframes, 1.0f - gt);
|
|
|
|
|
}
|
2013-03-14 02:02:45 +01:00
|
|
|
|
}
|
2010-01-18 04:16:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|