Clean up libardour tests a bit.

git-svn-id: svn://localhost/ardour2/branches/3.0@12641 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington
2012-06-09 23:07:27 +00:00
parent a715e566d0
commit 1dc8d99d78
20 changed files with 503 additions and 294 deletions

View File

@@ -34,7 +34,7 @@
#include "ardour/region.h"
class XMLNode;
class AudioRegionTest;
class AudioRegionReadTest;
class PlaylistReadTest;
namespace ARDOUR {
@@ -194,7 +194,7 @@ class AudioRegion : public Region
AudioRegion (SourceList &);
private:
friend class ::AudioRegionTest;
friend class ::AudioRegionReadTest;
friend class ::PlaylistReadTest;
PBD::Property<bool> _envelope_active;

View File

@@ -124,7 +124,7 @@ ardour_config_search_path ()
search_path = sp;
have_path = true;
std::cerr << "CONFIG PATH: " << search_path.to_string() << std::endl;
info << "CONFIG PATH: " << search_path.to_string() << endmsg;
}
return search_path;
@@ -153,7 +153,7 @@ ardour_data_search_path ()
search_path = sp;
have_path = true;
std::cerr << "DATA PATH: " << search_path.to_string() << std::endl;
info << "DATA PATH: " << search_path.to_string() << endmsg;
}
return search_path;

View File

@@ -0,0 +1,94 @@
/*
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/audioregion.h"
#include "audio_region_read_test.h"
#include "test_globals.h"
CPPUNIT_TEST_SUITE_REGISTRATION (AudioRegionReadTest);
using namespace std;
using namespace ARDOUR;
/** Check some basic reads */
void
AudioRegionReadTest::readTest ()
{
int const N = 1024;
Sample buf[N];
Sample mbuf[N];
float gbuf[N];
int const P = 100;
/* Simple read: 256 frames from start of region, no fades */
_ar[0]->set_position (P);
_ar[0]->set_length (1024);
_ar[0]->read_from_sources (_ar[0]->_sources, _ar[0]->_length, buf, P, 256, 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[0]->read_from_sources (_ar[0]->_sources, _ar[0]->_length, buf, P + 128, 256, 0);
check_staircase (buf, 128, 256);
/* Simple read with a fade-in: 256 frames from start of region, with fades */
_ar[0]->set_default_fade_in ();
CPPUNIT_ASSERT_EQUAL (double (64), _ar[0]->_fade_in->back()->when);
for (int i = 0; i < N; ++i) {
buf[i] = 0;
}
_ar[0]->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[0]->read_at (buf, mbuf, gbuf, P + 128, 256, 0);
check_staircase (buf, 128, 256);
}
void
AudioRegionReadTest::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]));
}
}

View File

