diff options
Diffstat (limited to 'libs/ardour/test')
-rw-r--r-- | libs/ardour/test/audio_region_test.cc | 85 | ||||
-rw-r--r-- | libs/ardour/test/audio_region_test.h | 15 | ||||
-rw-r--r-- | libs/ardour/test/playlist_read_test.cc | 171 | ||||
-rw-r--r-- | libs/ardour/test/playlist_read_test.h | 27 | ||||
-rw-r--r-- | libs/ardour/test/tempo_test.cc | 9 | ||||
-rw-r--r-- | libs/ardour/test/test_globals.cc | 4 | ||||
-rw-r--r-- | libs/ardour/test/test_globals.h | 3 | ||||
-rw-r--r-- | libs/ardour/test/test_needing_playlist_and_regions.cc | 20 |
8 files changed, 324 insertions, 10 deletions
diff --git a/libs/ardour/test/audio_region_test.cc b/libs/ardour/test/audio_region_test.cc new file mode 100644 index 0000000000..72e886b4e1 --- /dev/null +++ b/libs/ardour/test/audio_region_test.cc @@ -0,0 +1,85 @@ +#include "ardour/playlist.h" +#include "ardour/region.h" +#include "ardour/audioregion.h" +#include "audio_region_test.h" +#include "test_globals.h" + +CPPUNIT_TEST_SUITE_REGISTRATION (AudioRegionTest); + +using namespace std; +using namespace ARDOUR; + +void +AudioRegionTest::readTest () +{ + int const N = 1024; + + Sample buf[N]; + Sample mbuf[N]; + float gbuf[N]; + + int const P = 100; + boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (_region[0]); + + /* Simple read: 256 frames from start of region, no fades */ + + /* gbuf should be ignored; set it to 0 to ensure that it is */ + for (int i = 0; i < N; ++i) { + gbuf[i] = 0; + } + + ar->set_position (P); + ar->set_length (1024); + + for (int i = 0; i < N; ++i) { + buf[i] = 0; + } + + ar->_read_at (ar->_sources, ar->_length, buf, mbuf, gbuf, P, 256, 0, AudioRegion::ReadOps (0)); + check_staircase (buf, 0, 256); + + for (int i = 0; i < N; ++i) { + buf[i] = 0; + } + + /* Offset read: 256 frames from 128 frames into the region, no fades */ + ar->_read_at (ar->_sources, ar->_length, buf, mbuf, gbuf, P + 128, 256, 0, AudioRegion::ReadOps (0)); + check_staircase (buf, 128, 256); + + /* Simple read with a fade-in: 256 frames from start of region, with fades */ + ar->set_default_fade_in (); + CPPUNIT_ASSERT_EQUAL (double (64), ar->_fade_in->back()->when); + + for (int i = 0; i < N; ++i) { + buf[i] = 0; + } + + ar->read_at (buf, mbuf, gbuf, P, 256, 0); + for (int i = 0; i < 64; ++i) { + /* XXX: this isn't very accurate, but close enough for now; needs investigation */ + CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * i / 63.0), buf[i], 1e-4); + } + for (int i = 64; i < P; ++i) { + CPPUNIT_ASSERT_EQUAL (i, int (buf[i])); + } + + /* Offset read: 256 frames from 128 frames into the region, with fades + (though the fade should not affect it, as it is finished before the read starts) + */ + + for (int i = 0; i < N; ++i) { + buf[i] = 0; + } + + ar->read_at (buf, mbuf, gbuf, P + 128, 256, 0); + check_staircase (buf, 128, 256); +} + +void +AudioRegionTest::check_staircase (Sample* b, int offset, int N) +{ + for (int i = 0; i < N; ++i) { + int const j = i + offset; + CPPUNIT_ASSERT_EQUAL (j, int (b[i])); + } +} diff --git a/libs/ardour/test/audio_region_test.h b/libs/ardour/test/audio_region_test.h new file mode 100644 index 0000000000..e746b19ef3 --- /dev/null +++ b/libs/ardour/test/audio_region_test.h @@ -0,0 +1,15 @@ +#include "ardour/types.h" +#include "test_needing_playlist_and_regions.h" + +class AudioRegionTest : public TestNeedingPlaylistAndRegions +{ + CPPUNIT_TEST_SUITE (AudioRegionTest); + CPPUNIT_TEST (readTest); + CPPUNIT_TEST_SUITE_END (); + +public: + void readTest (); + +private: + void check_staircase (ARDOUR::Sample *, int, int); +}; diff --git a/libs/ardour/test/playlist_read_test.cc b/libs/ardour/test/playlist_read_test.cc new file mode 100644 index 0000000000..55c6abe4ad --- /dev/null +++ b/libs/ardour/test/playlist_read_test.cc @@ -0,0 +1,171 @@ +#include "ardour/playlist.h" +#include "ardour/region.h" +#include "ardour/audioplaylist.h" +#include "ardour/audioregion.h" +#include "ardour/session.h" +#include "playlist_read_test.h" +#include "test_globals.h" + +CPPUNIT_TEST_SUITE_REGISTRATION (PlaylistReadTest); + +using namespace std; +using namespace ARDOUR; + +void +PlaylistReadTest::setUp () +{ + TestNeedingPlaylistAndRegions::setUp (); + + _N = 1024; + _buf = new Sample[_N]; + _mbuf = new Sample[_N]; + _gbuf = new float[_N]; + + _session->config.set_auto_xfade (false); + + _apl = boost::dynamic_pointer_cast<AudioPlaylist> (_playlist); + + for (int i = 0; i < _N; ++i) { + _buf[i] = 0; + } +} + +void +PlaylistReadTest::tearDown () +{ + delete[] _buf; + delete[] _mbuf; + delete[] _gbuf; + + _apl.reset (); + + TestNeedingPlaylistAndRegions::tearDown (); +} + +void +PlaylistReadTest::singleReadTest () +{ + /* Single-region read with fades */ + + boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_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); + + 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. + */ + CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / 63.0)), _buf[i], 1e-16); + } + + for (int i = 64; i < 256; ++i) { + CPPUNIT_ASSERT_EQUAL (i, int (_buf[i])); + } +} + +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) + and some more of ar1. + */ + + boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_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); + + boost::shared_ptr<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_region[1]); + ar1->set_name ("ar1"); + _apl->add_region (ar1, 128); + 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); + _apl->read (_buf, _mbuf, _gbuf, 0, 256, 0); + + /* 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. + */ + CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / 63.0)), _buf[i], 1e-16); + } + + /* bit of ar0 */ + for (int i = 64; i < 128; ++i) { + CPPUNIT_ASSERT_EQUAL (i, int (_buf[i])); + } + + /* ar1's fade in */ + 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); + } +} + +void +PlaylistReadTest::transparentReadTest () +{ + boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_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); + + boost::shared_ptr<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_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, mixed */ + 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); + } + + /* ar0 and ar1 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 */ + 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); + } +} + +void +PlaylistReadTest::check_staircase (Sample* b, int offset, int N) +{ + for (int i = 0; i < N; ++i) { + int const j = i + offset; + CPPUNIT_ASSERT_EQUAL (j, int (b[i])); + } +} diff --git a/libs/ardour/test/playlist_read_test.h b/libs/ardour/test/playlist_read_test.h new file mode 100644 index 0000000000..9328d926e0 --- /dev/null +++ b/libs/ardour/test/playlist_read_test.h @@ -0,0 +1,27 @@ +#include "ardour/types.h" +#include "test_needing_playlist_and_regions.h" + +class PlaylistReadTest : public TestNeedingPlaylistAndRegions +{ + CPPUNIT_TEST_SUITE (PlaylistReadTest); + CPPUNIT_TEST (singleReadTest); + CPPUNIT_TEST (transparentReadTest); + CPPUNIT_TEST_SUITE_END (); + +public: + void setUp (); + void tearDown (); + + void singleReadTest (); + void overlappingReadTest (); + void transparentReadTest (); + +private: + int _N; + ARDOUR::Sample* _buf; + ARDOUR::Sample* _mbuf; + float* _gbuf; + boost::shared_ptr<ARDOUR::AudioPlaylist> _apl; + + void check_staircase (ARDOUR::Sample *, int, int); +}; diff --git a/libs/ardour/test/tempo_test.cc b/libs/ardour/test/tempo_test.cc index 845116470e..fa9ad0a520 100644 --- a/libs/ardour/test/tempo_test.cc +++ b/libs/ardour/test/tempo_test.cc @@ -41,15 +41,6 @@ TempoTest::recomputeMapTest () Meter meterB (3, 4); map.add_meter (meterB, BBT_Time (4, 1, 0)); - cout << "\n\n\n"; - for (list<MetricSection*>::iterator i = map.metrics.begin(); i != map.metrics.end(); ++i) { - if (dynamic_cast<TempoSection*> (*i)) { - cout << "\tTempo MS @ " << (*i)->start() << " " << (*i)->frame() << "\n"; - } else { - cout << "\tMeter MS @ " << (*i)->start() << " " << (*i)->frame() << "\n"; - } - } - list<MetricSection*>::iterator i = map.metrics.begin(); CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ()); diff --git a/libs/ardour/test/test_globals.cc b/libs/ardour/test/test_globals.cc new file mode 100644 index 0000000000..ff00fbc2e5 --- /dev/null +++ b/libs/ardour/test/test_globals.cc @@ -0,0 +1,4 @@ +#include "test_globals.h" + +int const Fs = 44100; +int const sinusoid_frequency = 440; diff --git a/libs/ardour/test/test_globals.h b/libs/ardour/test/test_globals.h new file mode 100644 index 0000000000..8595e0c9b1 --- /dev/null +++ b/libs/ardour/test/test_globals.h @@ -0,0 +1,3 @@ + +extern int const Fs; +extern int const sinusoid_frequency; diff --git a/libs/ardour/test/test_needing_playlist_and_regions.cc b/libs/ardour/test/test_needing_playlist_and_regions.cc index fea08cc4d9..4e0e42c67b 100644 --- a/libs/ardour/test/test_needing_playlist_and_regions.cc +++ b/libs/ardour/test/test_needing_playlist_and_regions.cc @@ -3,7 +3,9 @@ #include "ardour/source_factory.h" #include "ardour/region.h" #include "ardour/region_factory.h" +#include "ardour/sndfilesource.h" #include "test_needing_playlist_and_regions.h" +#include "test_globals.h" using namespace std; using namespace PBD; @@ -14,9 +16,25 @@ TestNeedingPlaylistAndRegions::setUp () { TestNeedingSession::setUp (); + /* This is important, otherwise createWritable will mark the source immutable (hence unwritable) */ + unlink ("libs/ardour/test/test.wav"); string const test_wav_path = "libs/ardour/test/test.wav"; _playlist = PlaylistFactory::create (DataType::AUDIO, *_session, "test"); - _source = SourceFactory::createWritable (DataType::AUDIO, *_session, test_wav_path, "", false, 44100); + _source = SourceFactory::createWritable (DataType::AUDIO, *_session, test_wav_path, "", false, Fs); + + /* Write a staircase to the source */ + + boost::shared_ptr<SndFileSource> s = boost::dynamic_pointer_cast<SndFileSource> (_source); + assert (s); + + int const signal_length = 4096; + + Sample staircase[signal_length]; + for (int i = 0; i < signal_length; ++i) { + staircase[i] = i; + } + + s->write (staircase, signal_length); PropertyList plist; plist.add (Properties::start, 0); |