2 Copyright (C) 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 "upmixer_b.h"
21 #include "audio_buffers.h"
22 #include "audio_mapping.h"
29 using boost::shared_ptr;
31 UpmixerB::UpmixerB (int sampling_rate)
32 : _lfe (0.01, 150.0 / sampling_rate)
33 , _delay (0.02 * sampling_rate)
39 UpmixerB::name () const
41 return _("Stereo to 5.1 up-mixer B");
48 return N_("stereo-5.1-upmix-b");
52 UpmixerB::out_channels () const
57 shared_ptr<AudioProcessor>
58 UpmixerB::clone (int sampling_rate) const
60 return shared_ptr<AudioProcessor> (new UpmixerB (sampling_rate));
63 shared_ptr<AudioBuffers>
64 UpmixerB::run (shared_ptr<const AudioBuffers> in, int channels)
66 shared_ptr<AudioBuffers> out (new AudioBuffers (channels, in->frames()));
68 /* L + R minus 6dB (in terms of amplitude) */
69 shared_ptr<AudioBuffers> in_LR = in->channel(0);
70 in_LR->accumulate_frames (in->channel(1).get(), 0, 0, in->frames());
71 in_LR->apply_gain (-6);
75 out->copy_channel_from (in.get(), 0, 0);
80 out->copy_channel_from (in.get(), 1, 1);
84 /* C = L + R minus 3dB */
85 out->copy_channel_from (in_LR.get(), 0, 2);
89 /* Lfe is filtered C */
90 out->copy_channel_from (_lfe.run(in_LR).get(), 0, 3);
93 shared_ptr<AudioBuffers> S;
95 /* Ls is L - R with some delay */
96 shared_ptr<AudioBuffers> sub (new AudioBuffers (1, in->frames()));
97 sub->copy_channel_from (in.get(), 0, 0);
98 float* p = sub->data (0);
99 float const * q = in->data (1);
100 for (int i = 0; i < in->frames(); ++i) {
103 S = _delay.run (sub);
104 out->copy_channel_from (S.get(), 0, 4);
109 out->copy_channel_from (S.get(), 0, 5);
123 UpmixerB::make_audio_mapping_default (AudioMapping& mapping) const
125 /* Just map the first two input channels to our L/R */
126 mapping.make_zero ();
127 for (int i = 0; i < min (2, mapping.input_channels()); ++i) {
128 mapping.set (i, i, 1);
133 UpmixerB::input_names () const
136 n.push_back (_("Upmix L"));
137 n.push_back (_("Upmix R"));