2 Copyright (C) 2012-2014 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/>.
21 /** @file src/sound_processor.cc
22 * @brief CinemaSoundProcessor class.
25 #include "cinema_sound_processor.h"
26 #include "dolby_cp750.h"
28 #include "datasat_ap2x.h"
29 #include "dcpomatic_assert.h"
35 vector<CinemaSoundProcessor const *> CinemaSoundProcessor::_cinema_sound_processors;
38 * @param n User-visible name.
40 CinemaSoundProcessor::CinemaSoundProcessor (string i, string n, float knee, float below, float above)
50 /** @return All available sound processors */
51 vector<CinemaSoundProcessor const *>
52 CinemaSoundProcessor::all ()
54 return _cinema_sound_processors;
57 /** Set up the static _sound_processors vector; must be called before from_*
61 CinemaSoundProcessor::setup_cinema_sound_processors ()
63 _cinema_sound_processors.push_back (new DolbyCP750);
64 _cinema_sound_processors.push_back (new USL);
65 _cinema_sound_processors.push_back (new DatasatAP2x);
68 /** @param id One of our ids.
69 * @return Corresponding sound processor, or 0.
71 CinemaSoundProcessor const *
72 CinemaSoundProcessor::from_id (string id)
74 vector<CinemaSoundProcessor const *>::iterator i = _cinema_sound_processors.begin ();
75 while (i != _cinema_sound_processors.end() && (*i)->id() != id) {
79 if (i == _cinema_sound_processors.end ()) {
86 /** @param s A sound processor from our static list.
87 * @return Index of the sound processor with the list, or -1.
90 CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s)
92 vector<CinemaSoundProcessor*>::size_type i = 0;
93 while (i < _cinema_sound_processors.size() && _cinema_sound_processors[i] != s) {
97 if (i == _cinema_sound_processors.size ()) {
104 /** @param i An index returned from as_index().
105 * @return Corresponding sound processor.
107 CinemaSoundProcessor const *
108 CinemaSoundProcessor::from_index (int i)
110 DCPOMATIC_ASSERT (i >= 0 && i < int(_cinema_sound_processors.size()));
111 return _cinema_sound_processors[i];
115 CinemaSoundProcessor::db_for_fader_change (float from, float to) const
121 float const t = min (to, _knee);
122 db += (t - from) * _below;
126 float const t = max (from, _knee);
127 db += (to - t) * _above;
131 float const t = max (to, _knee);
132 db -= (from - t) * _above;
136 float const t = min (from, _knee);
137 db -= (t - to) * _below;