Very basic audio processing framework.
[dcpomatic.git] / src / lib / mid_side_decoder.cc
1 /*
2     Copyright (C) 2014 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
23 #include "i18n.h"
24
25 using std::string;
26 using boost::shared_ptr;
27
28 string
29 MidSideDecoder::name () const
30 {
31         return _("Mid-side decoder");
32 }
33
34 string
35 MidSideDecoder::id () const
36 {
37         return N_("mid-side-decoder");
38 }
39
40 ChannelCount
41 MidSideDecoder::in_channels () const
42 {
43         return ChannelCount (2);
44 }
45
46 int
47 MidSideDecoder::out_channels (int) const
48 {
49         return 3;
50 }
51
52 shared_ptr<AudioProcessor>
53 MidSideDecoder::clone () const
54 {
55         return shared_ptr<AudioProcessor> (new MidSideDecoder ());
56 }
57
58 shared_ptr<AudioBuffers>
59 MidSideDecoder::run (shared_ptr<const AudioBuffers> in)
60 {
61         shared_ptr<AudioBuffers> out (new AudioBuffers (3, in->frames ()));
62         for (int i = 0; i < in->frames(); ++i) {
63                 float const left = in->data()[0][i];
64                 float const right = in->data()[1][i];
65                 float const mid = (left + right) / 2;
66                 out->data()[0][i] = left - mid;
67                 out->data()[1][i] = right - mid;
68                 out->data()[2][i] = mid;
69         }
70
71         return out;
72 }