Remove unused in_channels() in AudioProcessor.
[dcpomatic.git] / src / lib / mid_side_decoder.cc
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "mid_side_decoder.h"
21 #include "audio_buffers.h"
22 #include "audio_mapping.h"
23
24 #include "i18n.h"
25
26 using std::string;
27 using std::min;
28 using std::vector;
29 using boost::shared_ptr;
30
31 string
32 MidSideDecoder::name () const
33 {
34         return _("Mid-side decoder");
35 }
36
37 string
38 MidSideDecoder::id () const
39 {
40         return N_("mid-side-decoder");
41 }
42
43 int
44 MidSideDecoder::out_channels () const
45 {
46         return 3;
47 }
48
49 shared_ptr<AudioProcessor>
50 MidSideDecoder::clone (int) const
51 {
52         return shared_ptr<AudioProcessor> (new MidSideDecoder ());
53 }
54
55 shared_ptr<AudioBuffers>
56 MidSideDecoder::run (shared_ptr<const AudioBuffers> in, int channels)
57 {
58         int const N = min (channels, 3);
59         shared_ptr<AudioBuffers> out (new AudioBuffers (channels, in->frames ()));
60         for (int i = 0; i < in->frames(); ++i) {
61                 float const left = in->data()[0][i];
62                 float const right = in->data()[1][i];
63                 float const mid = (left + right) / 2;
64                 if (N > 0) {
65                         out->data()[0][i] = left - mid;
66                 }
67                 if (N > 1) {
68                         out->data()[1][i] = right - mid;
69                 }
70                 if (N > 2) {
71                         out->data()[2][i] = mid;
72                 }
73         }
74
75         for (int i = N; i < channels; ++i) {
76                 out->make_silent (i);
77         }
78
79         return out;
80 }
81
82 void
83 MidSideDecoder::make_audio_mapping_default (AudioMapping& mapping) const
84 {
85         /* Just map the first two input channels to our M/S */
86         mapping.make_zero ();
87         for (int i = 0; i < min (2, mapping.input_channels()); ++i) {
88                 mapping.set (i, i, 1);
89         }
90 }
91
92 vector<string>
93 MidSideDecoder::input_names () const
94 {
95         vector<string> n;
96
97         n.push_back (_("Left"));
98         n.push_back (_("Right"));
99
100         return n;
101 }