Fix the build for older macOS.
[dcpomatic.git] / src / lib / upmixer_a.cc
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "upmixer_a.h"
23 #include "audio_buffers.h"
24 #include "audio_mapping.h"
25
26 #include "i18n.h"
27
28
29 using std::make_shared;
30 using std::min;
31 using std::shared_ptr;
32 using std::string;
33 using std::vector;
34
35
36 UpmixerA::UpmixerA (int sampling_rate)
37         : _left (0.02, 1900.0 / sampling_rate, 4800.0 / sampling_rate)
38         , _right (0.02, 1900.0 / sampling_rate, 4800.0 / sampling_rate)
39         , _centre (0.01, 150.0 / sampling_rate, 1900.0 / sampling_rate)
40         , _lfe (0.01, 150.0 / sampling_rate)
41         , _ls (0.02, 4800.0 / sampling_rate, 20000.0 / sampling_rate)
42         , _rs (0.02, 4800.0 / sampling_rate, 20000.0 / sampling_rate)
43 {
44
45 }
46
47
48 string
49 UpmixerA::name () const
50 {
51         return _("Stereo to 5.1 up-mixer A");
52 }
53
54
55 string
56 UpmixerA::id () const
57 {
58         return N_("stereo-5.1-upmix-a");
59 }
60
61
62 int
63 UpmixerA::out_channels () const
64 {
65         return 6;
66 }
67
68
69 shared_ptr<AudioProcessor>
70 UpmixerA::clone (int sampling_rate) const
71 {
72         return make_shared<UpmixerA>(sampling_rate);
73 }
74
75
76 shared_ptr<AudioBuffers>
77 UpmixerA::run (shared_ptr<const AudioBuffers> in, int channels)
78 {
79         /* Input L and R */
80         auto in_L = in->channel (0);
81         auto in_R = in->channel (1);
82
83         /* Mix of L and R; -6dB down in amplitude (3dB in terms of power) */
84         auto in_LR = in_L->clone ();
85         in_LR->accumulate_frames (in_R.get(), in_R->frames(), 0, 0);
86         in_LR->apply_gain (-6);
87
88         /* Run filters */
89         vector<shared_ptr<AudioBuffers>> all_out;
90         all_out.push_back (_left.run(in_L));
91         all_out.push_back (_right.run(in_R));
92         all_out.push_back (_centre.run(in_LR));
93         all_out.push_back (_lfe.run(in_LR));
94         all_out.push_back (_ls.run(in_L));
95         all_out.push_back (_rs.run(in_R));
96
97         auto out = make_shared<AudioBuffers>(channels, in->frames());
98         int const N = min (channels, 6);
99
100         for (int i = 0; i < N; ++i) {
101                 out->copy_channel_from (all_out[i].get(), 0, i);
102         }
103
104         for (int i = N; i < channels; ++i) {
105                 out->make_silent (i);
106         }
107
108         return out;
109 }
110
111 void
112 UpmixerA::flush ()
113 {
114         _left.flush ();
115         _right.flush ();
116         _centre.flush ();
117         _lfe.flush ();
118         _ls.flush ();
119         _rs.flush ();
120 }
121
122
123 void
124 UpmixerA::make_audio_mapping_default (AudioMapping& mapping) const
125 {
126         /* Just map the first two input channels to our L/R */
127         mapping.make_zero ();
128         for (int i = 0; i < min (2, mapping.input_channels()); ++i) {
129                 mapping.set (i, i, 1);
130         }
131 }
132
133
134 vector<NamedChannel>
135 UpmixerA::input_names () const
136 {
137         return {
138                 NamedChannel(_("Upmix L"), 0),
139                 NamedChannel(_("Upmix R"), 1)
140         };
141 }