1 #include "framewalk_to_beats_test.h"
2 #include "ardour/tempo.h"
3 #include "timecode/bbt_time.h"
5 CPPUNIT_TEST_SUITE_REGISTRATION (FramewalkToBeatsTest);
8 using namespace ARDOUR;
9 using namespace Timecode;
12 FramewalkToBeatsTest::singleTempoTest ()
14 int const sampling_rate = 48000;
17 double const frames_per_beat = (60 / double (bpm)) * double (sampling_rate);
19 TempoMap map (sampling_rate);
23 map.add_meter (meter, BBT_Time (1, 1, 0));
24 map.add_tempo (tempo, BBT_Time (1, 1, 0));
26 /* Walk 1 beats-worth of frames from beat 3 */
27 double r = map.framewalk_to_beats (frames_per_beat * 2, frames_per_beat * 1);
28 CPPUNIT_ASSERT_EQUAL (1.0, r);
30 /* Walk 6 beats-worth of frames from beat 4 */
31 r = map.framewalk_to_beats (frames_per_beat * 3, frames_per_beat * 6);
32 CPPUNIT_ASSERT_EQUAL (6.0, r);
34 /* Walk 1.5 beats-worth of frames from beat 3 */
35 r = map.framewalk_to_beats (frames_per_beat * 2, frames_per_beat * 1.5);
36 CPPUNIT_ASSERT_EQUAL (1.5, r);
38 /* Walk 1.5 beats-worth of frames from beat 2.5 */
39 r = map.framewalk_to_beats (frames_per_beat * 2.5, frames_per_beat * 1.5);
40 CPPUNIT_ASSERT_EQUAL (1.5, r);
44 FramewalkToBeatsTest::doubleTempoTest ()
46 int const sampling_rate = 48000;
48 TempoMap map (sampling_rate);
50 map.add_meter (meter, BBT_Time (1, 1, 0));
53 120bpm at bar 1, 240bpm at bar 4
55 120bpm = 24e3 samples per beat
56 240bpm = 12e3 samples per beat
65 24e3 frames per beat 12e3 frames per beat
67 1.1 1.2 1.3 1.4 2.1 2.2 2.3 2.4 3.1 3.2 3.3 3.4 4.1 4.2 4.3 4.4 5.1
68 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
73 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
75 map.add_tempo (tempoB, BBT_Time (4, 1, 0));
79 /* Walk 1 beat from 1|2 */
80 double r = map.framewalk_to_beats (24e3, 24e3);
81 CPPUNIT_ASSERT_EQUAL (1.0, r);
83 /* Walk 2 beats from 3|3 to 4|1 (over the tempo change) */
84 r = map.framewalk_to_beats (240e3, (24e3 + 24e3));
85 CPPUNIT_ASSERT_EQUAL (2.0, r);
87 /* Walk 2.5 beats from 3|3.5 to 4.2 (over the tempo change) */
88 r = map.framewalk_to_beats (264e3 - 12e3, (24e3 + 12e3 + 12e3));
89 CPPUNIT_ASSERT_EQUAL (2.5, r);
90 /* Walk 3 beats from 3|4.5 to 4|3.5 (over the tempo change) */
91 r = map.framewalk_to_beats (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 6e3));
92 CPPUNIT_ASSERT_EQUAL (3.0, r);
94 /* Walk 3.5 beats from 3|4.5 to 4.4 (over the tempo change) */
95 r = map.framewalk_to_beats (264e3 - 12e3, (24e3 + 12e3 + 12e3 + 12e3));
96 CPPUNIT_ASSERT_EQUAL (3.5, r);
100 FramewalkToBeatsTest::tripleTempoTest ()
102 int const sampling_rate = 48000;
104 TempoMap map (sampling_rate);
106 map.add_meter (meter, BBT_Time (1, 1, 0));
109 120bpm at bar 1, 240bpm at bar 2, 160bpm at bar 3
111 120bpm = 24e3 samples per beat
112 160bpm = 18e3 samples per beat
113 240bpm = 12e3 samples per beat
120 0 beats 4 beats 8 beats
121 0 frames 96e3 frames 144e3 frames
123 | 1.1 1.2 1.3 1.4 | 2.1 2.2 2.3.2.4 | 3.1 3.2 3.3 3.4 | 4.1 4.2 4.3 4.4 |
128 map.add_tempo (tempoA, BBT_Time (1, 1, 0));
130 map.add_tempo (tempoB, BBT_Time (2, 1, 0));
132 map.add_tempo (tempoC, BBT_Time (3, 1, 0));
134 /* Walk from 1|3 to 4|1 */
135 double r = map.framewalk_to_beats (2 * 24e3, (2 * 24e3) + (4 * 12e3) + (4 * 18e3));
136 CPPUNIT_ASSERT_EQUAL (10.0, r);