2 Copyright (C) 2014-2021 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/>.
22 #include "mid_side_decoder.h"
23 #include "audio_buffers.h"
24 #include "audio_mapping.h"
29 using std::make_shared;
31 using std::shared_ptr;
37 MidSideDecoder::name () const
39 return _("Mid-side decoder");
44 MidSideDecoder::id () const
46 return N_("mid-side-decoder");
51 MidSideDecoder::out_channels () const
57 shared_ptr<AudioProcessor>
58 MidSideDecoder::clone (int) const
60 return make_shared<MidSideDecoder>();
64 shared_ptr<AudioBuffers>
65 MidSideDecoder::run (shared_ptr<const AudioBuffers> in, int channels)
67 int const N = min (channels, 3);
68 auto out = make_shared<AudioBuffers>(channels, in->frames ());
69 for (int i = 0; i < in->frames(); ++i) {
70 auto const left = in->data()[0][i];
71 auto const right = in->data()[1][i];
72 auto const mid = (left + right) / 2;
74 out->data()[0][i] = left - mid;
77 out->data()[1][i] = right - mid;
80 out->data()[2][i] = mid;
84 for (int i = N; i < channels; ++i) {
93 MidSideDecoder::make_audio_mapping_default (AudioMapping& mapping) const
95 /* Just map the first two input channels to our M/S */
97 for (int i = 0; i < min(2, mapping.input_channels()); ++i) {
98 mapping.set (i, i, 1);
104 MidSideDecoder::input_names () const
107 NamedChannel(_("Left"), 0),
108 NamedChannel(_("Right"), 1)