2 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "ardour/amp.h"
20 #include "ardour/audio_buffer.h"
21 #include "ardour/phase_control.h"
22 #include "ardour/polarity_processor.h"
23 #include "ardour/session.h"
27 using namespace ARDOUR;
30 PolarityProcessor::PolarityProcessor (Session& s, boost::shared_ptr<PhaseControl> control)
31 : Processor(s, "Polarity")
37 PolarityProcessor::can_support_io_configuration (const ChanCount& in, ChanCount& out)
44 PolarityProcessor::configure_io (ChanCount in, ChanCount out)
46 if (out != in) { // always 1:1
50 _control->resize (in.n_audio ());
51 _current_gain.resize (in.n_audio (), 1.f);
53 return Processor::configure_io (in, out);
57 PolarityProcessor::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double /*speed*/, pframes_t nframes, bool)
60 if (!_active && !_pending_active) {
61 /* fade all to unity */
62 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
63 _current_gain[chn] = Amp::apply_gain (*i, _session.nominal_sample_rate(), nframes, _current_gain[chn], 1.0);
67 _active = _pending_active;
69 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
70 _current_gain[chn] = Amp::apply_gain (*i, _session.nominal_sample_rate(), nframes, _current_gain[chn], _control->inverted (chn) ? -1.f : 1.f);
75 PolarityProcessor::state ()
77 XMLNode& node (Processor::state ());
78 node.set_property("type", "polarity");