@@ -0,0 +1,33 @@
/*
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/types.h"
#include "audio_region_test.h"
class AudioRegionReadTest : public AudioRegionTest
{
CPPUNIT_TEST_SUITE (AudioRegionReadTest);
CPPUNIT_TEST (readTest);
CPPUNIT_TEST_SUITE_END ();
public:
void readTest ();
private:
void check_staircase (ARDOUR::Sample *, int, int);
};

View File

@@ -1,76 +1,85 @@
#include "ardour/playlist.h"
/*
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 "pbd/filesystem.h"
#include "pbd/compose.h"
#include "ardour/playlist_factory.h"
#include "ardour/source_factory.h"
#include "ardour/region.h"
#include "ardour/region_factory.h"
#include "ardour/sndfilesource.h"
#include "ardour/audioregion.h"
#include "ardour/audioplaylist.h"
#include "audio_region_test.h"
#include "test_globals.h"
CPPUNIT_TEST_SUITE_REGISTRATION (AudioRegionTest);
using namespace std;
using namespace PBD;
using namespace ARDOUR;
void
AudioRegionTest::readTest ()
AudioRegionTest::setUp ()
{
int const N = 1024;
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");
_audio_playlist = boost::dynamic_pointer_cast<AudioPlaylist> (_playlist);
_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 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 */
ar->set_position (P);
ar->set_length (1024);
ar->read_from_sources (ar->_sources, ar->_length, buf, P, 256, 0);
check_staircase (buf, 0, 256);
for (int i = 0; i < N; ++i) {
buf[i] = 0;
Sample staircase[signal_length];
for (int i = 0; i < signal_length; ++i) {
staircase[i] = i;
}
/* Offset read: 256 frames from 128 frames into the region, no fades */
ar->read_from_sources (ar->_sources, ar->_length, buf, P + 128, 256, 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]));
}
s->write (staircase, signal_length);
/* 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;
PropertyList plist;
plist.add (Properties::start, 0);
plist.add (Properties::length, 100);
for (int i = 0; i < 16; ++i) {
_r[i] = RegionFactory::create (_source, plist);
_ar[i] = boost::dynamic_pointer_cast<AudioRegion> (_r[i]);
_ar[i]->set_name (string_compose ("ar%1", i));
}
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)
AudioRegionTest::tearDown ()
{
for (int i = 0; i < N; ++i) {
int const j = i + offset;
CPPUNIT_ASSERT_EQUAL (j, int (b[i]));
_playlist.reset ();
_audio_playlist.reset ();
_source.reset ();
for (int i = 0; i < 16; ++i) {
_r[i].reset ();
_ar[i].reset ();
}
TestNeedingSession::tearDown ();
}

View File

@@ -1,15 +1,50 @@
#include "ardour/types.h"
#include "test_needing_playlist_and_regions.h"
/*
Copyright (C) 2012 Paul Davis
class AudioRegionTest : public TestNeedingPlaylistAndRegions
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 <boost/shared_ptr.hpp>
#include "test_needing_session.h"
namespace ARDOUR {
class Playlist;
class AudioPlaylist;
class Source;
class Region;
class AudioRegion;
}
/** A parent class for tests which offers some audio regions,
* each with a staircase waveform within them.
*/
class AudioRegionTest : public TestNeedingSession
{
CPPUNIT_TEST_SUITE (AudioRegionTest);
CPPUNIT_TEST (readTest);
CPPUNIT_TEST_SUITE_END ();
public:
void readTest ();
virtual void setUp ();
virtual void tearDown ();
private:
void check_staircase (ARDOUR::Sample *, int, int);
protected:
boost::shared_ptr<ARDOUR::Playlist> _playlist;
/** AudioPlaylist downcast of _playlist */
boost::shared_ptr<ARDOUR::AudioPlaylist> _audio_playlist;
boost::shared_ptr<ARDOUR::Source> _source;
/** 16 regions, of length 100, each referencing a source which is 4096
* frames of a staircase waveform.
*/
boost::shared_ptr<ARDOUR::Region> _r[16];
/** AudioRegion downcasts of _r[] */
boost::shared_ptr<ARDOUR::AudioRegion> _ar[16];
};

View File

