2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/test/unit_test.hpp>
23 #include <dcp/sound_mxf.h>
24 #include <dcp/sound_frame.h>
26 #include <dcp/reel_sound_asset.h>
27 #include "lib/sndfile_content.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/ratio.h"
34 using boost::lexical_cast;
35 using boost::shared_ptr;
37 static void test_silence_padding (int channels)
39 string const film_name = "silence_padding_test_" + lexical_cast<string> (channels);
40 shared_ptr<Film> film = new_test_film (film_name);
41 film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR"));
42 film->set_container (Ratio::from_id ("185"));
43 film->set_name (film_name);
45 shared_ptr<SndfileContent> content (new SndfileContent (film, "test/data/staircase.wav"));
46 film->examine_and_add_content (content);
49 film->set_audio_channels (channels);
53 boost::filesystem::path path = "build/test";
55 path /= film->dcp_name ();
56 dcp::DCP check (path.string ());
59 shared_ptr<const dcp::ReelSoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound ();
60 BOOST_CHECK (sound_asset);
61 BOOST_CHECK (sound_asset->mxf()->channels () == channels);
63 /* Sample index in the DCP */
65 /* DCP sound asset frame */
68 while (n < sound_asset->mxf()->intrinsic_duration()) {
69 shared_ptr<const dcp::SoundFrame> sound_frame = sound_asset->mxf()->get_frame (frame++);
70 uint8_t const * d = sound_frame->data ();
72 for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->mxf()->channels())) {
74 if (sound_asset->mxf()->channels() > 0) {
75 /* L should be silent */
76 int const sample = d[i + 0] | (d[i + 1] << 8);
77 BOOST_CHECK_EQUAL (sample, 0);
80 if (sound_asset->mxf()->channels() > 1) {
81 /* R should be silent */
82 int const sample = d[i + 2] | (d[i + 3] << 8);
83 BOOST_CHECK_EQUAL (sample, 0);
86 if (sound_asset->mxf()->channels() > 2) {
87 /* Mono input so it will appear on centre */
88 int const sample = d[i + 7] | (d[i + 8] << 8);
89 BOOST_CHECK_EQUAL (sample, n);
92 if (sound_asset->mxf()->channels() > 3) {
93 /* Lfe should be silent */
94 int const sample = d[i + 9] | (d[i + 10] << 8);
95 BOOST_CHECK_EQUAL (sample, 0);
98 if (sound_asset->mxf()->channels() > 4) {
99 /* Ls should be silent */
100 int const sample = d[i + 11] | (d[i + 12] << 8);
101 BOOST_CHECK_EQUAL (sample, 0);
105 if (sound_asset->mxf()->channels() > 5) {
106 /* Rs should be silent */
107 int const sample = d[i + 13] | (d[i + 14] << 8);
108 BOOST_CHECK_EQUAL (sample, 0);
117 BOOST_AUTO_TEST_CASE (silence_padding_test)
119 for (int i = 1; i < MAX_AUDIO_CHANNELS; ++i) {
120 test_silence_padding (i);