Merge remote-tracking branch 'origin/master' into 2.0
[dcpomatic.git] / src / lib / upmixer_a.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 "upmixer_a.h"
21 #include "audio_buffers.h"
22
23 #include "i18n.h"
24
25 using std::string;
26 using boost::shared_ptr;
27
28 UpmixerA::UpmixerA (int sampling_rate)
29         : _left (0.02, 1900.0 / sampling_rate, 4800.0 / sampling_rate)
30         , _right (0.02, 1900.0 / sampling_rate, 4800.0 / sampling_rate)
31         , _centre (0.02, 150.0 / sampling_rate, 1900.0 / sampling_rate)
32         , _lfe (0.02, 20.0 / sampling_rate, 150.0 / sampling_rate)
33         , _ls (0.02, 4800.0 / sampling_rate, 20000.0 / sampling_rate)
34         , _rs (0.02, 4800.0 / sampling_rate, 20000.0 / sampling_rate)
35 {
36
37 }
38
39 string
40 UpmixerA::name () const
41 {
42         return _("Stereo to 5.1 up-mixer A");
43 }
44
45
46 string
47 UpmixerA::id () const
48 {
49         return N_("stereo-5.1-upmix-a");
50 }
51
52 ChannelCount
53 UpmixerA::in_channels () const
54 {
55         return ChannelCount (2);
56 }
57
58 int
59 UpmixerA::out_channels (int) const
60 {
61         return 6;
62 }
63
64 shared_ptr<AudioProcessor>
65 UpmixerA::clone (int sampling_rate) const
66 {
67         return shared_ptr<AudioProcessor> (new UpmixerA (sampling_rate));
68 }
69
70 shared_ptr<AudioBuffers>
71 UpmixerA::run (shared_ptr<const AudioBuffers> in)
72 {
73         /* Input L and R */
74         shared_ptr<AudioBuffers> in_L = in->channel (0);
75         shared_ptr<AudioBuffers> in_R = in->channel (1);
76
77         /* Mix of L and R */
78         shared_ptr<AudioBuffers> in_LR = in_L->clone ();
79         in_LR->accumulate_frames (in_R.get(), 0, 0, in_R->frames ());
80         in_LR->apply_gain (0.5);
81
82         /* Run filters */
83         shared_ptr<AudioBuffers> L = _left.run (in_L);
84         shared_ptr<AudioBuffers> R = _right.run (in_R);
85         shared_ptr<AudioBuffers> C = _centre.run (in_LR);
86         shared_ptr<AudioBuffers> Lfe = _lfe.run (in_LR);
87         shared_ptr<AudioBuffers> Ls = _ls.run (in_L);
88         shared_ptr<AudioBuffers> Rs = _rs.run (in_R);
89
90         shared_ptr<AudioBuffers> out (new AudioBuffers (6, in->frames ()));
91         out->copy_channel_from (L.get(), 0, 0);
92         out->copy_channel_from (R.get(), 0, 1);
93         out->copy_channel_from (C.get(), 0, 2);
94         out->copy_channel_from (Lfe.get(), 0, 3);
95         out->copy_channel_from (Ls.get(), 0, 4);
96         out->copy_channel_from (Rs.get(), 0, 5);
97         return out;
98 }
99
100 void
101 UpmixerA::flush ()
102 {
103         _left.flush ();
104         _right.flush ();
105         _centre.flush ();
106         _lfe.flush ();
107         _ls.flush ();
108         _rs.flush ();
109 }