X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_mapping.cc;h=65eb5fc962c77baa42b7fb4ca5faec9b78a47190;hb=0a93237cb5e4642d3b698ff9b7d0cfae5401478c;hp=1db827046946a8008d54bff21597d4fd1d201bff;hpb=e8c1880a2b9a40eb11ee259feee3edd799139a43;p=dcpomatic.git diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 1db827046..65eb5fc96 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2015 Carl Hetherington 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 @@ -17,19 +17,21 @@ */ -#include -#include -#include #include "audio_mapping.h" #include "util.h" +#include "md5_digester.h" +#include "raw_convert.h" +#include +#include using std::list; using std::cout; using std::make_pair; using std::pair; using std::string; +using std::min; +using std::vector; using boost::shared_ptr; -using boost::lexical_cast; using boost::dynamic_pointer_cast; AudioMapping::AudioMapping () @@ -38,12 +40,12 @@ AudioMapping::AudioMapping () } -/** Create a default AudioMapping for a given channel count. - * @param c Number of channels. +/** Create an empty AudioMapping for a given channel count. + * @param channels Number of channels. */ -AudioMapping::AudioMapping (int c) +AudioMapping::AudioMapping (int channels) { - setup (c); + setup (channels); } void @@ -53,31 +55,41 @@ AudioMapping::setup (int c) _gain.resize (_content_channels); for (int i = 0; i < _content_channels; ++i) { - _gain[i].resize (MAX_AUDIO_CHANNELS); + _gain[i].resize (MAX_DCP_AUDIO_CHANNELS); } + + _name.resize (_content_channels); + + make_zero (); } void -AudioMapping::make_default () +AudioMapping::make_zero () { for (int i = 0; i < _content_channels; ++i) { - for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) { + for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) { _gain[i][j] = 0; } } +} + +void +AudioMapping::make_default () +{ + make_zero (); if (_content_channels == 1) { /* Mono -> Centre */ set (0, dcp::CENTRE, 1); } else { /* 1:1 mapping */ - for (int i = 0; i < _content_channels; ++i) { + for (int i = 0; i < min (_content_channels, MAX_DCP_AUDIO_CHANNELS); ++i) { set (i, static_cast (i), 1); } } } -AudioMapping::AudioMapping (shared_ptr node, int state_version) +AudioMapping::AudioMapping (cxml::ConstNodePtr node, int state_version) { setup (node->number_child ("ContentChannels")); @@ -93,7 +105,7 @@ AudioMapping::AudioMapping (shared_ptr node, int state_version set ( (*i)->number_attribute ("Content"), static_cast ((*i)->number_attribute ("DCP")), - lexical_cast ((*i)->content ()) + raw_convert ((*i)->content ()) ); } } @@ -114,14 +126,68 @@ AudioMapping::get (int c, dcp::Channel d) const void AudioMapping::as_xml (xmlpp::Node* node) const { - node->add_child ("ContentChannels")->add_child_text (lexical_cast (_content_channels)); + node->add_child ("ContentChannels")->add_child_text (raw_convert (_content_channels)); for (int c = 0; c < _content_channels; ++c) { - for (int d = 0; d < MAX_AUDIO_CHANNELS; ++d) { + for (int d = 0; d < MAX_DCP_AUDIO_CHANNELS; ++d) { xmlpp::Element* t = node->add_child ("Gain"); - t->set_attribute ("Content", lexical_cast (c)); - t->set_attribute ("DCP", lexical_cast (d)); - t->add_child_text (lexical_cast (get (c, static_cast (d)))); + t->set_attribute ("Content", raw_convert (c)); + t->set_attribute ("DCP", raw_convert (d)); + t->add_child_text (raw_convert (get (c, static_cast (d)))); + } + } +} + +/** @return a string which is unique for a given AudioMapping configuration, for + * differentiation between different AudioMappings. + */ +string +AudioMapping::digest () const +{ + MD5Digester digester; + digester.add (_content_channels); + for (int i = 0; i < _content_channels; ++i) { + for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) { + digester.add (_gain[i][j]); } } + + return digester.get (); +} + +list +AudioMapping::mapped_dcp_channels () const +{ + static float const minus_96_db = 0.000015849; + + list mapped; + + for (vector >::const_iterator i = _gain.begin(); i != _gain.end(); ++i) { + for (size_t j = 0; j < i->size(); ++j) { + if (abs ((*i)[j]) > minus_96_db) { + mapped.push_back ((dcp::Channel) j); + } + } + } + + mapped.sort (); + mapped.unique (); + + return mapped; +} + +void +AudioMapping::unmap_all () +{ + for (vector >::iterator i = _gain.begin(); i != _gain.end(); ++i) { + for (vector::iterator j = i->begin(); j != i->end(); ++j) { + *j = 0; + } + } +} + +void +AudioMapping::set_name (int channel, string name) +{ + _name[channel] = name; }