@@ -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 "combine_regions_test.h"
#include "ardour/types.h"
#include "ardour/audioplaylist.h"
@@ -17,10 +35,8 @@ CombineRegionsTest::check_crossfade ()
ARDOUR::Sample mbuf[512];
float gbuf[512];
boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (_playlist);
/* Read from the playlist */
apl->read (buf, mbuf, gbuf, 0, 256 * 2 - 128, 0);
_audio_playlist->read (buf, mbuf, gbuf, 0, 256 * 2 - 128, 0);
/* region[0]'s fade in */
for (int i = 0; i < 64; ++i) {
@@ -34,14 +50,11 @@ CombineRegionsTest::check_crossfade ()
CPPUNIT_ASSERT_DOUBLES_EQUAL (i, buf[i], 1e-16);
}
boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_region[0]);
boost::shared_ptr<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_region[1]);
float fade_in[128];
float fade_out[128];
ar1->fade_in()->curve().get_vector (0, 128, fade_in, 128);
ar1->inverse_fade_in()->curve().get_vector (0, 128, fade_out, 128);
_ar[1]->fade_in()->curve().get_vector (0, 128, fade_in, 128);
_ar[1]->inverse_fade_in()->curve().get_vector (0, 128, fade_out, 128);
/* Crossfading region[0] to region[1] using region[1]'s fade in and inverse fade in.
region[0] also has a standard region fade out to add to the fun.
@@ -83,27 +96,22 @@ CombineRegionsTest::crossfadeTest ()
{
/* Two regions, both 256 frames in length, overlapping by 128 frames in the middle */
boost::shared_ptr<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_region[0]);
ar0->set_name ("ar0");
boost::shared_ptr<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_region[1]);
ar1->set_name ("ar1");
ar0->set_default_fade_in ();
ar0->set_default_fade_out ();
ar1->set_default_fade_out ();
_ar[0]->set_default_fade_in ();
_ar[0]->set_default_fade_out ();
_ar[1]->set_default_fade_out ();
_playlist->add_region (_region[0], 0);
_region[0]->set_length (256);
_playlist->add_region (_r[0], 0);
_r[0]->set_length (256);
_playlist->add_region (_region[1], 128);
_region[1]->set_length (256);
_playlist->add_region (_r[1], 128);
_r[1]->set_length (256);
/* Check that the right fades have been set up */
CPPUNIT_ASSERT_EQUAL (false, ar0->fade_in_is_xfade ());
CPPUNIT_ASSERT_EQUAL (false, ar0->fade_out_is_xfade ());
CPPUNIT_ASSERT_EQUAL (true, ar1->fade_in_is_xfade ());
CPPUNIT_ASSERT_EQUAL (false, ar1->fade_out_is_xfade ());
CPPUNIT_ASSERT_EQUAL (false, _ar[0]->fade_in_is_xfade ());
CPPUNIT_ASSERT_EQUAL (false, _ar[0]->fade_out_is_xfade ());
CPPUNIT_ASSERT_EQUAL (true, _ar[1]->fade_in_is_xfade ());
CPPUNIT_ASSERT_EQUAL (false, _ar[1]->fade_out_is_xfade ());
/* Check that the read comes back correctly */
@@ -112,8 +120,8 @@ CombineRegionsTest::crossfadeTest ()
/* Combine the two regions */
RegionList rl;
rl.push_back (_region[0]);
rl.push_back (_region[1]);
rl.push_back (_r[0]);
rl.push_back (_r[1]);
_playlist->combine (rl);
/* ...so we just have the one region... */

View File

@@ -1,6 +1,24 @@
#include "test_needing_playlist_and_regions.h"
/*
Copyright (C) 2012 Paul Davis
class CombineRegionsTest : public TestNeedingPlaylistAndRegions
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 "audio_region_test.h"
class CombineRegionsTest : public AudioRegionTest
{
CPPUNIT_TEST_SUITE (CombineRegionsTest);
CPPUNIT_TEST (crossfadeTest);

View File

@@ -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 "control_surfaces_test.h"
#include "ardour/control_protocol_manager.h"
#include "ardour/session.h"
@@ -8,7 +26,7 @@ using namespace std;
using namespace ARDOUR;
/** Instantiate and then immediately tear down all our control surfaces.
* This is to check that there are no crashes when doing this ...
* This is to check that there are no crashes when doing this.
*/
void
ControlSurfacesTest::instantiateAndTeardownTest ()

View File

