diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-02-26 01:40:30 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-04-19 23:04:32 +0100 |
| commit | 58dce923b9d438a27ce1cd7e3125370f74d46e3a (patch) | |
| tree | 5a332a967aa3fb9bcb923f62b4832d8bb4d2bb17 /test | |
| parent | e7e06b4c9a6bf4459ff27a30cf347121c0e40e07 (diff) | |
Fix merging of audio in various circumstances.
Diffstat (limited to 'test')
| -rw-r--r-- | test/audio_buffers_test.cc | 4 | ||||
| -rw-r--r-- | test/audio_merger_test.cc | 98 | ||||
| -rw-r--r-- | test/dcpomatic_time_test.cc | 141 | ||||
| -rw-r--r-- | test/vf_test.cc | 6 |
4 files changed, 208 insertions, 41 deletions
diff --git a/test/audio_buffers_test.cc b/test/audio_buffers_test.cc index 25be3fe4b..c9231ae7f 100644 --- a/test/audio_buffers_test.cc +++ b/test/audio_buffers_test.cc @@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE (audio_buffers_move) int const to = 666; int const frames = 444; - buffers.move (from, to, frames); + buffers.move (frames, from, to); /* Re-seed and check the un-moved parts */ srand (84); @@ -288,7 +288,7 @@ BOOST_AUTO_TEST_CASE (audio_buffers_accumulate_frames) AudioBuffers b (3, 256); random_fill (b); - a.accumulate_frames (&b, 91, 44, 129); + a.accumulate_frames (&b, 129, 91, 44); srand (38); for (int i = 0; i < 256; ++i) { diff --git a/test/audio_merger_test.cc b/test/audio_merger_test.cc index a03d3b30f..2b6cdc267 100644 --- a/test/audio_merger_test.cc +++ b/test/audio_merger_test.cc @@ -24,8 +24,11 @@ #include <boost/bind.hpp> #include <boost/function.hpp> #include <boost/signals2.hpp> +#include <iostream> using std::pair; +using std::list; +using std::cout; using boost::shared_ptr; using boost::bind; @@ -33,34 +36,39 @@ static shared_ptr<const AudioBuffers> last_audio; int const sampling_rate = 48000; -BOOST_AUTO_TEST_CASE (audio_merger_test1) +static void +push (AudioMerger& merger, int from, int to, int at) { - AudioMerger merger (1, sampling_rate); - - /* Push 64 samples, 0 -> 63 at time 0 */ - shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); - for (int i = 0; i < 64; ++i) { - buffers->data()[0][i] = i; + shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, to - from)); + for (int i = 0; i < (to - from); ++i) { + buffers->data()[0][i] = from + i; } - merger.push (buffers, DCPTime()); + merger.push (buffers, DCPTime(at, sampling_rate)); +} - /* Push 64 samples, 0 -> 63 at time 22 */ - merger.push (buffers, DCPTime::from_frames (22, sampling_rate)); +/* Basic mixing, 2 overlapping pushes */ +BOOST_AUTO_TEST_CASE (audio_merger_test1) +{ + AudioMerger merger (sampling_rate); - pair<shared_ptr<AudioBuffers>, DCPTime> tb = merger.pull (DCPTime::from_frames (22, sampling_rate)); - BOOST_CHECK (tb.first != shared_ptr<const AudioBuffers> ()); - BOOST_CHECK_EQUAL (tb.first->frames(), 22); - BOOST_CHECK_EQUAL (tb.second.get(), 0); + push (merger, 0, 64, 0); + push (merger, 0, 64, 22); + + list<pair<shared_ptr<AudioBuffers>, DCPTime> > tb = merger.pull (DCPTime::from_frames (22, sampling_rate)); + BOOST_REQUIRE (tb.size() == 1); + BOOST_CHECK (tb.front().first != shared_ptr<const AudioBuffers> ()); + BOOST_CHECK_EQUAL (tb.front().first->frames(), 22); + BOOST_CHECK_EQUAL (tb.front().second.get(), 0); /* And they should be a staircase */ for (int i = 0; i < 22; ++i) { - BOOST_CHECK_EQUAL (tb.first->data()[0][i], i); + BOOST_CHECK_EQUAL (tb.front().first->data()[0][i], i); } tb = merger.pull (DCPTime::from_frames (22 + 64, sampling_rate)); - - BOOST_CHECK_EQUAL (tb.first->frames(), 64); - BOOST_CHECK_EQUAL (tb.second.get(), DCPTime::from_frames(22, sampling_rate).get()); + BOOST_REQUIRE (tb.size() == 1); + BOOST_CHECK_EQUAL (tb.front().first->frames(), 64); + BOOST_CHECK_EQUAL (tb.front().second.get(), DCPTime::from_frames(22, sampling_rate).get()); /* Check the sample values */ for (int i = 0; i < 64; ++i) { @@ -68,36 +76,56 @@ BOOST_AUTO_TEST_CASE (audio_merger_test1) if (i < (64 - 22)) { correct += i + 22; } - BOOST_CHECK_EQUAL (tb.first->data()[0][i], correct); + BOOST_CHECK_EQUAL (tb.front().first->data()[0][i], correct); } } +/* Push at non-zero time */ BOOST_AUTO_TEST_CASE (audio_merger_test2) { - AudioMerger merger (1, sampling_rate); + AudioMerger merger (sampling_rate); + + push (merger, 0, 64, 9); - /* Push 64 samples, 0 -> 63 at time 9 */ - shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); + /* There's nothing from 0 to 9 */ + list<pair<shared_ptr<AudioBuffers>, DCPTime> > tb = merger.pull (DCPTime::from_frames (9, sampling_rate)); + BOOST_CHECK_EQUAL (tb.size(), 0); + + /* Then there's our data at 9 */ + tb = merger.pull (DCPTime::from_frames (9 + 64, sampling_rate)); + + BOOST_CHECK_EQUAL (tb.front().first->frames(), 64); + BOOST_CHECK_EQUAL (tb.front().second.get(), DCPTime::from_frames(9, sampling_rate).get()); + + /* Check the sample values */ for (int i = 0; i < 64; ++i) { - buffers->data()[0][i] = i; + BOOST_CHECK_EQUAL (tb.front().first->data()[0][i], i); } - merger.push (buffers, DCPTime::from_frames (9, sampling_rate)); +} - pair<shared_ptr<AudioBuffers>, DCPTime> tb = merger.pull (DCPTime::from_frames (9, sampling_rate)); - BOOST_CHECK_EQUAL (tb.first->frames(), 9); - BOOST_CHECK_EQUAL (tb.second.get(), 0); +/* Push two non contiguous blocks */ +BOOST_AUTO_TEST_CASE (audio_merger_test3) +{ + AudioMerger merger (sampling_rate); - for (int i = 0; i < 9; ++i) { - BOOST_CHECK_EQUAL (tb.first->data()[0][i], 0); - } + push (merger, 0, 64, 17); + push (merger, 0, 64, 114); - tb = merger.pull (DCPTime::from_frames (9 + 64, sampling_rate)); + /* Get them back */ - BOOST_CHECK_EQUAL (tb.first->frames(), 64); - BOOST_CHECK_EQUAL (tb.second.get(), DCPTime::from_frames(9, sampling_rate).get()); + list<pair<shared_ptr<AudioBuffers>, DCPTime> > tb = merger.pull (DCPTime::from_frames (100, sampling_rate)); + BOOST_REQUIRE (tb.size() == 1); + BOOST_CHECK_EQUAL (tb.front().first->frames(), 64); + BOOST_CHECK_EQUAL (tb.front().second.get(), DCPTime::from_frames(17, sampling_rate).get()); + for (int i = 0; i < 64; ++i) { + BOOST_CHECK_EQUAL (tb.front().first->data()[0][i], i); + } - /* Check the sample values */ + tb = merger.pull (DCPTime::from_frames (200, sampling_rate)); + BOOST_REQUIRE (tb.size() == 1); + BOOST_CHECK_EQUAL (tb.front().first->frames(), 64); + BOOST_CHECK_EQUAL (tb.front().second.get(), DCPTime::from_frames(114, sampling_rate).get()); for (int i = 0; i < 64; ++i) { - BOOST_CHECK_EQUAL (tb.first->data()[0][i], i); + BOOST_CHECK_EQUAL (tb.front().first->data()[0][i], i); } } diff --git a/test/dcpomatic_time_test.cc b/test/dcpomatic_time_test.cc index ae03d91c0..7489e7a24 100644 --- a/test/dcpomatic_time_test.cc +++ b/test/dcpomatic_time_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2017 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,11 @@ */ -#include <boost/test/unit_test.hpp> #include "lib/dcpomatic_time.h" +#include <boost/test/unit_test.hpp> +#include <list> + +using std::list; BOOST_AUTO_TEST_CASE (dcpomatic_time_test) { @@ -72,3 +75,137 @@ BOOST_AUTO_TEST_CASE (dcpomatic_time_period_overlaps_test) BOOST_CHECK (a.overlap(b)); BOOST_CHECK (a.overlap(b).get() == DCPTimePeriod(DCPTime(1), DCPTime(9))); } + +BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test1) +{ + DCPTimePeriod A (DCPTime (0), DCPTime (106)); + list<DCPTimePeriod> B; + B.push_back (DCPTimePeriod (DCPTime (0), DCPTime (42))); + B.push_back (DCPTimePeriod (DCPTime (52), DCPTime (91))); + B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (106))); + list<DCPTimePeriod> r = subtract (A, B); + list<DCPTimePeriod>::const_iterator i = r.begin (); + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (42)); + BOOST_CHECK (i->to == DCPTime (52)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (91)); + BOOST_CHECK (i->to == DCPTime (94)); + ++i; + BOOST_REQUIRE (i == r.end ()); +} + +BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test2) +{ + DCPTimePeriod A (DCPTime (0), DCPTime (106)); + list<DCPTimePeriod> B; + B.push_back (DCPTimePeriod (DCPTime (14), DCPTime (42))); + B.push_back (DCPTimePeriod (DCPTime (52), DCPTime (91))); + B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (106))); + list<DCPTimePeriod> r = subtract (A, B); + list<DCPTimePeriod>::const_iterator i = r.begin (); + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (0)); + BOOST_CHECK (i->to == DCPTime (14)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (42)); + BOOST_CHECK (i->to == DCPTime (52)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (91)); + BOOST_CHECK (i->to == DCPTime (94)); + ++i; + BOOST_REQUIRE (i == r.end ()); +} + +BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test3) +{ + DCPTimePeriod A (DCPTime (0), DCPTime (106)); + list<DCPTimePeriod> B; + B.push_back (DCPTimePeriod (DCPTime (14), DCPTime (42))); + B.push_back (DCPTimePeriod (DCPTime (52), DCPTime (91))); + B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (99))); + list<DCPTimePeriod> r = subtract (A, B); + list<DCPTimePeriod>::const_iterator i = r.begin (); + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (0)); + BOOST_CHECK (i->to == DCPTime (14)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (42)); + BOOST_CHECK (i->to == DCPTime (52)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (91)); + BOOST_CHECK (i->to == DCPTime (94)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (99)); + BOOST_CHECK (i->to == DCPTime (106)); + ++i; + BOOST_REQUIRE (i == r.end ()); +} + +BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test4) +{ + DCPTimePeriod A (DCPTime (0), DCPTime (106)); + list<DCPTimePeriod> B; + list<DCPTimePeriod> r = subtract (A, B); + list<DCPTimePeriod>::const_iterator i = r.begin (); + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (0)); + BOOST_CHECK (i->to == DCPTime (106)); + ++i; + BOOST_REQUIRE (i == r.end ()); +} + +BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test5) +{ + DCPTimePeriod A (DCPTime (0), DCPTime (106)); + list<DCPTimePeriod> B; + B.push_back (DCPTimePeriod (DCPTime (14), DCPTime (42))); + B.push_back (DCPTimePeriod (DCPTime (42), DCPTime (91))); + B.push_back (DCPTimePeriod (DCPTime (94), DCPTime (99))); + list<DCPTimePeriod> r = subtract (A, B); + list<DCPTimePeriod>::const_iterator i = r.begin (); + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (0)); + BOOST_CHECK (i->to == DCPTime (14)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from ==DCPTime (91)); + BOOST_CHECK (i->to == DCPTime (94)); + ++i; + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (99)); + BOOST_CHECK (i->to == DCPTime (106)); + ++i; + BOOST_REQUIRE (i == r.end ()); +} + +BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test6) +{ + DCPTimePeriod A (DCPTime (0), DCPTime (106)); + list<DCPTimePeriod> B; + B.push_back (DCPTimePeriod (DCPTime (0), DCPTime (42))); + B.push_back (DCPTimePeriod (DCPTime (42), DCPTime (91))); + B.push_back (DCPTimePeriod (DCPTime (91), DCPTime (106))); + list<DCPTimePeriod> r = subtract (A, B); + BOOST_CHECK (r.empty()); +} + +BOOST_AUTO_TEST_CASE (dcpomatic_time_period_subtract_test7) +{ + DCPTimePeriod A (DCPTime (228), DCPTime (356)); + list<DCPTimePeriod> B; + B.push_back (DCPTimePeriod (DCPTime (34), DCPTime (162))); + list<DCPTimePeriod> r = subtract (A, B); + list<DCPTimePeriod>::const_iterator i = r.begin (); + BOOST_REQUIRE (i != r.end ()); + BOOST_CHECK (i->from == DCPTime (228)); + BOOST_CHECK (i->to == DCPTime (356)); + ++i; + BOOST_REQUIRE (i == r.end ()); +} diff --git a/test/vf_test.cc b/test/vf_test.cc index f4f8fb2a6..539b2b9fa 100644 --- a/test/vf_test.cc +++ b/test/vf_test.cc @@ -94,12 +94,14 @@ BOOST_AUTO_TEST_CASE (vf_test2) ov->make_dcp (); wait_for_jobs (); + std::cout << "incoming vf.\n"; + /* Make the VF */ shared_ptr<Film> vf = new_test_film ("vf_test2_vf"); vf->set_name ("vf_test2_vf"); vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST")); vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT); - shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content_factory (vf, ov->dir (ov->dcp_name ())).front()); + shared_ptr<DCPContent> dcp (new DCPContent (vf, ov->dir (ov->dcp_name ()))); BOOST_REQUIRE (dcp); vf->examine_and_add_content (dcp); wait_for_jobs (); @@ -156,7 +158,7 @@ BOOST_AUTO_TEST_CASE (vf_test3) vf->set_name ("vf_test3_vf"); vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST")); vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT); - shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content_factory(vf, ov->dir (ov->dcp_name ())).front()); + shared_ptr<DCPContent> dcp (new DCPContent (vf, ov->dir (ov->dcp_name ()))); BOOST_REQUIRE (dcp); dcp->set_trim_start (ContentTime::from_seconds (1)); dcp->set_trim_end (ContentTime::from_seconds (1)); |
