2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "ardour/playlist.h"
20 #include "ardour/region.h"
21 #include "ardour/audioregion.h"
22 #include "audio_region_read_test.h"
24 CPPUNIT_TEST_SUITE_REGISTRATION (AudioRegionReadTest);
27 using namespace ARDOUR;
29 /** Check some basic reads */
31 AudioRegionReadTest::readTest ()
41 /* Simple read: 256 frames from start of region, no fades */
43 _ar[0]->set_position (P);
44 _ar[0]->set_length (1024);
46 _ar[0]->read_from_sources (_ar[0]->_sources, _ar[0]->_length, buf, P, 256, 0);
47 check_staircase (buf, 0, 256);
49 for (int i = 0; i < N; ++i) {
53 /* Offset read: 256 frames from 128 frames into the region, no fades */
54 _ar[0]->read_from_sources (_ar[0]->_sources, _ar[0]->_length, buf, P + 128, 256, 0);
55 check_staircase (buf, 128, 256);
57 /* Simple read with a fade-in: 256 frames from start of region, with fades */
58 _ar[0]->set_default_fade_in ();
59 CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_in->back()->when);
61 for (int i = 0; i < N; ++i) {
65 _ar[0]->read_at (buf, mbuf, gbuf, P, 256, 0);
66 for (int i = 0; i < 64; ++i) {
67 /* XXX: this isn't very accurate, but close enough for now; needs investigation */
68 CPPUNIT_ASSERT_DOUBLES_EQUAL (float (i * i / 63.0), buf[i], 1e-4);
70 for (int i = 64; i < P; ++i) {
71 CPPUNIT_ASSERT_EQUAL (i, int (buf[i]));
74 /* Offset read: 256 frames from 128 frames into the region, with fades
75 (though the fade should not affect it, as it is finished before the read starts)
78 for (int i = 0; i < N; ++i) {
82 _ar[0]->read_at (buf, mbuf, gbuf, P + 128, 256, 0);
83 check_staircase (buf, 128, 256);
87 AudioRegionReadTest::check_staircase (Sample* b, int offset, int N)
89 for (int i = 0; i < N; ++i) {
90 int const j = i + offset;
91 CPPUNIT_ASSERT_EQUAL (j, int (b[i]));