summaryrefslogtreecommitdiff
path: root/libs/ardour/test
diff options
context:
space:
mode:
authornick_m <mainsbridge@gmail.com>2016-10-25 04:02:58 +1100
committernick_m <mainsbridge@gmail.com>2016-10-25 04:02:58 +1100
commit20d02c4c68514e143f5ecc820cfd8bc7a8343c14 (patch)
treed4606fc64d0a57cd3e465181f1d41fd52a4577ef /libs/ardour/test
parent509d938b047320b35bffbfef73bbc5fe71ffdab0 (diff)
expand on existing tempo tests.
Diffstat (limited to 'libs/ardour/test')
-rw-r--r--libs/ardour/test/tempo_test.cc139
-rw-r--r--libs/ardour/test/tempo_test.h6
2 files changed, 114 insertions, 31 deletions
diff --git a/libs/ardour/test/tempo_test.cc b/libs/ardour/test/tempo_test.cc
index f80fab4f24..af77543b35 100644
--- a/libs/ardour/test/tempo_test.cc
+++ b/libs/ardour/test/tempo_test.cc
@@ -45,13 +45,37 @@ TempoTest::recomputeMapTest ()
list<MetricSection*>::iterator i = map._metrics.begin();
CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ());
+ /* check the tempo section for ecpected result (no map) */
+ const TempoSection& tsa (map.tempo_section_at_frame (0));
+ CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), tsa.frame_at_pulse (3.0, sampling_rate));
+ CPPUNIT_ASSERT_EQUAL (framepos_t (144e3), tsa.frame_at_pulse (1.5, sampling_rate));
+ CPPUNIT_ASSERT_EQUAL (framepos_t (96e3), tsa.frame_at_pulse (1.0, sampling_rate));
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, tsa.pulse_at_frame (288e3, sampling_rate), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, tsa.pulse_at_frame (144e3, sampling_rate), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tsa.pulse_at_frame (96e3, sampling_rate), 1e-17);
+
+ /* do the same via the map */
+ CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), map.frame_at_pulse (3.0));
+ CPPUNIT_ASSERT_EQUAL (framepos_t (144e3), map.frame_at_pulse (1.5));
+ CPPUNIT_ASSERT_EQUAL (framepos_t (96e3), map.frame_at_pulse (1.0));
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_frame (288e3), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, map.pulse_at_frame (144e3), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, map.pulse_at_frame (96e3), 1e-17);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_beat (24.0).beats_per_minute(), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_beat (12.0).beats_per_minute(), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_beat (6.0).beats_per_minute(), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_beat (0.0).beats_per_minute(), 1e-17);
+
i = map._metrics.end();
--i;
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), (*i)->frame ());
}
void
-TempoTest::rampTest ()
+TempoTest::rampTest48 ()
{
int const sampling_rate = 48000;
@@ -82,32 +106,86 @@ TempoTest::rampTest ()
20 seconds 125.0 bpm / note_type
*/
- TempoSection* tA = 0;
- TempoSection* tB;
- list<MetricSection*>::iterator i;
-
- for (i = map._metrics.begin(); i != map._metrics.end(); ++i) {
- if ((tB = dynamic_cast<TempoSection*> (*i)) != 0) {
- if (tA) {
- break;
- }
- tA = tB;
- }
- }
- map.recompute_map (map._metrics);
+ TempoSection& tA = map.first_tempo();
+ const TempoSection& tB = map.tempo_section_at_frame ((framepos_t) 60 * sampling_rate);
- CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_tempo (tB->beats_per_minute(), 300.0, sampling_rate));
- CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (tB->pulse(), sampling_rate));
+ CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_tempo (tB.beats_per_minute(), 300.0, sampling_rate));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (217.0, tA.tempo_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-17);
+ CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_pulse (tB.pulse(), sampling_rate));
+ /* note 1e-14 here. (expm1) */
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-14);
/* self-check tempo at pulse @ 125 bpm. */
- CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0, 0, sampling_rate)), 0.00000000000000001);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA.tempo_at_pulse (tA.pulse_at_tempo (125.0, 0, sampling_rate)), 1e-17);
+
+ /* check that tB's pulse is what tA thinks it should be */
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 0, sampling_rate), 1e-17);
+
+ /* check that the tempo at the halfway mark (in pulses) is half the tempo delta.*/
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (147.0, tA.tempo_at_pulse (tB.pulse() / 2.0), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL ((tB.pulse() - tA.pulse()) / 2.0, tA.pulse_at_tempo (147.0, 0, sampling_rate), 1e-17);
/* self-check frame at pulse 20 seconds in. */
const framepos_t target = 20 * sampling_rate;
- const framepos_t result = tA->frame_at_pulse (tA->pulse_at_frame (target, sampling_rate), sampling_rate);
+ const framepos_t result = tA.frame_at_pulse (tA.pulse_at_frame (target, sampling_rate), sampling_rate);
CPPUNIT_ASSERT_EQUAL (target, result);
}
+void
+TempoTest::rampTest44 ()
+{
+ int const sampling_rate = 44100;
+
+ TempoMap map (sampling_rate);
+ Meter meterA (4, 4);
+ Tempo tempoA (77.0, 4.0);
+ Tempo tempoB (217.0, 4.0);
+ map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Ramp, AudioTime);
+ map.add_tempo (tempoB, 0.0, (framepos_t) 60 * sampling_rate, TempoSection::Ramp, AudioTime);
+ map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
+
+ /*
+
+ 77bpm 217bpm
+ 0 frames 60 * sample rate frames
+ | | | | |
+ | *|
+ | * |
+ | * |
+ | * |
+ | * |
+ | * |
+ | * |
+ | * | |
+ | * | |
+ | * | | |
+ -------------------|-----------|-----------------------
+ 20 seconds 125.0 bpm / note_type
+ */
+
+ TempoSection& tA = map.first_tempo();
+ const TempoSection& tB = map.tempo_section_at_frame ((framepos_t) 60 * sampling_rate);
+
+ CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_tempo (tB.beats_per_minute(), 300.0, sampling_rate));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (217.0, tA.tempo_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-17);
+ CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_pulse (tB.pulse(), sampling_rate));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-14);
+
+ /* self-check tempo at pulse @ 125 bpm. */
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA.tempo_at_pulse (tA.pulse_at_tempo (125.0, 0, sampling_rate)), 1e-17);
+
+ /* check that tB's pulse is what tA thinks it should be */
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 0, sampling_rate), 1e-17);
+
+ /* check that the tempo at the halfway mark (in pulses) is half the tempo delta.*/
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (147.0, tA.tempo_at_pulse (tB.pulse() / 2.0), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL ((tB.pulse() - tA.pulse()) / 2.0, tA.pulse_at_tempo (147.0, 0, sampling_rate), 1e-17);
+
+ /* self-check frame at pulse 20 seconds in. */
+ const framepos_t target = 20 * sampling_rate;
+ const framepos_t result = tA.frame_at_pulse (tA.pulse_at_frame (target, sampling_rate), sampling_rate);
+ CPPUNIT_ASSERT_EQUAL (target, result);
+}
void
TempoTest::tempoAtPulseTest ()
@@ -150,20 +228,23 @@ TempoTest::tempoAtPulseTest ()
}
}
- CPPUNIT_ASSERT_EQUAL (tB->beats_per_minute(), tA->tempo_at_pulse (20.0));
- CPPUNIT_ASSERT_EQUAL (tC->beats_per_minute(), tB->tempo_at_pulse (30.0));
+ CPPUNIT_ASSERT_EQUAL (160.0, tA->tempo_at_pulse (20.0));
+ CPPUNIT_ASSERT_EQUAL (123.0, tB->tempo_at_pulse (30.0));
/* check that the tempo at the halfway mark (in pulses) is half the tempo delta.*/
- CPPUNIT_ASSERT_EQUAL (((tA->beats_per_minute() - tB->beats_per_minute()) / 2.0) + tB->beats_per_minute(), tA->tempo_at_pulse (10.0));
- CPPUNIT_ASSERT_EQUAL (((tA->pulse() - tB->pulse()) / 2.0) + tB->pulse(), tA->pulse_at_tempo (120, 0, sampling_rate));
- CPPUNIT_ASSERT_EQUAL (((tB->beats_per_minute() - tC->beats_per_minute()) / 2.0) + tC->beats_per_minute(), tB->tempo_at_pulse (25.0));
- CPPUNIT_ASSERT_EQUAL (((tB->pulse() - tC->pulse()) / 2.0) + tC->pulse(), tB->pulse_at_tempo (141.5, 0, sampling_rate));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (((80.0 - 160.0) / 2.0) + 160.0, tA->tempo_at_pulse (10.0), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (20.0 / 2.0, tA->pulse_at_tempo (120, 0, sampling_rate), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (((160.0 - 123.0) / 2.0) + 123.0, tB->tempo_at_pulse (25.0), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (((20.0 - 30.0) / 2.0) + 30.0, tB->pulse_at_tempo (141.5, 0, sampling_rate), 1e-17);
+
+ CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (20.0, sampling_rate));
+ CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_pulse (30.0, sampling_rate));
- CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (tB->pulse(), sampling_rate));
- CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_pulse (tC->pulse(), sampling_rate));
+ CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_tempo (160.0, 20.0, sampling_rate));
+ CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_tempo (123.0, 30.0, sampling_rate));
/* self-check tempo at pulse @ 125 bpm. */
- CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0, 0, sampling_rate)), 0.00000000000000001);
- CPPUNIT_ASSERT_DOUBLES_EQUAL (160.0, tA->tempo_at_pulse (20.0), 0.00000000000000001);
- CPPUNIT_ASSERT_DOUBLES_EQUAL (123.0, tB->tempo_at_pulse (30.0), 0.00000000000000001);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0, 0, sampling_rate)), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (160.0, tA->tempo_at_pulse (20.0), 1e-17);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (123.0, tB->tempo_at_pulse (30.0), 1e-17);
}
diff --git a/libs/ardour/test/tempo_test.h b/libs/ardour/test/tempo_test.h
index 7df6a089e8..72e9e4748f 100644
--- a/libs/ardour/test/tempo_test.h
+++ b/libs/ardour/test/tempo_test.h
@@ -6,7 +6,8 @@ class TempoTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE (TempoTest);
CPPUNIT_TEST (recomputeMapTest);
- CPPUNIT_TEST (rampTest);
+ CPPUNIT_TEST (rampTest48);
+ CPPUNIT_TEST (rampTest44);
CPPUNIT_TEST (tempoAtPulseTest);
CPPUNIT_TEST_SUITE_END ();
@@ -15,7 +16,8 @@ public:
void tearDown () {}
void recomputeMapTest ();
- void rampTest ();
+ void rampTest48 ();
+ void rampTest44 ();
void tempoAtPulseTest();
};