From 1dc8d99d78908222545e78f41cff08896f46a529 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 9 Jun 2012 23:07:27 +0000 Subject: Clean up libardour tests a bit. git-svn-id: svn://localhost/ardour2/branches/3.0@12641 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/test/playlist_read_test.cc | 196 ++++++++++++++++----------------- 1 file changed, 97 insertions(+), 99 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 7b1f2aa797..a1b4579e8a 100644 --- a/libs/ardour/test/playlist_read_test.cc +++ b/libs/ardour/test/playlist_read_test.cc @@ -1,3 +1,21 @@ +/* + Copyright (C) 2012 Paul Davis + + 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 "ardour/playlist.h" #include "ardour/region.h" #include "ardour/audioplaylist.h" @@ -14,7 +32,7 @@ using namespace ARDOUR; void PlaylistReadTest::setUp () { - TestNeedingPlaylistAndRegions::setUp (); + AudioRegionTest::setUp (); _N = 1024; _buf = new Sample[_N]; @@ -23,8 +41,6 @@ PlaylistReadTest::setUp () _session->config.set_auto_xfade (false); - _apl = boost::dynamic_pointer_cast (_playlist); - for (int i = 0; i < _N; ++i) { _buf[i] = 0; } @@ -37,9 +53,7 @@ PlaylistReadTest::tearDown () delete[] _mbuf; delete[] _gbuf; - _apl.reset (); - - TestNeedingPlaylistAndRegions::tearDown (); + AudioRegionTest::tearDown (); } void @@ -47,15 +61,13 @@ PlaylistReadTest::singleReadTest () { /* Single-region read with fades */ - boost::shared_ptr ar0 = boost::dynamic_pointer_cast (_region[0]); - ar0->set_name ("ar0"); - _apl->add_region (ar0, 0); - ar0->set_default_fade_in (); - ar0->set_default_fade_out (); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_in->back()->when); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_out->back()->when); - ar0->set_length (1024); - _apl->read (_buf, _mbuf, _gbuf, 0, 256, 0); + _audio_playlist->add_region (_ar[0], 0); + _ar[0]->set_default_fade_in (); + _ar[0]->set_default_fade_out (); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_in->back()->when); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_out->back()->when); + _ar[0]->set_length (1024); + _audio_playlist->read (_buf, _mbuf, _gbuf, 0, 256, 0); for (int i = 0; i < 64; ++i) { /* Note: this specific float casting is necessary so that the rounding @@ -72,42 +84,38 @@ PlaylistReadTest::singleReadTest () void 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 - faded out with the inverse gain), and some more of ar1. + /* Overlapping read; _ar[0] and _ar[1] are both 1024 frames long, _ar[0] starts at 0, + _ar[1] starts at 128. We test a read from 0 to 256, which should consist + of the start of _ar[0], with its fade in, followed by _ar[1]'s fade in (mixed with _ar[0] + faded out with the inverse gain), and some more of _ar[1]. */ - boost::shared_ptr ar0 = boost::dynamic_pointer_cast (_region[0]); - ar0->set_name ("ar0"); - _apl->add_region (ar0, 0); - ar0->set_default_fade_in (); - ar0->set_default_fade_out (); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_in->back()->when); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_out->back()->when); - ar0->set_length (1024); + _audio_playlist->add_region (_ar[0], 0); + _ar[0]->set_default_fade_in (); + _ar[0]->set_default_fade_out (); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_in->back()->when); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_out->back()->when); + _ar[0]->set_length (1024); /* Note: these are ordinary fades, not xfades */ - CPPUNIT_ASSERT_EQUAL (false, ar0->fade_in_is_xfade()); - CPPUNIT_ASSERT_EQUAL (false, ar0->fade_out_is_xfade()); + CPPUNIT_ASSERT_EQUAL (false, _ar[0]->fade_in_is_xfade()); + CPPUNIT_ASSERT_EQUAL (false, _ar[0]->fade_out_is_xfade()); - boost::shared_ptr ar1 = boost::dynamic_pointer_cast (_region[1]); - ar1->set_name ("ar1"); - _apl->add_region (ar1, 128); - ar1->set_default_fade_in (); - ar1->set_default_fade_out (); + _audio_playlist->add_region (_ar[1], 128); + _ar[1]->set_default_fade_in (); + _ar[1]->set_default_fade_out (); /* Note: these are ordinary fades, not xfades */ - CPPUNIT_ASSERT_EQUAL (false, ar1->fade_in_is_xfade()); - CPPUNIT_ASSERT_EQUAL (false, ar1->fade_out_is_xfade()); + CPPUNIT_ASSERT_EQUAL (false, _ar[1]->fade_in_is_xfade()); + CPPUNIT_ASSERT_EQUAL (false, _ar[1]->fade_out_is_xfade()); - CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_in->back()->when); - CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_out->back()->when); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[1]->_fade_in->back()->when); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[1]->_fade_out->back()->when); - ar1->set_length (1024); - _apl->read (_buf, _mbuf, _gbuf, 0, 256, 0); + _ar[1]->set_length (1024); + _audio_playlist->read (_buf, _mbuf, _gbuf, 0, 256, 0); - /* ar0's fade in */ + /* _ar[0]'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; the gain factor @@ -117,12 +125,12 @@ PlaylistReadTest::overlappingReadTest () CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / (double) 63)), _buf[i], 1e-16); } - /* bit of ar0 */ + /* bit of _ar[0] */ for (int i = 64; i < 128; ++i) { CPPUNIT_ASSERT_EQUAL (i, int (_buf[i])); } - /* ar1's fade in with faded-out ar0 */ + /* _ar[1]'s fade in with faded-out _ar[0] */ for (int i = 0; i < 64; ++i) { /* Similar carry-on to above with float rounding */ float const from_ar0 = (128 + i) * float (1 - (i / (double) 63)); @@ -134,29 +142,25 @@ PlaylistReadTest::overlappingReadTest () void PlaylistReadTest::transparentReadTest () { - boost::shared_ptr ar0 = boost::dynamic_pointer_cast (_region[0]); - ar0->set_name ("ar0"); - _apl->add_region (ar0, 0); - ar0->set_default_fade_in (); - ar0->set_default_fade_out (); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_in->back()->when); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_out->back()->when); - ar0->set_length (1024); + _audio_playlist->add_region (_ar[0], 0); + _ar[0]->set_default_fade_in (); + _ar[0]->set_default_fade_out (); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_in->back()->when); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_out->back()->when); + _ar[0]->set_length (1024); - boost::shared_ptr ar1 = boost::dynamic_pointer_cast (_region[1]); - ar1->set_name ("ar1"); - _apl->add_region (ar1, 0); - ar1->set_default_fade_in (); - ar1->set_default_fade_out (); - CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_in->back()->when); - CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_out->back()->when); - ar1->set_length (1024); - ar1->set_opaque (false); - - _apl->read (_buf, _mbuf, _gbuf, 0, 1024, 0); - - /* ar0 and ar1 fade-ins; ar1 is on top, but it is transparent, so - its fade in will not affect ar0; ar0 will just fade in by itself, + _audio_playlist->add_region (_ar[1], 0); + _ar[1]->set_default_fade_in (); + _ar[1]->set_default_fade_out (); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[1]->_fade_in->back()->when); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[1]->_fade_out->back()->when); + _ar[1]->set_length (1024); + _ar[1]->set_opaque (false); + + _audio_playlist->read (_buf, _mbuf, _gbuf, 0, 1024, 0); + + /* _ar[0] and _ar[1] fade-ins; _ar[1] is on top, but it is transparent, so + its fade in will not affect _ar[0]; _ar[0] will just fade in by itself, and the two will be mixed. */ for (int i = 0; i < 64; ++i) { @@ -166,12 +170,12 @@ PlaylistReadTest::transparentReadTest () CPPUNIT_ASSERT_DOUBLES_EQUAL (ar0 + ar1, _buf[i], 1e-16); } - /* ar0 and ar1 bodies, mixed */ + /* _ar[0] and _ar[1] bodies, mixed */ for (int i = 64; i < (1024 - 64); ++i) { CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * 2), _buf[i], 1e-16); } - /* ar0 and ar1 fade-outs, mixed */ + /* _ar[0] and _ar[1] fade-outs, mixed */ for (int i = (1024 - 64); i < 1024; ++i) { /* Ardour fades out from 1 to VERY_SMALL_SIGNAL, which is 0.0000001, so this fade out expression is a little long-winded. @@ -189,23 +193,21 @@ PlaylistReadTest::transparentReadTest () void PlaylistReadTest::miscReadTest () { - boost::shared_ptr ar0 = boost::dynamic_pointer_cast (_region[0]); - ar0->set_name ("ar0"); - _apl->add_region (ar0, 0); - ar0->set_default_fade_in (); - ar0->set_default_fade_out (); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_in->back()->when); - CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_out->back()->when); - ar0->set_length (128); + _audio_playlist->add_region (_ar[0], 0); + _ar[0]->set_default_fade_in (); + _ar[0]->set_default_fade_out (); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_in->back()->when); + CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_out->back()->when); + _ar[0]->set_length (128); /* Read for just longer than the region */ - _apl->read (_buf, _mbuf, _gbuf, 0, 129, 0); + _audio_playlist->read (_buf, _mbuf, _gbuf, 0, 129, 0); /* Read for much longer than the region */ - _apl->read (_buf, _mbuf, _gbuf, 0, 1024, 0); + _audio_playlist->read (_buf, _mbuf, _gbuf, 0, 1024, 0); /* Read one sample */ - _apl->read (_buf, _mbuf, _gbuf, 53, 54, 0); + _audio_playlist->read (_buf, _mbuf, _gbuf, 53, 54, 0); } void @@ -227,46 +229,42 @@ PlaylistReadTest::check_staircase (Sample* b, int offset, int N) void PlaylistReadTest::enclosedTransparentReadTest () { - boost::shared_ptr ar0 = boost::dynamic_pointer_cast (_region[0]); - ar0->set_name ("ar0"); - _apl->add_region (ar0, 256); + _audio_playlist->add_region (_ar[0], 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); + _ar[0]->set_fade_in_length (0); + _ar[0]->set_fade_out_length (0); + _ar[0]->set_length (256); - boost::shared_ptr ar1 = boost::dynamic_pointer_cast (_region[1]); - ar1->set_name ("ar1"); - _apl->add_region (ar1, 0); + _audio_playlist->add_region (_ar[1], 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); + _ar[1]->set_fade_in_length (0); + _ar[1]->set_fade_out_length (0); + _ar[1]->set_length (1024); + _ar[1]->set_opaque (false); - _apl->read (_buf, _mbuf, _gbuf, 0, 1024, 0); + _audio_playlist->read (_buf, _mbuf, _gbuf, 0, 1024, 0); - /* First 64 samples should just be ar1, faded in */ + /* First 64 samples should just be _ar[1], 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 */ + /* Then some of _ar[1] 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 */ + /* Then _ar[1] + _ar[0] (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 */ + /* Then _ar[1] + _ar[0] 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 */ + /* Then _ar[1] + _ar[0] (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 */ @@ -274,12 +272,12 @@ PlaylistReadTest::enclosedTransparentReadTest () CPPUNIT_ASSERT_DOUBLES_EQUAL (i + float (ar0_without_fade * fade), _buf[i], 1e-16); } - /* Then just ar1 for a while */ + /* Then just _ar[1] 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 */ + /* And finally _ar[1]'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; -- cgit v1.2.3