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<CinemaSoundProcessor const *> 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 return _cinema_sound_processors;
64 /** Set up the static _sound_processors vector; must be called before from_*
68 CinemaSoundProcessor::setup_cinema_sound_processors ()
70 _cinema_sound_processors.push_back (new DolbyCP750);
71 _cinema_sound_processors.push_back (new USL);
72 _cinema_sound_processors.push_back (new DatasatAP2x);
76 /** @param id One of our ids.
77 * @return Corresponding sound processor, or 0.
79 CinemaSoundProcessor const *
80 CinemaSoundProcessor::from_id (string id)
82 auto i = _cinema_sound_processors.begin ();
83 while (i != _cinema_sound_processors.end() && (*i)->id() != id) {
87 if (i == _cinema_sound_processors.end ()) {
95 /** @param s A sound processor from our static list.
96 * @return Index of the sound processor with the list, or -1.
99 CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s)
101 vector<CinemaSoundProcessor*>::size_type i = 0;
102 while (i < _cinema_sound_processors.size() && _cinema_sound_processors[i] != s) {
106 if (i == _cinema_sound_processors.size ()) {
114 /** @param i An index returned from as_index().
115 * @return Corresponding sound processor.
117 CinemaSoundProcessor const *
118 CinemaSoundProcessor::from_index (int i)
120 DCPOMATIC_ASSERT (i >= 0 && i < int(_cinema_sound_processors.size()));
121 return _cinema_sound_processors[i];
126 CinemaSoundProcessor::db_for_fader_change (float from, float to) const
132 float const t = min (to, _knee);
133 db += (t - from) * _below;
137 float const t = max (from, _knee);
138 db += (to - t) * _above;
142 float const t = max (to, _knee);
143 db -= (from - t) * _above;
147 float const t = min (from, _knee);
148 db -= (t - to) * _below;