diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-07-11 15:50:18 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-07-11 15:50:18 +0100 |
| commit | 4122f932b1dc25f7a4592f49f2c9ab19d63b3a4e (patch) | |
| tree | da592cad1e8e7293d22dcc45839de2a0f11a1d68 /test | |
| parent | bba1bd9b08eb78bda8cdf7fa1393f3eeb2a504d9 (diff) | |
Add test for audio delay, and do it in the player rather than the decoder.
Diffstat (limited to 'test')
| -rw-r--r-- | test/audio_delay_test.cc | 89 | ||||
| -rw-r--r-- | test/test.cc | 15 |
2 files changed, 100 insertions, 4 deletions
diff --git a/test/audio_delay_test.cc b/test/audio_delay_test.cc new file mode 100644 index 000000000..5574bd627 --- /dev/null +++ b/test/audio_delay_test.cc @@ -0,0 +1,89 @@ +/* + 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/sound_frame.h> +#include <libdcp/cpl.h> +#include <libdcp/reel.h> +#include <libdcp/sound_asset.h> +#include "sndfile_content.h" + +using boost::lexical_cast; + +static +void test_audio_delay (int delay_in_ms) +{ + string const film_name = "audio_delay_test_" + lexical_cast<string> (delay_in_ms); + 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")); + content->set_audio_delay (delay_in_ms); + film->examine_and_add_content (content); + wait_for_jobs (); + + 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); + + /* Sample index in the DCP */ + int n = 0; + /* DCP sound asset frame */ + int frame = 0; + /* Delay in frames */ + int const delay_in_frames = delay_in_ms * 48000 / 1000; + bool done = false; + + while (n < sound_asset->intrinsic_duration()) { + shared_ptr<const libdcp::SoundFrame> sound_frame = sound_asset->get_frame (frame++); + uint8_t const * d = sound_frame->data (); + + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->channels())) { + + /* Mono input so it will appear on centre */ + int const sample = d[i + 7] | (d[i + 8] << 8); + + int delayed = n - delay_in_frames; + if (delayed < 0 || delayed >= 4800) { + delayed = 0; + } + + BOOST_CHECK_EQUAL (sample, delayed); + ++n; + } + } +} + + +/* Test audio delay when specified in a piece of audio content */ +BOOST_AUTO_TEST_CASE (audio_delay_test) +{ + test_audio_delay (0); + test_audio_delay (42); + test_audio_delay (-66); +} diff --git a/test/test.cc b/test/test.cc index 0a682383a..dfa38c8f4 100644 --- a/test/test.cc +++ b/test/test.cc @@ -75,7 +75,7 @@ struct TestConfig BOOST_GLOBAL_FIXTURE (TestConfig); -boost::filesystem::path +static boost::filesystem::path test_film_dir (string name) { boost::filesystem::path p; @@ -85,7 +85,7 @@ test_film_dir (string name) return p; } -shared_ptr<Film> +static shared_ptr<Film> new_test_film (string name) { boost::filesystem::path p = test_film_dir (name); @@ -98,7 +98,7 @@ new_test_film (string name) return f; } -void +static void check_file (string ref, string check) { uintmax_t N = boost::filesystem::file_size (ref); @@ -136,7 +136,7 @@ note (libdcp::NoteType, string n) cout << n << "\n"; } -void +static void check_dcp (string ref, string check) { libdcp::DCP ref_dcp (ref); @@ -154,6 +154,13 @@ check_dcp (string ref, string check) BOOST_CHECK (ref_dcp.equals (check_dcp, options, boost::bind (note, _1, _2))); } +static void +wait_for_jobs () +{ + while (JobManager::instance()->work_to_do ()) {} +} + +#include "audio_delay_test.cc" #include "ffmpeg_pts_offset.cc" #include "ffmpeg_examiner_test.cc" #include "black_fill_test.cc" |
