2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 /** @file src/sound_processor.cc
23 * @brief CinemaSoundProcessor class.
27 #include "cinema_sound_processor.h"
28 #include "dolby_cp750.h"
30 #include "datasat_ap2x.h"
31 #include "dcpomatic_assert.h"
39 vector<unique_ptr<const CinemaSoundProcessor>> CinemaSoundProcessor::_cinema_sound_processors;
43 * @param n User-visible name.
45 CinemaSoundProcessor::CinemaSoundProcessor (string i, string n, float knee, float below, float above)
56 /** @return All available sound processors */
57 vector<CinemaSoundProcessor const *>
58 CinemaSoundProcessor::all ()
60 vector<CinemaSoundProcessor const *> raw;
61 for (auto& processor: _cinema_sound_processors) {
62 raw.push_back (processor.get());
68 /** Set up the static _sound_processors vector; must be called before from_*
72 CinemaSoundProcessor::setup_cinema_sound_processors ()
74 _cinema_sound_processors.push_back (unique_ptr<CinemaSoundProcessor>(new DolbyCP750));
75 _cinema_sound_processors.push_back (unique_ptr<CinemaSoundProcessor>(new USL));
76 _cinema_sound_processors.push_back (unique_ptr<CinemaSoundProcessor>(new DatasatAP2x));
80 /** @param id One of our ids.
81 * @return Corresponding sound processor, or 0.
83 CinemaSoundProcessor const *
84 CinemaSoundProcessor::from_id (string id)
86 auto i = _cinema_sound_processors.begin ();
87 while (i != _cinema_sound_processors.end() && (*i)->id() != id) {
91 if (i == _cinema_sound_processors.end ()) {
99 /** @param i An index returned from as_index().
100 * @return Corresponding sound processor.
102 CinemaSoundProcessor const *
103 CinemaSoundProcessor::from_index (int i)
105 DCPOMATIC_ASSERT (i >= 0 && i < int(_cinema_sound_processors.size()));
106 return _cinema_sound_processors[i].get();
111 CinemaSoundProcessor::db_for_fader_change (float from, float to) const
117 float const t = min (to, _knee);
118 db += (t - from) * _below;
122 float const t = max (from, _knee);
123 db += (to - t) * _above;
127 float const t = max (to, _knee);
128 db -= (from - t) * _above;
132 float const t = min (from, _knee);
133 db -= (t - to) * _below;