2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "mid_side_decoder.h"
21 #include "audio_buffers.h"
22 #include "audio_mapping.h"
29 using boost::shared_ptr;
32 MidSideDecoder::name () const
34 return _("Mid-side decoder");
38 MidSideDecoder::id () const
40 return N_("mid-side-decoder");
44 MidSideDecoder::in_channels () const
46 return ChannelCount (2);
50 MidSideDecoder::out_channels () const
55 shared_ptr<AudioProcessor>
56 MidSideDecoder::clone (int) const
58 return shared_ptr<AudioProcessor> (new MidSideDecoder ());
61 shared_ptr<AudioBuffers>
62 MidSideDecoder::run (shared_ptr<const AudioBuffers> in, int channels)
64 int const N = min (channels, 3);
65 shared_ptr<AudioBuffers> out (new AudioBuffers (channels, in->frames ()));
66 for (int i = 0; i < in->frames(); ++i) {
67 float const left = in->data()[0][i];
68 float const right = in->data()[1][i];
69 float const mid = (left + right) / 2;
71 out->data()[0][i] = left - mid;
74 out->data()[1][i] = right - mid;
77 out->data()[2][i] = mid;
81 for (int i = N; i < channels; ++i) {
89 MidSideDecoder::make_audio_mapping_default (AudioMapping& mapping) const
91 /* Just map the first two input channels to our M/S */
93 for (int i = 0; i < min (2, mapping.input_channels()); ++i) {
94 mapping.set (i, i, 1);
99 MidSideDecoder::input_names () const
103 n.push_back (_("Left"));
104 n.push_back (_("Right"));