summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-01-06 16:45:18 +0000
committerCarl Hetherington <cth@carlh.net>2014-01-06 16:45:18 +0000
commit34b40f12d7eec52862999da9e4417fc8f6e0f9af (patch)
treeea24126bc477d8fddceb6c1e001d4cadb302dd06 /src/lib
parent9314d6bdf8857bc6cd29b0596158f2d0ff787513 (diff)
Basics of per-channel audio gain.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_mapping.cc92
-rw-r--r--src/lib/audio_mapping.h21
-rw-r--r--src/lib/ffmpeg_content.cc2
-rw-r--r--src/lib/film.cc5
-rw-r--r--src/lib/player.cc16
-rw-r--r--src/lib/sndfile_content.cc4
6 files changed, 79 insertions, 61 deletions
diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc
index 362000125..ae7702998 100644
--- a/src/lib/audio_mapping.cc
+++ b/src/lib/audio_mapping.cc
@@ -21,6 +21,7 @@
#include <libxml++/libxml++.h>
#include <libcxml/cxml.h>
#include "audio_mapping.h"
+#include "util.h"
using std::list;
using std::cout;
@@ -41,77 +42,86 @@ AudioMapping::AudioMapping ()
* @param c Number of channels.
*/
AudioMapping::AudioMapping (int c)
- : _content_channels (c)
{
+ setup (c);
+}
+void
+AudioMapping::setup (int c)
+{
+ _content_channels = c;
+
+ _gain.resize (_content_channels);
+ for (int i = 0; i < _content_channels; ++i) {
+ _gain[i].resize (MAX_AUDIO_CHANNELS);
+ }
}
void
AudioMapping::make_default ()
{
+ for (int i = 0; i < _content_channels; ++i) {
+ for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) {
+ _gain[i][j] = 0;
+ }
+ }
+
if (_content_channels == 1) {
/* Mono -> Centre */
- add (0, libdcp::CENTRE);
+ set (0, libdcp::CENTRE, 1);
} else {
/* 1:1 mapping */
for (int i = 0; i < _content_channels; ++i) {
- add (i, static_cast<libdcp::Channel> (i));
+ set (i, static_cast<libdcp::Channel> (i), 1);
}
}
}
-AudioMapping::AudioMapping (shared_ptr<const cxml::Node> node)
+AudioMapping::AudioMapping (shared_ptr<const cxml::Node> node, int state_version)
{
- _content_channels = node->number_child<int> ("ContentChannels");
-
- list<cxml::NodePtr> const c = node->node_children ("Map");
- for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
- add ((*i)->number_child<int> ("ContentIndex"), static_cast<libdcp::Channel> ((*i)->number_child<int> ("DCP")));
+ setup (node->number_child<int> ("ContentChannels"));
+
+ if (state_version <= 5) {
+ /* Old-style: on/off mapping */
+ list<cxml::NodePtr> const c = node->node_children ("Map");
+ for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
+ set ((*i)->number_child<int> ("ContentIndex"), static_cast<libdcp::Channel> ((*i)->number_child<int> ("DCP")), 1);
+ }
+ } else {
+ list<cxml::NodePtr> const c = node->node_children ("Gain");
+ for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
+ set (
+ (*i)->number_attribute<int> ("Content"),
+ static_cast<libdcp::Channel> ((*i)->number_attribute<int> ("DCP")),
+ lexical_cast<float> ((*i)->content ())
+ );
+ }
}
}
void
-AudioMapping::add (int c, libdcp::Channel d)
+AudioMapping::set (int c, libdcp::Channel d, float g)
{
- _content_to_dcp.push_back (make_pair (c, d));
+ _gain[c][d] = g;
}
-list<int>
-AudioMapping::dcp_to_content (libdcp::Channel d) const
+float
+AudioMapping::get (int c, libdcp::Channel d) const
{
- list<int> c;
- for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
- if (i->second == d) {
- c.push_back (i->first);
- }
- }
-
- return c;
-}
-
-list<libdcp::Channel>
-AudioMapping::content_to_dcp (int c) const
-{
- assert (c < _content_channels);
-
- list<libdcp::Channel> d;
- for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
- if (i->first == c) {
- d.push_back (i->second);
- }
- }
-
- return d;
+ return _gain[c][d];
}
void
AudioMapping::as_xml (xmlpp::Node* node) const
{
node->add_child ("ContentChannels")->add_child_text (lexical_cast<string> (_content_channels));
-
- for (list<pair<int, libdcp::Channel> >::const_iterator i = _content_to_dcp.begin(); i != _content_to_dcp.end(); ++i) {
- xmlpp::Node* t = node->add_child ("Map");
- t->add_child ("ContentIndex")->add_child_text (lexical_cast<string> (i->first));
- t->add_child ("DCP")->add_child_text (lexical_cast<string> (i->second));
+
+ for (int c = 0; c < _content_channels; ++c) {
+ for (int d = 0; d < MAX_AUDIO_CHANNELS; ++d) {
+ xmlpp::Element* t = node->add_child ("Gain");
+ t->set_attribute ("Content", lexical_cast<string> (c));
+ t->set_attribute ("DCP", lexical_cast<string> (d));
+ t->add_child_text (lexical_cast<string> (get (c, static_cast<libdcp::Channel> (d))));
+ }
}
}
diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h
index 9a507b550..26087bfff 100644
--- a/src/lib/audio_mapping.h
+++ b/src/lib/audio_mapping.h
@@ -20,7 +20,7 @@
#ifndef DCPOMATIC_AUDIO_MAPPING_H
#define DCPOMATIC_AUDIO_MAPPING_H
-#include <list>
+#include <vector>
#include <libdcp/types.h>
#include <boost/shared_ptr.hpp>
@@ -34,37 +34,34 @@ namespace cxml {
/** A many-to-many mapping from some content channels to DCP channels.
* The number of content channels is set on construction and fixed,
- * and then each of those content channels can be mapped to zero or
- * more DCP channels.
+ * and then each of those content channels are mapped to each DCP channel
+ * by a linear gain.
*/
class AudioMapping
{
public:
AudioMapping ();
AudioMapping (int);
- AudioMapping (boost::shared_ptr<const cxml::Node>);
+ AudioMapping (boost::shared_ptr<const cxml::Node>, int);
/* Default copy constructor is fine */
void as_xml (xmlpp::Node *) const;
- void add (int, libdcp::Channel);
void make_default ();
- std::list<int> dcp_to_content (libdcp::Channel) const;
- std::list<std::pair<int, libdcp::Channel> > content_to_dcp () const {
- return _content_to_dcp;
- }
+ void set (int, libdcp::Channel, float);
+ float get (int, libdcp::Channel) const;
int content_channels () const {
return _content_channels;
}
- std::list<libdcp::Channel> content_to_dcp (int) const;
-
private:
+ void setup (int);
+
int _content_channels;
- std::list<std::pair<int, libdcp::Channel> > _content_to_dcp;
+ std::vector<std::vector<float> > _gain;
};
#endif
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc
index 9533315a5..f59551d1d 100644
--- a/src/lib/ffmpeg_content.cc
+++ b/src/lib/ffmpeg_content.cc
@@ -374,7 +374,7 @@ FFmpegStream::as_xml (xmlpp::Node* root) const
FFmpegAudioStream::FFmpegAudioStream (shared_ptr<const cxml::Node> node, int version)
: FFmpegStream (node, version)
- , mapping (node->node_child ("Mapping"))
+ , mapping (node->node_child ("Mapping"), version)
{
frame_rate = node->number_child<int> ("FrameRate");
channels = node->number_child<int64_t> ("Channels");
diff --git a/src/lib/film.cc b/src/lib/film.cc
index edd47c6d0..8586d4b73 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -81,7 +81,10 @@ using boost::optional;
using libdcp::Size;
using libdcp::Signer;
-int const Film::state_version = 5;
+/* 5 -> 6
+ * AudioMapping XML changed.
+ */
+int const Film::state_version = 6;
/** Construct a Film object in a given directory.
*
diff --git a/src/lib/player.cc b/src/lib/player.cc
index cacb42651..e1bf1fdb5 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -344,10 +344,18 @@ Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers
/* Remap channels */
shared_ptr<AudioBuffers> dcp_mapped (new AudioBuffers (_film->audio_channels(), audio->frames()));
dcp_mapped->make_silent ();
- list<pair<int, libdcp::Channel> > map = content->audio_mapping().content_to_dcp ();
- for (list<pair<int, libdcp::Channel> >::iterator i = map.begin(); i != map.end(); ++i) {
- if (i->first < audio->channels() && i->second < dcp_mapped->channels()) {
- dcp_mapped->accumulate_channel (audio.get(), i->first, i->second);
+
+ AudioMapping map = content->audio_mapping ();
+ for (int i = 0; i < map.content_channels(); ++i) {
+ for (int j = 0; j < _film->audio_channels(); ++j) {
+ if (map.get (i, static_cast<libdcp::Channel> (j)) > 0) {
+ dcp_mapped->accumulate_channel (
+ audio.get(),
+ i,
+ static_cast<libdcp::Channel> (j),
+ map.get (i, static_cast<libdcp::Channel> (j))
+ );
+ }
}
}
diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc
index 89db865d5..796229777 100644
--- a/src/lib/sndfile_content.cc
+++ b/src/lib/sndfile_content.cc
@@ -43,10 +43,10 @@ SndfileContent::SndfileContent (shared_ptr<const Film> f, boost::filesystem::pat
}
-SndfileContent::SndfileContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node, int)
+SndfileContent::SndfileContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node, int version)
: Content (f, node)
, AudioContent (f, node)
- , _audio_mapping (node->node_child ("AudioMapping"))
+ , _audio_mapping (node->node_child ("AudioMapping"), version)
{
_audio_channels = node->number_child<int> ("AudioChannels");
_audio_length = node->number_child<AudioContent::Frame> ("AudioLength");