summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-12 13:49:57 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-12 13:49:57 +0100
commitd19b7cbd3d1a428697bc9b26fdc0be36fafa444a (patch)
tree599e541098b179841c0fc268c5539dd4a0f87499
parentf0233eb1e3d6dfd9284d6c5e4865011550e2a0e3 (diff)
Add silence padding test.
-rw-r--r--src/lib/audio_buffers.cc1
-rw-r--r--src/lib/player.cc4
-rw-r--r--src/lib/sndfile_content.h5
-rw-r--r--test/silence_padding_test.cc60
-rw-r--r--test/test.cc1
5 files changed, 70 insertions, 1 deletions
diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc
index 6d4eb8514..7b3af91e0 100644
--- a/src/lib/audio_buffers.cc
+++ b/src/lib/audio_buffers.cc
@@ -209,6 +209,7 @@ AudioBuffers::accumulate_channel (AudioBuffers const * from, int from_channel, i
{
int const N = frames ();
assert (from->frames() == N);
+ assert (to_channel <= _channels);
float* s = from->data (from_channel);
float* d = _data[to_channel];
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 7ab72d9a1..61764a39d 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -271,7 +271,9 @@ Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers
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) {
- dcp_mapped->accumulate_channel (audio.get(), i->first, i->second);
+ if (i->first < audio->channels() && i->second < dcp_mapped->channels()) {
+ dcp_mapped->accumulate_channel (audio.get(), i->first, i->second);
+ }
}
audio = dcp_mapped;
diff --git a/src/lib/sndfile_content.h b/src/lib/sndfile_content.h
index 876d66088..3d3f0c36c 100644
--- a/src/lib/sndfile_content.h
+++ b/src/lib/sndfile_content.h
@@ -17,6 +17,9 @@
*/
+#ifndef DVDOMATIC_SNDFILE_CONTENT_H
+#define DVDOMATIC_SNDFILE_CONTENT_H
+
extern "C" {
#include <libavutil/audioconvert.h>
}
@@ -76,3 +79,5 @@ private:
int _audio_frame_rate;
AudioMapping _audio_mapping;
};
+
+#endif
diff --git a/test/silence_padding_test.cc b/test/silence_padding_test.cc
new file mode 100644
index 000000000..e3b0243e0
--- /dev/null
+++ b/test/silence_padding_test.cc
@@ -0,0 +1,60 @@
+/*
+ Copyright (C) 2013 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <libdcp/cpl.h>
+#include <libdcp/dcp.h>
+#include <libdcp/sound_asset.h>
+#include <libdcp/reel.h>
+#include "sndfile_content.h"
+
+using boost::lexical_cast;
+
+static void test_silence_padding (int channels)
+{
+ string const film_name = "silence_padding_test_" + lexical_cast<string> (channels);
+ shared_ptr<Film> film = new_test_film (film_name);
+ film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR"));
+ film->set_container (Ratio::from_id ("185"));
+ film->set_name (film_name);
+
+ shared_ptr<SndfileContent> content (new SndfileContent (film, "test/data/staircase.wav"));
+ film->examine_and_add_content (content);
+ wait_for_jobs ();
+
+ film->set_dcp_audio_channels (channels);
+ film->make_dcp ();
+ wait_for_jobs ();
+
+ boost::filesystem::path path = "build/test";
+ path /= film_name;
+ path /= film->dcp_name ();
+ libdcp::DCP check (path.string ());
+ check.read ();
+
+ shared_ptr<const libdcp::SoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound ();
+ BOOST_CHECK (sound_asset);
+ BOOST_CHECK (sound_asset->channels () == channels);
+}
+
+BOOST_AUTO_TEST_CASE (silence_padding_test)
+{
+ for (int i = 1; i < MAX_AUDIO_CHANNELS; ++i) {
+ test_silence_padding (i);
+ }
+}
diff --git a/test/test.cc b/test/test.cc
index dfa38c8f4..1f0d2db5b 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -160,6 +160,7 @@ wait_for_jobs ()
while (JobManager::instance()->work_to_do ()) {}
}
+#include "silence_padding_test.cc"
#include "audio_delay_test.cc"
#include "ffmpeg_pts_offset.cc"
#include "ffmpeg_examiner_test.cc"