diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-02-25 20:52:20 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-02-25 20:52:20 +0000 |
| commit | eac941aed6e6eed7f0329e42c7a036ed620f8df0 (patch) | |
| tree | 5a494d82b2ba88223f162e8f8c01ad016ba293b0 /src/lib | |
| parent | 6e0f2a39c9deeb51f05c0c8c9bd46632c2c6483a (diff) | |
Try to tidy up channel mapping a bit.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/encoder.cc | 26 | ||||
| -rw-r--r-- | src/lib/util.cc | 65 | ||||
| -rw-r--r-- | src/lib/util.h | 15 | ||||
| -rw-r--r-- | src/lib/writer.cc | 6 |
4 files changed, 84 insertions, 28 deletions
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index f25256379..07139968d 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -423,18 +423,20 @@ Encoder::encoder_thread (ServerDescription* server) void Encoder::write_audio (shared_ptr<const AudioBuffers> data) { - if (_film->audio_channels() == 1) { - /* We need to switch things around so that the mono channel is on - the centre channel of a 5.1 set (with other channels silent). - */ - - shared_ptr<AudioBuffers> b (new AudioBuffers (6, data->frames ())); - b->make_silent (libdcp::LEFT); - b->make_silent (libdcp::RIGHT); - memcpy (b->data()[libdcp::CENTRE], data->data()[0], data->frames() * sizeof(float)); - b->make_silent (libdcp::LFE); - b->make_silent (libdcp::LS); - b->make_silent (libdcp::RS); + AudioMapping m (_film->audio_channels ()); + if (m.dcp_channels() != _film->audio_channels()) { + + /* Remap (currently just for mono -> 5.1) */ + + shared_ptr<AudioBuffers> b (new AudioBuffers (m.dcp_channels(), data->frames ())); + for (int i = 0; i < m.dcp_channels(); ++i) { + optional<int> s = m.dcp_to_source (static_cast<libdcp::Channel> (i)); + if (!s) { + b->make_silent (i); + } else { + memcpy (b->data()[i], data->data()[s.get()], data->frames() * sizeof(float)); + } + } data = b; } 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; +} diff --git a/src/lib/util.h b/src/lib/util.h index b76aead41..22c6ea95b 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -29,6 +29,7 @@ #include <vector> #include <boost/shared_ptr.hpp> #include <boost/asio.hpp> +#include <boost/optional.hpp> #include <libdcp/util.h> extern "C" { #include <libavcodec/avcodec.h> @@ -179,7 +180,6 @@ struct Rect extern std::string crop_string (Position, libdcp::Size); extern int dcp_audio_sample_rate (int); -extern int dcp_audio_channels (int); extern std::string colour_lut_index_to_name (int index); extern int stride_round_up (int, int const *, int); extern int stride_lookup (int c, int const * stride); @@ -269,6 +269,19 @@ private: float** _data; }; +class AudioMapping +{ +public: + AudioMapping (int); + + boost::optional<libdcp::Channel> source_to_dcp (int c) const; + boost::optional<int> dcp_to_source (libdcp::Channel c) const; + int dcp_channels () const; + +private: + int _source_channels; +}; + extern int64_t video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float frames_per_second); extern bool still_image_file (std::string); extern std::pair<std::string, int> cpu_info (); diff --git a/src/lib/writer.cc b/src/lib/writer.cc index c2cc00328..1dad4357d 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -72,13 +72,15 @@ Writer::Writer (shared_ptr<Film> f) _picture_asset_writer = _picture_asset->start_write (_first_nonexistant_frame > 0); - if (dcp_audio_channels (_film->audio_channels()) > 0) { + AudioMapping m (_film->audio_channels ()); + + if (m.dcp_channels() > 0) { _sound_asset.reset ( new libdcp::SoundAsset ( _film->dir (_film->dcp_name()), "audio.mxf", DCPFrameRate (_film->frames_per_second()).frames_per_second, - dcp_audio_channels (_film->audio_channels()), + m.dcp_channels (), dcp_audio_sample_rate (_film->audio_stream()->sample_rate()) ) ); |
