From 2072261bb07aac3d84f2cb0959042f5289f200dc Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 18 Apr 2012 22:22:47 +0000 Subject: Re-work fade operation to be closer to Mixbus; things below the top region's fades are implicitly faded in the opposite sense; restore short crossfades option. git-svn-id: svn://localhost/ardour2/branches/3.0@12022 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/test/playlist_read_test.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'libs/ardour/test/playlist_read_test.cc') diff --git a/libs/ardour/test/playlist_read_test.cc b/libs/ardour/test/playlist_read_test.cc index 55c6abe4ad..e016b3adc6 100644 --- a/libs/ardour/test/playlist_read_test.cc +++ b/libs/ardour/test/playlist_read_test.cc @@ -74,8 +74,8 @@ PlaylistReadTest::overlappingReadTest () { /* Overlapping read; ar0 and ar1 are both 1024 frames long, ar0 starts at 0, ar1 starts at 128. We test a read from 0 to 256, which should consist - of the start of ar0, with its fade in, followed by ar1's fade in (mixed with ar0) - and some more of ar1. + of the start of ar0, with its fade in, followed by ar1's fade in (mixed with ar0 + faded out with the inverse gain), and some more of ar1. */ boost::shared_ptr ar0 = boost::dynamic_pointer_cast (_region[0]); @@ -102,9 +102,11 @@ PlaylistReadTest::overlappingReadTest () /* ar0's fade in */ for (int i = 0; i < 64; ++i) { /* Note: this specific float casting is necessary so that the rounding - is done here the same as it is done in AudioPlaylist. + is done here the same as it is done in AudioPlaylist; the gain factor + must be computed using double precision, with the result then cast + to float. */ - CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / 63.0)), _buf[i], 1e-16); + CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / (double) 63)), _buf[i], 1e-16); } /* bit of ar0 */ @@ -112,10 +114,12 @@ PlaylistReadTest::overlappingReadTest () CPPUNIT_ASSERT_EQUAL (i, int (_buf[i])); } - /* ar1's fade in */ + /* ar1's fade in with faded-out ar0 */ for (int i = 0; i < 64; ++i) { /* Similar carry-on to above with float rounding */ - CPPUNIT_ASSERT_DOUBLES_EQUAL (i + 128 + float (i * float (i / 63.0)), _buf[i + 128], 1e-4); + float const from_ar0 = (128 + i) * float (1 - float (i / (double) 63)); + float const from_ar1 = i * float (i / (double) 63); + CPPUNIT_ASSERT_DOUBLES_EQUAL (from_ar0 + from_ar1, _buf[i + 128], 1e-16); } } @@ -143,10 +147,14 @@ PlaylistReadTest::transparentReadTest () _apl->read (_buf, _mbuf, _gbuf, 0, 1024, 0); - /* ar0 and ar1 fade-ins, mixed */ + /* ar0 and ar1 fade-ins; ar1 is on top, so its fade in will implicitly + fade in ar0 + */ for (int i = 0; i < 64; ++i) { - float const fade = i / 63.0; - CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * fade) * 2, _buf[i], 1e-16); + float const fade = i / (double) 63; + float const ar0 = i * fade * (1 - fade); + float const ar1 = i * fade; + CPPUNIT_ASSERT_DOUBLES_EQUAL (ar0 + ar1, _buf[i], 1e-16); } /* ar0 and ar1 bodies, mixed */ @@ -154,10 +162,12 @@ PlaylistReadTest::transparentReadTest () CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * 2), _buf[i], 1e-16); } - /* ar0 and ar1 fade-outs, mixed */ + /* ar0 and ar1 fade-outs, mixed (with implicit fade-in of ar0) */ for (int i = (1024 - 64); i < 1024; ++i) { - float const fade = (1023 - i) / 63.0; - CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * fade) * 2, _buf[i], 1e-16); + float const fade = (1023 - i) / (double) 63; + float const ar0 = i * fade * (1 - fade); + float const ar1 = i * fade; + CPPUNIT_ASSERT_DOUBLES_EQUAL (ar0 + ar1, _buf[i], 1e-16); } } -- cgit v1.2.3