summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-02-25 20:52:20 +0000
committerCarl Hetherington <cth@carlh.net>2013-02-25 20:52:20 +0000
commiteac941aed6e6eed7f0329e42c7a036ed620f8df0 (patch)
tree5a494d82b2ba88223f162e8f8c01ad016ba293b0 /src/lib/util.cc
parent6e0f2a39c9deeb51f05c0c8c9bd46632c2c6483a (diff)
Try to tidy up channel mapping a bit.
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc65
1 files changed, 52 insertions, 13 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index f807bf329..8ad980361 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -445,19 +445,6 @@ dcp_audio_sample_rate (int fs)
return 96000;
}
-int
-dcp_audio_channels (int f)
-{
- if (f == 1) {
- /* The source is mono, so to put the mono channel into
- the centre we need to generate a 5.1 soundtrack.
- */
- return 6;
- }
-
- return f;
-}
-
bool operator== (Crop const & a, Crop const & b)
{
return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom);
@@ -918,3 +905,55 @@ audio_channel_name (int c)
return channels[c];
}
+
+AudioMapping::AudioMapping (int c)
+ : _source_channels (c)
+{
+
+}
+
+optional<libdcp::Channel>
+AudioMapping::source_to_dcp (int c) const
+{
+ if (c >= _source_channels) {
+ return optional<libdcp::Channel> ();
+ }
+
+ if (_source_channels == 1) {
+ /* mono sources to centre */
+ return libdcp::CENTRE;
+ }
+
+ return static_cast<libdcp::Channel> (c);
+}
+
+optional<int>
+AudioMapping::dcp_to_source (libdcp::Channel c) const
+{
+ if (_source_channels == 1) {
+ if (c == libdcp::CENTRE) {
+ return 0;
+ } else {
+ return optional<int> ();
+ }
+ }
+
+ if (static_cast<int> (c) >= _source_channels) {
+ return optional<int> ();
+ }
+
+ return static_cast<int> (c);
+}
+
+int
+AudioMapping::dcp_channels () const
+{
+ if (_source_channels == 1) {
+ /* The source is mono, so to put the mono channel into
+ the centre we need to generate a 5.1 soundtrack.
+ */
+ return 6;
+ }
+
+ return _source_channels;
+}