X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=test%2Fsilence_padding_test.cc;h=2bc0c3bb66c3bfacad9471342deaa5423cf2431b;hp=e3b0243e0bbe99b004a54c8a325ec4174ec0e0bd;hb=254b3044d72de6b033d7c584f5abd2b9aa70aad5;hpb=d19b7cbd3d1a428697bc9b26fdc0be36fafa444a diff --git a/test/silence_padding_test.cc b/test/silence_padding_test.cc index e3b0243e0..2bc0c3bb6 100644 --- a/test/silence_padding_test.cc +++ b/test/silence_padding_test.cc @@ -1,60 +1,130 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic 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, + DCP-o-matic 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. + along with DCP-o-matic. If not, see . */ -#include -#include -#include -#include -#include "sndfile_content.h" +/** @file test/silence_padding_test.cc + * @brief Test the padding (with silence) of a mono source to a 6-channel DCP. + * @ingroup specific + */ + +#include "lib/ffmpeg_content.h" +#include "lib/film.h" +#include "lib/dcp_content_type.h" +#include "lib/ratio.h" +#include "test.h" +#include +#include +#include +#include +#include +#include +#include +#include +using std::string; using boost::lexical_cast; +using boost::shared_ptr; -static void test_silence_padding (int channels) +static void +test_silence_padding (int channels) { string const film_name = "silence_padding_test_" + lexical_cast (channels); shared_ptr film = new_test_film (film_name); - film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR")); + film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR")); film->set_container (Ratio::from_id ("185")); film->set_name (film_name); - shared_ptr content (new SndfileContent (film, "test/data/staircase.wav")); + shared_ptr content (new FFmpegContent("test/data/staircase.wav")); film->examine_and_add_content (content); wait_for_jobs (); - film->set_dcp_audio_channels (channels); + film->set_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 ()); + dcp::DCP check (path.string ()); check.read (); - shared_ptr sound_asset = check.cpls().front()->reels().front()->main_sound (); + shared_ptr sound_asset = check.cpls().front()->reels().front()->main_sound (); BOOST_CHECK (sound_asset); - BOOST_CHECK (sound_asset->channels () == channels); + BOOST_CHECK_EQUAL (sound_asset->asset()->channels (), channels); + + /* Sample index in the DCP */ + int n = 0; + /* DCP sound asset frame */ + int frame = 0; + + while (n < sound_asset->asset()->intrinsic_duration()) { + shared_ptr sound_frame = sound_asset->asset()->start_read()->get_frame (frame++); + uint8_t const * d = sound_frame->data (); + + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->asset()->channels())) { + + if (sound_asset->asset()->channels() > 0) { + /* L should be silent */ + int const sample = d[i + 1] | (d[i + 2] << 8); + BOOST_CHECK_EQUAL (sample, 0); + } + + if (sound_asset->asset()->channels() > 1) { + /* R should be silent */ + int const sample = d[i + 4] | (d[i + 5] << 8); + BOOST_CHECK_EQUAL (sample, 0); + } + + if (sound_asset->asset()->channels() > 2) { + /* Mono input so it will appear on centre */ + int const sample = d[i + 7] | (d[i + 8] << 8); + BOOST_CHECK_EQUAL (sample, n); + } + + if (sound_asset->asset()->channels() > 3) { + /* Lfe should be silent */ + int const sample = d[i + 10] | (d[i + 11] << 8); + BOOST_CHECK_EQUAL (sample, 0); + } + + if (sound_asset->asset()->channels() > 4) { + /* Ls should be silent */ + int const sample = d[i + 13] | (d[i + 14] << 8); + BOOST_CHECK_EQUAL (sample, 0); + } + + + if (sound_asset->asset()->channels() > 5) { + /* Rs should be silent */ + int const sample = d[i + 16] | (d[i + 17] << 8); + BOOST_CHECK_EQUAL (sample, 0); + } + + ++n; + } + } + } BOOST_AUTO_TEST_CASE (silence_padding_test) { - for (int i = 1; i < MAX_AUDIO_CHANNELS; ++i) { + for (int i = 1; i < MAX_DCP_AUDIO_CHANNELS; ++i) { test_silence_padding (i); } }