/*
- Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2015 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
*/
-#include <libxml++/libxml++.h>
-#include <libcxml/cxml.h>
-#include <dcp/raw_convert.h>
#include "audio_mapping.h"
#include "util.h"
#include "md5_digester.h"
+#include "raw_convert.h"
+#include <libcxml/cxml.h>
+#include <libxml++/libxml++.h>
using std::list;
using std::cout;
using std::pair;
using std::string;
using std::min;
+using std::vector;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
-using dcp::raw_convert;
AudioMapping::AudioMapping ()
: _content_channels (0)
}
-/** Create a default AudioMapping for a given channel count.
+/** Create an empty AudioMapping for a given channel count.
* @param channels Number of channels.
*/
AudioMapping::AudioMapping (int channels)
for (int i = 0; i < _content_channels; ++i) {
_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_DCP_AUDIO_CHANNELS; ++j) {
_gain[i][j] = 0;
}
}
+}
+
+void
+AudioMapping::make_default ()
+{
+ make_zero ();
if (_content_channels == 1) {
/* Mono -> Centre */
return digester.get ();
}
+
+list<dcp::Channel>
+AudioMapping::mapped_dcp_channels () const
+{
+ static float const minus_96_db = 0.000015849;
+
+ list<dcp::Channel> mapped;
+
+ for (vector<vector<float> >::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<vector<float> >::iterator i = _gain.begin(); i != _gain.end(); ++i) {
+ for (vector<float>::iterator j = i->begin(); j != i->end(); ++j) {
+ *j = 0;
+ }
+ }
+}
+
+void
+AudioMapping::set_name (int channel, string name)
+{
+ _name[channel] = name;
+}