1 #include "ardour/playlist.h"
2 #include "ardour/region.h"
3 #include "ardour/audioplaylist.h"
4 #include "ardour/audioregion.h"
5 #include "ardour/session.h"
6 #include "playlist_read_test.h"
7 #include "test_globals.h"
9 CPPUNIT_TEST_SUITE_REGISTRATION (PlaylistReadTest);
12 using namespace ARDOUR;
15 PlaylistReadTest::setUp ()
17 TestNeedingPlaylistAndRegions::setUp ();
20 _buf = new Sample[_N];
21 _mbuf = new Sample[_N];
22 _gbuf = new float[_N];
24 _session->config.set_auto_xfade (false);
26 _apl = boost::dynamic_pointer_cast<AudioPlaylist> (_playlist);
28 for (int i = 0; i < _N; ++i) {
34 PlaylistReadTest::tearDown ()
42 TestNeedingPlaylistAndRegions::tearDown ();
46 PlaylistReadTest::singleReadTest ()
48 /* Single-region read with fades */
50 boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_region[0]);
51 ar0->set_name ("ar0");
52 _apl->add_region (ar0, 0);
53 ar0->set_default_fade_in ();
54 ar0->set_default_fade_out ();
55 CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_in->back()->when);
56 CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_out->back()->when);
57 ar0->set_length (1024);
58 _apl->read (_buf, _mbuf, _gbuf, 0, 256, 0);
60 for (int i = 0; i < 64; ++i) {
61 /* Note: this specific float casting is necessary so that the rounding
62 is done here the same as it is done in AudioPlaylist.
64 CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / 63.0)), _buf[i], 1e-16);
67 for (int i = 64; i < 256; ++i) {
68 CPPUNIT_ASSERT_EQUAL (i, int (_buf[i]));
73 PlaylistReadTest::overlappingReadTest ()
75 /* Overlapping read; ar0 and ar1 are both 1024 frames long, ar0 starts at 0,
76 ar1 starts at 128. We test a read from 0 to 256, which should consist
77 of the start of ar0, with its fade in, followed by ar1's fade in (mixed with ar0)
81 boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_region[0]);
82 ar0->set_name ("ar0");
83 _apl->add_region (ar0, 0);
84 ar0->set_default_fade_in ();
85 ar0->set_default_fade_out ();
86 CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_in->back()->when);
87 CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_out->back()->when);
88 ar0->set_length (1024);
90 boost::shared_ptr<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_region[1]);
91 ar1->set_name ("ar1");
92 _apl->add_region (ar1, 128);
93 ar1->set_default_fade_in ();
94 ar1->set_default_fade_out ();
96 CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_in->back()->when);
97 CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_out->back()->when);
99 ar1->set_length (1024);
100 _apl->read (_buf, _mbuf, _gbuf, 0, 256, 0);
103 for (int i = 0; i < 64; ++i) {
104 /* Note: this specific float casting is necessary so that the rounding
105 is done here the same as it is done in AudioPlaylist.
107 CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * float (i / 63.0)), _buf[i], 1e-16);
111 for (int i = 64; i < 128; ++i) {
112 CPPUNIT_ASSERT_EQUAL (i, int (_buf[i]));
116 for (int i = 0; i < 64; ++i) {
117 /* Similar carry-on to above with float rounding */
118 CPPUNIT_ASSERT_DOUBLES_EQUAL (i + 128 + float (i * float (i / 63.0)), _buf[i + 128], 1e-4);
123 PlaylistReadTest::transparentReadTest ()
125 boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_region[0]);
126 ar0->set_name ("ar0");
127 _apl->add_region (ar0, 0);
128 ar0->set_default_fade_in ();
129 ar0->set_default_fade_out ();
130 CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_in->back()->when);
131 CPPUNIT_ASSERT_EQUAL (double (64), ar0->_fade_out->back()->when);
132 ar0->set_length (1024);
134 boost::shared_ptr<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_region[1]);
135 ar1->set_name ("ar1");
136 _apl->add_region (ar1, 0);
137 ar1->set_default_fade_in ();
138 ar1->set_default_fade_out ();
139 CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_in->back()->when);
140 CPPUNIT_ASSERT_EQUAL (double (64), ar1->_fade_out->back()->when);
141 ar1->set_length (1024);
142 ar1->set_opaque (false);
144 _apl->read (_buf, _mbuf, _gbuf, 0, 1024, 0);
146 /* ar0 and ar1 fade-ins, mixed */
147 for (int i = 0; i < 64; ++i) {
148 float const fade = i / 63.0;
149 CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * fade) * 2, _buf[i], 1e-16);
152 /* ar0 and ar1 bodies, mixed */
153 for (int i = 64; i < (1024 - 64); ++i) {
154 CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * 2), _buf[i], 1e-16);
157 /* ar0 and ar1 fade-outs, mixed */
158 for (int i = (1024 - 64); i < 1024; ++i) {
159 float const fade = (1023 - i) / 63.0;
160 CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * fade) * 2, _buf[i], 1e-16);
165 PlaylistReadTest::check_staircase (Sample* b, int offset, int N)
167 for (int i = 0; i < N; ++i) {
168 int const j = i + offset;
169 CPPUNIT_ASSERT_EQUAL (j, int (b[i]));