Fix ramp test, add tempoAtPulseTest.

This commit is contained in:
nick_m 2016-10-13 14:14:27 +11:00
parent eae567bd9e
commit d824e696c0
2 changed files with 67 additions and 3 deletions

View File

@ -65,7 +65,7 @@ TempoTest::rampTest ()
/*
77bpm / note typeA 217bpm / note type B
77bpm 217bpm
0 frames 60 * sample rate frames
| | | | |
| *|
@ -96,14 +96,76 @@ TempoTest::rampTest ()
}
map.recompute_map (map._metrics);
CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_tempo (tB->beats_per_minute() / tB->note_type(), 300.0, 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));
/* self-check tempo at pulse @ 125 bpm. */
CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0 / 4.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0 / 4.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)), 0.00000000000000001);
/* 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 ()
{
int const sampling_rate = 48000;
TempoMap map (sampling_rate);
Meter meterA (4, 8);
Tempo tempoA (80.0, 8.0);
Tempo tempoB (160.0, 3.0);
Tempo tempoC (123.0, 4.0);
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Ramp, AudioTime);
map.add_tempo (tempoB, 20.0, 0, TempoSection::Ramp, MusicTime);
map.add_tempo (tempoC, 30.0, 0, TempoSection::Ramp, MusicTime);
map.recompute_map (map._metrics);
TempoSection* tA = 0;
TempoSection* tB = 0;
TempoSection* tC = 0;
list<MetricSection*>::iterator i;
for (i = map._metrics.begin(); i != map._metrics.end(); ++i) {
TempoSection* t;
if ((t = dynamic_cast<TempoSection*> (*i)) != 0) {
if (!tA) {
tA = t;
continue;
}
if (!tB) {
tB = t;
continue;
}
if (!tC) {
tC = t;
continue;
}
}
}
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));
/* 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_EQUAL (tB->frame(), tA->frame_at_pulse (tB->pulse(), sampling_rate));
CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_pulse (tC->pulse(), 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 (tB->pulse()), 0.00000000000000001);
CPPUNIT_ASSERT_DOUBLES_EQUAL (123.0, tB->tempo_at_pulse (tC->pulse()), 0.00000000000000001);
}

View File

@ -7,6 +7,7 @@ class TempoTest : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE (TempoTest);
CPPUNIT_TEST (recomputeMapTest);
CPPUNIT_TEST (rampTest);
CPPUNIT_TEST (tempoAtPulseTest);
CPPUNIT_TEST_SUITE_END ();
public:
@ -15,5 +16,6 @@ public:
void recomputeMapTest ();
void rampTest ();
void tempoAtPulseTest();
};