3 #include "ardour/dsp_load_calculator.h"
5 #include "dsp_load_calculator_test.h"
7 CPPUNIT_TEST_SUITE_REGISTRATION (DSPLoadCalculatorTest);
10 using namespace ARDOUR;
13 DSPLoadCalculatorTest::basicTest ()
15 DSPLoadCalculator dsp_calc;
17 dsp_calc.set_max_time(48000, 512);
18 int64_t dsp_100_pc_48k_us = 10666;
20 CPPUNIT_ASSERT(dsp_calc.get_max_time_us() == dsp_100_pc_48k_us);
22 // test equivalent of 10% load
23 dsp_calc.set_start_timestamp_us(0);
24 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us/10);
25 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 0.1f);
27 // test equivalent of 50% load and check that the load jumps to 50 percent
28 dsp_calc.set_start_timestamp_us(0);
29 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us/2);
30 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 0.5f);
32 // test equivalent of 100% load
33 dsp_calc.set_start_timestamp_us(0);
34 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us);
35 CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == dsp_100_pc_48k_us);
36 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0f);
38 // test setting the equivalent of 100% twice doesn't lead to a dsp value > 1.0
39 dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us);
40 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us * 2);
41 CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == dsp_100_pc_48k_us);
42 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0f);
44 // test setting the equivalent of 200% clamps the value to 1.0
45 dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us);
46 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us * 3);
47 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() == 1.0f);
49 // test setting the an stop timestamp before the start timestamp is ignored
50 // and the previous dsp value is returned
51 dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us * 2);
52 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us);
53 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() == 1.0f);
55 float dsp_load = dsp_calc.get_dsp_load();
57 // test setting the equivalent of beyond the max_timer_error_us is ignored and
58 // the previous dsp value is returned
59 dsp_calc.set_start_timestamp_us (0);
60 dsp_calc.set_stop_timestamp_us (dsp_100_pc_48k_us*10);
61 CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() > dsp_calc.max_timer_error_us());
62 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() == dsp_load);
64 // test the rate of rolloff of the LPF from 100% with load at constant 50%
65 // over the equivalent of 1 second
66 for (int i = 0; i < 1e6 / dsp_100_pc_48k_us; ++i) {
67 dsp_calc.set_start_timestamp_us(0);
68 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us / 2);
69 CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == 5333);
70 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0);
71 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() >= 0.5);
73 std::cout << "DSP 50% load value = " << dsp_calc.get_dsp_load() << std::endl;
77 // test that the LPF is still working after one second of values
78 // TODO need to work out what is required in terms of responsiveness etc
79 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() > 0.5f);
82 DSPLoadCalculator dsp_calc_96k;
83 dsp_calc_96k.set_max_time(96000, 512);
84 int64_t dsp_100_pc_96k_us = 5333;
87 dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us);
88 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us * 2);
89 CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == dsp_100_pc_48k_us);
90 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0f);
91 dsp_calc_96k.set_start_timestamp_us(dsp_100_pc_96k_us);
92 dsp_calc_96k.set_stop_timestamp_us(dsp_100_pc_96k_us * 2);
93 CPPUNIT_ASSERT(dsp_calc_96k.elapsed_time_us() == dsp_100_pc_96k_us);
94 CPPUNIT_ASSERT(dsp_calc_96k.get_dsp_load() <= 1.0f);
96 // test the rate of rolloff of the LPF from 100% with load at constant 50%
97 // over the equivalent of 1 second for 48k and 96k and test for ~equality
98 for (int i = 0; i < 1e6 / dsp_100_pc_96k_us; ++i) {
99 dsp_calc_96k.set_start_timestamp_us(0);
100 dsp_calc_96k.set_stop_timestamp_us(dsp_100_pc_96k_us / 2);
102 dsp_calc.set_start_timestamp_us(0);
103 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us / 2);
105 std::cout << "DSP 50% load value 48k = " << dsp_calc.get_dsp_load()
107 std::cout << "DSP 50% load value 96k = " << dsp_calc_96k.get_dsp_load()
110 CPPUNIT_ASSERT_DOUBLES_EQUAL(dsp_calc.get_dsp_load(),
111 dsp_calc_96k.get_dsp_load(), 0.001);