Add silence padding test.
authorCarl Hetherington <cth@carlh.net>
Fri, 12 Jul 2013 12:49:57 +0000 (13:49 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 12 Jul 2013 12:49:57 +0000 (13:49 +0100)
src/lib/audio_buffers.cc
src/lib/player.cc
src/lib/sndfile_content.h
test/silence_padding_test.cc [new file with mode: 0644]
test/test.cc

index 6d4eb85147545fab2a3610f86d285e944dd275b3..7b3af91e0069324efb4ca69f5e7c41a19ead512a 100644 (file)
@@ -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];
index 7ab72d9a15379b7c71fade6ba432cdb686b77546..61764a39dcf1c9b05f6903665070a8f2e2b139fa 100644 (file)
@@ -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;
index 876d66088c6f7a5a84f4b289de622d43256d1d97..3d3f0c36c3bce3d0ed298603d8571805f908375c 100644 (file)
@@ -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 (file)
index 0000000..e3b0243
--- /dev/null
@@ -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);
+       }
+}
index dfa38c8f4a488b3e179d5cf21734ec043187d356..1f0d2db5b45ab63442cce66b9f892a6bc585683b 100644 (file)
@@ -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"