diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-07-31 19:38:28 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-07-31 19:38:28 +0100 |
| commit | 5d0f01f04f85280a562ac9da8f58ad0c3489f7aa (patch) | |
| tree | 7b7639d407e2c2b475cdfe21669831584bc70851 /src/lib | |
| parent | 75be8cbd1d3307ea62fe8e79543ca518f4ee7bc2 (diff) | |
Basic support for calculating audio gains based on the sound processor's gain curve.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/config.cc | 5 | ||||
| -rw-r--r-- | src/lib/config.h | 7 | ||||
| -rw-r--r-- | src/lib/dolby_cp750.cc | 58 | ||||
| -rw-r--r-- | src/lib/dolby_cp750.h | 28 | ||||
| -rw-r--r-- | src/lib/scaler.h | 2 | ||||
| -rw-r--r-- | src/lib/sound_processor.cc | 103 | ||||
| -rw-r--r-- | src/lib/sound_processor.h | 66 | ||||
| -rw-r--r-- | src/lib/util.cc | 2 | ||||
| -rw-r--r-- | src/lib/wscript | 2 |
9 files changed, 272 insertions, 1 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 92044d81a..53674645d 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -27,6 +27,7 @@ #include "scaler.h" #include "screen.h" #include "filter.h" +#include "sound_processor.h" using namespace std; using namespace boost; @@ -41,6 +42,7 @@ Config::Config () , _j2k_bandwidth (250000000) , _reference_scaler (Scaler::from_id ("bicubic")) , _tms_path (".") + , _sound_processor (SoundProcessor::from_id ("dolby_cp750")) { ifstream f (file().c_str ()); string line; @@ -85,6 +87,8 @@ Config::Config () _tms_user = v; } else if (k == "tms_password") { _tms_password = v; + } else if (k == "sound_processor") { + _sound_processor = SoundProcessor::from_id (v); } } @@ -139,4 +143,5 @@ Config::write () const f << "tms_path " << _tms_path << "\n"; f << "tms_user " << _tms_user << "\n"; f << "tms_password " << _tms_password << "\n"; + f << "sound_processor " << _sound_processor->id (); } diff --git a/src/lib/config.h b/src/lib/config.h index cbb83ad86..64bcf4d86 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -32,6 +32,7 @@ class Server; class Screen; class Scaler; class Filter; +class SoundProcessor; /** @class Config * @brief A singleton class holding configuration. @@ -97,6 +98,10 @@ public: return _tms_password; } + SoundProcessor const * sound_processor () const { + return _sound_processor; + } + /** @param n New number of local encoding threads */ void set_num_local_encoding_threads (int n) { _num_local_encoding_threads = n; @@ -200,6 +205,8 @@ private: std::string _tms_user; std::string _tms_password; + SoundProcessor const * _sound_processor; + /** Singleton instance, or 0 */ static Config* _instance; }; diff --git a/src/lib/dolby_cp750.cc b/src/lib/dolby_cp750.cc new file mode 100644 index 000000000..262e57bc7 --- /dev/null +++ b/src/lib/dolby_cp750.cc @@ -0,0 +1,58 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +#include "dolby_cp750.h" + +using namespace std; + +DolbyCP750::DolbyCP750 () + : SoundProcessor ("dolby_cp750", "Dolby CP750") +{ + +} + +float +DolbyCP750::db_for_fader_change (float from, float to) const +{ + float db = 0; + + if (from < to) { + if (from <= 4) { + float const t = min (to, 4.0f); + db += (t - from) * 20; + } + + if (to > 4) { + float const t = max (from, 4.0f); + db += (to - t) * 3.33333333333333333; + } + } else { + if (from >= 4) { + float const t = max (to, 4.0f); + db -= (from - t) * 3.33333333333333333; + } + + if (to < 4) { + float const t = min (from, 4.0f); + db -= (t - to) * 20; + } + } + + return db; +} diff --git a/src/lib/dolby_cp750.h b/src/lib/dolby_cp750.h new file mode 100644 index 000000000..b6c0e7df2 --- /dev/null +++ b/src/lib/dolby_cp750.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +#include "sound_processor.h" + +class DolbyCP750 : public SoundProcessor +{ +public: + DolbyCP750 (); + + float db_for_fader_change (float from, float to) const; +}; diff --git a/src/lib/scaler.h b/src/lib/scaler.h index 8ededfe2a..d5a83f732 100644 --- a/src/lib/scaler.h +++ b/src/lib/scaler.h @@ -71,7 +71,7 @@ private: /** user-visible name for this scaler */ std::string _name; - /** sll available scalers */ + /** all available scalers */ static std::vector<Scaler const *> _scalers; }; diff --git a/src/lib/sound_processor.cc b/src/lib/sound_processor.cc new file mode 100644 index 000000000..9be6621cc --- /dev/null +++ b/src/lib/sound_processor.cc @@ -0,0 +1,103 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +/** @file src/sound_processor.cc + * @brief A class to describe a sound processor. + */ + +#include <iostream> +#include <cassert> +#include "sound_processor.h" +#include "dolby_cp750.h" + +using namespace std; + +vector<SoundProcessor const *> SoundProcessor::_sound_processors; + +/** @param i Our id. + * @param n User-visible name. + */ +SoundProcessor::SoundProcessor (string i, string n) + : _id (i) + , _name (n) +{ + +} + +/** @return All available sound processors */ +vector<SoundProcessor const *> +SoundProcessor::all () +{ + return _sound_processors; +} + +/** Set up the static _sound_processors vector; must be called before from_* + * methods are used. + */ +void +SoundProcessor::setup_sound_processors () +{ + _sound_processors.push_back (new DolbyCP750); +} + +/** @param id One of our ids. + * @return Corresponding sound processor, or 0. + */ +SoundProcessor const * +SoundProcessor::from_id (string id) +{ + vector<SoundProcessor const *>::iterator i = _sound_processors.begin (); + while (i != _sound_processors.end() && (*i)->id() != id) { + ++i; + } + + if (i == _sound_processors.end ()) { + return 0; + } + + return *i; +} + +/** @param s A sound processor from our static list. + * @return Index of the sound processor with the list, or -1. + */ +int +SoundProcessor::as_index (SoundProcessor const * s) +{ + vector<SoundProcessor*>::size_type i = 0; + while (i < _sound_processors.size() && _sound_processors[i] != s) { + ++i; + } + + if (i == _sound_processors.size ()) { + return -1; + } + + return i; +} + +/** @param i An index returned from as_index(). + * @return Corresponding sound processor. + */ +SoundProcessor const * +SoundProcessor::from_index (int i) +{ + assert (i <= int(_sound_processors.size ())); + return _sound_processors[i]; +} diff --git a/src/lib/sound_processor.h b/src/lib/sound_processor.h new file mode 100644 index 000000000..2edf38840 --- /dev/null +++ b/src/lib/sound_processor.h @@ -0,0 +1,66 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +/** @file src/sound_processor.h + * @brief A class to describe a sound processor. + */ + +#ifndef DVDOMATIC_SOUND_PROCESSOR_H +#define DVDOMATIC_SOUND_PROCESSOR_H + +#include <string> +#include <vector> + +/** @class SoundProcessor + * @brief Class to describe a sound processor. + */ +class SoundProcessor +{ +public: + SoundProcessor (std::string i, std::string n); + + virtual float db_for_fader_change (float from, float to) const = 0; + + /** @return id for our use */ + std::string id () const { + return _id; + } + + /** @return user-visible name for this sound processor */ + std::string name () const { + return _name; + } + + static std::vector<SoundProcessor const *> all (); + static void setup_sound_processors (); + static SoundProcessor const * from_id (std::string id); + static SoundProcessor const * from_index (int); + static int as_index (SoundProcessor const *); + +private: + /** id for our use */ + std::string _id; + /** user-visible name for this sound processor */ + std::string _name; + + /** sll available sound processors */ + static std::vector<SoundProcessor const *> _sound_processors; +}; + +#endif diff --git a/src/lib/util.cc b/src/lib/util.cc index 5106f3182..1ab8c1e65 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -54,6 +54,7 @@ extern "C" { #include "filter.h" #include "screen.h" #include "film_state.h" +#include "sound_processor.h" #ifndef DVDOMATIC_DISABLE_PLAYER #include "player_manager.h" #endif @@ -386,6 +387,7 @@ dvdomatic_setup () DCPContentType::setup_dcp_content_types (); Scaler::setup_scalers (); Filter::setup_filters (); + SoundProcessor::setup_sound_processors (); #ifdef DVDOMATIC_POSIX struct sigaction sa; diff --git a/src/lib/wscript b/src/lib/wscript index afc916605..71a2b23f4 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -23,6 +23,7 @@ def build(bld): decoder.cc decoder_factory.cc delay_line.cc + dolby_cp750.cc dvd.cc encoder.cc encoder_factory.cc @@ -46,6 +47,7 @@ def build(bld): scaler.cc screen.cc server.cc + sound_processor.cc thumbs_job.cc tiff_decoder.cc tiff_encoder.cc |
