Add test for a transparent region on top of (and enclosing) another.
authorCarl Hetherington <carl@carlh.net>
Thu, 24 May 2012 00:53:23 +0000 (00:53 +0000)
committerCarl Hetherington <carl@carlh.net>
Thu, 24 May 2012 00:53:23 +0000 (00:53 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12409 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/test/playlist_read_test.cc
libs/ardour/test/playlist_read_test.h

index ac76198ae54cefe5451df5ff615fafcaaba7fe61..04dc8081fed0280f9267e57be3867b296598bc78 100644 (file)
@@ -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<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_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<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_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);
+
+       }
+}
index be891a500407c75c49166574782c8ed777292922..4d0cabee88cdddc9f386ae85ca3e7fdefb2e79ce 100644 (file)
@@ -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: