From: Carl Hetherington Date: Thu, 24 May 2012 00:53:23 +0000 (+0000) Subject: Add test for a transparent region on top of (and enclosing) another. X-Git-Tag: 3.0~1394 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=ba56c4bd032483d20c4815528a7df1a7894bed9a;p=ardour.git Add test for a transparent region on top of (and enclosing) another. git-svn-id: svn://localhost/ardour2/branches/3.0@12409 d708f5d6-7413-0410-9779-e7cbd77b26cf --- diff --git a/libs/ardour/test/playlist_read_test.cc b/libs/ardour/test/playlist_read_test.cc index ac76198ae5..04dc8081fe 100644 --- a/libs/ardour/test/playlist_read_test.cc +++ b/libs/ardour/test/playlist_read_test.cc @@ -208,3 +208,74 @@ PlaylistReadTest::check_staircase (Sample* b, int offset, int N) CPPUNIT_ASSERT_EQUAL (j, int (b[i])); } } + +/* Check the case where we have + * |----------- Region A (transparent) ------------------| + * |---- Region B (opaque) --| + * + * The result should be a mix of the two during region B's time. + */ + +void +PlaylistReadTest::enclosedTransparentReadTest () +{ + boost::shared_ptr ar0 = boost::dynamic_pointer_cast (_region[0]); + ar0->set_name ("ar0"); + _apl->add_region (ar0, 256); + /* These calls will result in a 64-sample fade */ + ar0->set_fade_in_length (0); + ar0->set_fade_out_length (0); + ar0->set_length (256); + + boost::shared_ptr ar1 = boost::dynamic_pointer_cast (_region[1]); + ar1->set_name ("ar1"); + _apl->add_region (ar1, 0); + /* These calls will result in a 64-sample fade */ + ar1->set_fade_in_length (0); + ar1->set_fade_out_length (0); + ar1->set_length (1024); + ar1->set_opaque (false); + + _apl->read (_buf, _mbuf, _gbuf, 0, 1024, 0); + + /* First 64 samples should just be ar1, faded in */ + for (int i = 0; i < 64; ++i) { + CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / 63.0)), _buf[i], 1e-16); + } + + /* Then some of ar1 with no fade */ + for (int i = 64; i < 256; ++i) { + CPPUNIT_ASSERT_DOUBLES_EQUAL (i, _buf[i], 1e-16); + } + + /* Then ar1 + ar0 (faded in) for 64 samples */ + for (int i = 256; i < (256 + 64); ++i) { + CPPUNIT_ASSERT_DOUBLES_EQUAL (i + float ((i - 256) * float ((i - 256) / 63.0)), _buf[i], 1e-16); + } + + /* Then ar1 + ar0 for 128 samples */ + for (int i = (256 + 64); i < (256 + 64 + 128); ++i) { + CPPUNIT_ASSERT_DOUBLES_EQUAL (i + i - (256 + 64) + 64, _buf[i], 1e-16); + } + + /* Then ar1 + ar0 (faded out) for 64 samples */ + for (int i = (256 + 64 + 128); i < 512; ++i) { + float const ar0_without_fade = i - 256; + /* See above regarding VERY_SMALL_SIGNAL SNAFU */ + float const fade = (((double) 1 - 0.0000001) / 63) * (511 - i) + 0.0000001; + CPPUNIT_ASSERT_DOUBLES_EQUAL (i + float (ar0_without_fade * fade), _buf[i], 1e-16); + } + + /* Then just ar1 for a while */ + for (int i = 512; i < (1024 - 64); ++i) { + CPPUNIT_ASSERT_DOUBLES_EQUAL (i, _buf[i], 1e-16); + } + + /* And finally ar1's fade out */ + for (int i = (1024 - 64); i < 1024; ++i) { + /* See above regarding VERY_SMALL_SIGNAL SNAFU */ + float const fade = (((double) 1 - 0.0000001) / 63) * (1023 - i) + 0.0000001; + CPPUNIT_ASSERT_DOUBLES_EQUAL (i * fade, _buf[i], 1e-16); + + } +} diff --git a/libs/ardour/test/playlist_read_test.h b/libs/ardour/test/playlist_read_test.h index be891a5004..4d0cabee88 100644 --- a/libs/ardour/test/playlist_read_test.h +++ b/libs/ardour/test/playlist_read_test.h @@ -7,6 +7,7 @@ class PlaylistReadTest : public TestNeedingPlaylistAndRegions CPPUNIT_TEST (singleReadTest); CPPUNIT_TEST (overlappingReadTest); CPPUNIT_TEST (transparentReadTest); + CPPUNIT_TEST (enclosedTransparentReadTest); CPPUNIT_TEST (miscReadTest); CPPUNIT_TEST_SUITE_END (); @@ -17,6 +18,7 @@ public: void singleReadTest (); void overlappingReadTest (); void transparentReadTest (); + void enclosedTransparentReadTest (); void miscReadTest (); private: