2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "mid_side_decoder.h"
22 #include "audio_buffers.h"
23 #include "audio_mapping.h"
30 using boost::shared_ptr;
33 MidSideDecoder::name () const
35 return _("Mid-side decoder");
39 MidSideDecoder::id () const
41 return N_("mid-side-decoder");
45 MidSideDecoder::out_channels () const
50 shared_ptr<AudioProcessor>
51 MidSideDecoder::clone (int) const
53 return shared_ptr<AudioProcessor> (new MidSideDecoder ());
56 shared_ptr<AudioBuffers>
57 MidSideDecoder::run (shared_ptr<const AudioBuffers> in, int channels)
59 int const N = min (channels, 3);
60 shared_ptr<AudioBuffers> out (new AudioBuffers (channels, in->frames ()));
61 for (int i = 0; i < in->frames(); ++i) {
62 float const left = in->data()[0][i];
63 float const right = in->data()[1][i];
64 float const mid = (left + right) / 2;
66 out->data()[0][i] = left - mid;
69 out->data()[1][i] = right - mid;
72 out->data()[2][i] = mid;
76 for (int i = N; i < channels; ++i) {
84 MidSideDecoder::make_audio_mapping_default (AudioMapping& mapping) const
86 /* Just map the first two input channels to our M/S */
88 for (int i = 0; i < min (2, mapping.input_channels()); ++i) {
89 mapping.set (i, i, 1);
94 MidSideDecoder::input_names () const
96 vector<NamedChannel> n;
97 n.push_back (NamedChannel(_("Left"), 0));
98 n.push_back (NamedChannel(_("Right"), 1));