@@ -1,5 +1,24 @@
/*
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 "test_needing_session.h"
/** Tests for control surfaces */
class ControlSurfacesTest : public TestNeedingSession
{
CPPUNIT_TEST_SUITE (ControlSurfacesTest);

View File

@@ -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 "playlist_layering_test.h"
@@ -10,18 +28,18 @@ using namespace ARDOUR;
void
PlaylistLayeringTest::basicsTest ()
{
_playlist->add_region (_region[0], 0);
_playlist->add_region (_region[1], 10);
_playlist->add_region (_region[2], 20);
_playlist->add_region (_r[0], 0);
_playlist->add_region (_r[1], 10);
_playlist->add_region (_r[2], 20);
CPPUNIT_ASSERT_EQUAL (layer_t (0), _region[0]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (1), _region[1]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (2), _region[2]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (0), _r[0]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (1), _r[1]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (2), _r[2]->layer ());
_region[0]->set_position (5);
_r[0]->set_position (5);
/* region move should have no effect */
CPPUNIT_ASSERT_EQUAL (layer_t (0), _region[0]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (1), _region[1]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (2), _region[2]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (0), _r[0]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (1), _r[1]->layer ());
CPPUNIT_ASSERT_EQUAL (layer_t (2), _r[2]->layer ());
}

View File

@@ -1,6 +1,24 @@
#include "test_needing_playlist_and_regions.h"
/*
Copyright (C) 2012 Paul Davis
class PlaylistLayeringTest : public TestNeedingPlaylistAndRegions
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 "audio_region_test.h"
class PlaylistLayeringTest : public AudioRegionTest
{
CPPUNIT_TEST_SUITE (PlaylistLayeringTest);
CPPUNIT_TEST (basicsTest);

View File

@@ -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<AudioPlaylist> (_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<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);
_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<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);
_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<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 ();
_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<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);
_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<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);
_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);
_apl->read (_buf, _mbuf, _gbuf, 0, 1024, 0);
_audio_playlist->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,
/* _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<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 (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<AudioRegion> ar0 = boost::dynamic_pointer_cast<AudioRegion> (_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<AudioRegion> ar1 = boost::dynamic_pointer_cast<AudioRegion> (_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;

View File

@@ -1,7 +1,25 @@
#include "ardour/types.h"
#include "test_needing_playlist_and_regions.h"
/*
Copyright (C) 2012 Paul Davis
class PlaylistReadTest : public TestNeedingPlaylistAndRegions
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/types.h"
#include "audio_region_test.h"
class PlaylistReadTest : public AudioRegionTest
{
CPPUNIT_TEST_SUITE (PlaylistReadTest);
CPPUNIT_TEST (singleReadTest);
@@ -26,7 +44,6 @@ private:
ARDOUR::Sample* _buf;
ARDOUR::Sample* _mbuf;
float* _gbuf;
boost::shared_ptr<ARDOUR::AudioPlaylist> _apl;
void check_staircase (ARDOUR::Sample *, int, int);
};

View File

@@ -1,4 +1,3 @@
#include "test_globals.h"
int const Fs = 44100;
int const sinusoid_frequency = 440;

View File

@@ -1,3 +1,2 @@
extern int const Fs;
extern int const sinusoid_frequency;

View File

@@ -1,59 +0,0 @@
#include "pbd/filesystem.h"
#include "ardour/playlist_factory.h"
#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;
using namespace ARDOUR;
void
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, 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);
plist.add (Properties::length, 100);
for (int i = 0; i < 16; ++i) {
_region[i] = RegionFactory::create (_source, plist);
}
}
void
TestNeedingPlaylistAndRegions::tearDown ()
{
_playlist.reset ();
_source.reset ();
for (int i = 0; i < 16; ++i) {
_region[i].reset ();
}
TestNeedingSession::tearDown ();
}

View File

@@ -1,20 +0,0 @@
#include <boost/shared_ptr.hpp>
#include "test_needing_session.h"
namespace ARDOUR {
class Playlist;
class Source;
class Region;
}
class TestNeedingPlaylistAndRegions : public TestNeedingSession
{
public:
virtual void setUp ();
virtual void tearDown ();
protected:
boost::shared_ptr<ARDOUR::Playlist> _playlist;
boost::shared_ptr<ARDOUR::Source> _source;
boost::shared_ptr<ARDOUR::Region> _region[16];
};

View File

@@ -61,6 +61,11 @@ TestNeedingSession::setUp ()
test_receiver.listen_to (fatal);
test_receiver.listen_to (warning);
/* We can't use VSTs here as we have a stub instead of the
required bits in gtk2_ardour.
*/
Config->set_use_lxvst (false);
AudioEngine* engine = new AudioEngine ("test", "");
init_post_engine ();

View File

@@ -423,9 +423,9 @@ def build(bld):
testobj.source = '''
test/dummy_lxvst.cc
test/test_needing_session.cc
test/test_needing_playlist_and_regions.cc
test/test_globals.cc
test/audio_region_test.cc
test/test_globals.cc
test/audio_region_read_test.cc
test/bbt_test.cc
test/tempo_test.cc
test/interpolation_test.cc