ardour
audio_region_read_test.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Paul Davis
3 
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.
8 
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.
13 
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.
17 */
18 
19 #include "ardour/playlist.h"
20 #include "ardour/region.h"
21 #include "ardour/audioregion.h"
22 #include "audio_region_read_test.h"
23 
25 
26 using namespace std;
27 using namespace ARDOUR;
28 
30 void
32 {
33  int const N = 1024;
34 
35  Sample buf[N];
36  Sample mbuf[N];
37  float gbuf[N];
38 
39  int const P = 100;
40 
41  /* Simple read: 256 frames from start of region, no fades */
42 
43  _ar[0]->set_position (P);
44  _ar[0]->set_length (1024);
45 
46  _ar[0]->read_from_sources (_ar[0]->_sources, _ar[0]->_length, buf, P, 256, 0);
47  check_staircase (buf, 0, 256);
48 
49  for (int i = 0; i < N; ++i) {
50  buf[i] = 0;
51  }
52 
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);
56 
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);
60 
61  for (int i = 0; i < N; ++i) {
62  buf[i] = 0;
63  }
64 
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);
69  }
70  for (int i = 64; i < P; ++i) {
71  CPPUNIT_ASSERT_EQUAL (i, int (buf[i]));
72  }
73 
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)
76  */
77 
78  for (int i = 0; i < N; ++i) {
79  buf[i] = 0;
80  }
81 
82  _ar[0]->read_at (buf, mbuf, gbuf, P + 128, 256, 0);
83  check_staircase (buf, 128, 256);
84 }
85 
86 void
88 {
89  for (int i = 0; i < N; ++i) {
90  int const j = i + offset;
91  CPPUNIT_ASSERT_EQUAL (j, int (b[i]));
92  }
93 }
CPPUNIT_TEST_SUITE_REGISTRATION(AudioRegionReadTest)
static int N
Definition: signals_test.cc:27
Definition: Beats.hpp:239
void check_staircase(ARDOUR::Sample *, int, int)
float Sample
Definition: types.h:54
Definition: amp.h:29