Fix a tiny memory-leak when calling vfork
[ardour.git] / libs / ardour / polarity_processor.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
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.
8  *
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.
13  *
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.
17  */
18
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"
24
25 #include "pbd/i18n.h"
26
27 using namespace ARDOUR;
28 using namespace PBD;
29
30 PolarityProcessor::PolarityProcessor (Session& s, boost::shared_ptr<PhaseControl> control)
31         : Processor(s, "Polarity")
32         , _control (control)
33 {
34 }
35
36 bool
37 PolarityProcessor::can_support_io_configuration (const ChanCount& in, ChanCount& out)
38 {
39         out = in;
40         return true;
41 }
42
43 bool
44 PolarityProcessor::configure_io (ChanCount in, ChanCount out)
45 {
46         if (out != in) { // always 1:1
47                 return false;
48         }
49
50         _control->resize (in.n_audio ());
51         _current_gain.resize (in.n_audio (), 1.f);
52
53         return Processor::configure_io (in, out);
54 }
55
56 void
57 PolarityProcessor::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double /*speed*/, pframes_t nframes, bool)
58 {
59         int chn = 0;
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);
64                 }
65                 return;
66         }
67         _active = _pending_active;
68
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);
71         }
72 }
73
74 XMLNode&
75 PolarityProcessor::state ()
76 {
77         XMLNode& node (Processor::state ());
78         node.set_property("type", "polarity");
79         return node;
80 }