X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcinema_sound_processor.cc;h=434fdd1cf6628ae92d79c95cb663c63c5a5390a0;hb=182b9d2e2feb6545592868606aaf0f0146095481;hp=6a79051145e81e33ff998cacf1f4f7e21cb6c7d7;hpb=cc27c2716f755305d67f1e1ba828ecf37f8405dd;p=dcpomatic.git diff --git a/src/lib/cinema_sound_processor.cc b/src/lib/cinema_sound_processor.cc index 6a7905114..434fdd1cf 100644 --- a/src/lib/cinema_sound_processor.cc +++ b/src/lib/cinema_sound_processor.cc @@ -1,96 +1,100 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ + /** @file src/sound_processor.cc * @brief CinemaSoundProcessor class. */ -#include -#include + #include "cinema_sound_processor.h" #include "dolby_cp750.h" +#include "usl.h" +#include "datasat_ap2x.h" +#include "dcpomatic_assert.h" +#include +#include + using namespace std; -vector CinemaSoundProcessor::_cinema_sound_processors; + +vector> CinemaSoundProcessor::_cinema_sound_processors; + /** @param i Our id. * @param n User-visible name. */ -CinemaSoundProcessor::CinemaSoundProcessor (string i, string n) +CinemaSoundProcessor::CinemaSoundProcessor (string i, string n, float knee, float below, float above) : _id (i) , _name (n) + , _knee (knee) + , _below (below) + , _above (above) { } + /** @return All available sound processors */ vector CinemaSoundProcessor::all () { - return _cinema_sound_processors; + vector raw; + for (auto& processor: _cinema_sound_processors) { + raw.push_back (processor.get()); + } + return raw; } + /** Set up the static _sound_processors vector; must be called before from_* * methods are used. */ void CinemaSoundProcessor::setup_cinema_sound_processors () { - _cinema_sound_processors.push_back (new DolbyCP750); + _cinema_sound_processors.push_back (unique_ptr(new DolbyCP750)); + _cinema_sound_processors.push_back (unique_ptr(new USL)); + _cinema_sound_processors.push_back (unique_ptr(new DatasatAP2x)); } + /** @param id One of our ids. * @return Corresponding sound processor, or 0. */ CinemaSoundProcessor const * CinemaSoundProcessor::from_id (string id) { - vector::iterator i = _cinema_sound_processors.begin (); + auto i = _cinema_sound_processors.begin (); while (i != _cinema_sound_processors.end() && (*i)->id() != id) { ++i; } if (i == _cinema_sound_processors.end ()) { - return 0; + return nullptr; } - return *i; + return i->get(); } -/** @param s A sound processor from our static list. - * @return Index of the sound processor with the list, or -1. - */ -int -CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s) -{ - vector::size_type i = 0; - while (i < _cinema_sound_processors.size() && _cinema_sound_processors[i] != s) { - ++i; - } - - if (i == _cinema_sound_processors.size ()) { - return -1; - } - - return i; -} /** @param i An index returned from as_index(). * @return Corresponding sound processor. @@ -98,6 +102,37 @@ CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s) CinemaSoundProcessor const * CinemaSoundProcessor::from_index (int i) { - assert (i <= int(_cinema_sound_processors.size ())); - return _cinema_sound_processors[i]; + DCPOMATIC_ASSERT (i >= 0 && i < int(_cinema_sound_processors.size())); + return _cinema_sound_processors[i].get(); +} + + +float +CinemaSoundProcessor::db_for_fader_change (float from, float to) const +{ + float db = 0; + + if (from < to) { + if (from <= _knee) { + float const t = min (to, _knee); + db += (t - from) * _below; + } + + if (to > 4) { + float const t = max (from, _knee); + db += (to - t) * _above; + } + } else { + if (from >= _knee) { + float const t = max (to, _knee); + db -= (from - t) * _above; + } + + if (to < _knee) { + float const t = min (from, _knee); + db -= (t - to) * _below; + } + } + + return db; }