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 std::cout << std::endl;
66 // test the rate of rolloff of the LPF from 100% with load at constant 50%
67 // over the equivalent of 1 second
68 for (int i = 0; i < 1e6 / dsp_100_pc_48k_us; ++i) {
69 dsp_calc.set_start_timestamp_us(0);
70 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us / 2);
71 CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == 5333);
72 std::cout << "DSP 50% load value = " << dsp_calc.get_dsp_load() << std::endl;
75 // test that the LPF is still working after one second of values
76 // TODO need to work out what is required in terms of responsiveness etc
77 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() > 0.5f);
80 DSPLoadCalculator dsp_calc_96k;
81 dsp_calc_96k.set_max_time(96000, 512);
82 int64_t dsp_100_pc_96k_us = 5333;
85 dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us);
86 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us * 2);
87 CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == dsp_100_pc_48k_us);
88 CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0f);
89 dsp_calc_96k.set_start_timestamp_us(dsp_100_pc_96k_us);
90 dsp_calc_96k.set_stop_timestamp_us(dsp_100_pc_96k_us * 2);
91 CPPUNIT_ASSERT(dsp_calc_96k.elapsed_time_us() == dsp_100_pc_96k_us);
92 CPPUNIT_ASSERT(dsp_calc_96k.get_dsp_load() <= 1.0f);
94 // test the rate of rolloff of the LPF from 100% with load at constant 50%
95 // over the equivalent of 1 second for 48k and 96k and test for ~equality
96 for (int i = 0; i < 1e6 / dsp_100_pc_96k_us; ++i) {
97 dsp_calc_96k.set_start_timestamp_us(0);
98 dsp_calc_96k.set_stop_timestamp_us(dsp_100_pc_96k_us / 2);
100 dsp_calc.set_start_timestamp_us(0);
101 dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us / 2);
103 std::cout << "DSP 50% load value 48k = " << dsp_calc.get_dsp_load()
105 std::cout << "DSP 50% load value 96k = " << dsp_calc_96k.get_dsp_load()
107 CPPUNIT_ASSERT_DOUBLES_EQUAL(dsp_calc.get_dsp_load(),
108 dsp_calc_96k.get_dsp_load(), 0.001);