summaryrefslogtreecommitdiff
path: root/libs/ardour/test
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2015-09-14 16:56:22 +1000
committerTim Mayberry <mojofunk@gmail.com>2015-09-16 11:22:17 +1000
commit449b57d583b63507241939540da630511b8e335b (patch)
tree9b801255b6e80c9bb1c0ef256e56bf09d94fc817 /libs/ardour/test
parent158c12eb92295509f45b1d868fe9b689d38aa39d (diff)
Add test for DSPLoadCalculator to libardour tests
Diffstat (limited to 'libs/ardour/test')
-rw-r--r--libs/ardour/test/dsp_load_calculator_test.cc112
-rw-r--r--libs/ardour/test/dsp_load_calculator_test.h12
2 files changed, 124 insertions, 0 deletions
diff --git a/libs/ardour/test/dsp_load_calculator_test.cc b/libs/ardour/test/dsp_load_calculator_test.cc
new file mode 100644
index 0000000000..12f063f165
--- /dev/null
+++ b/libs/ardour/test/dsp_load_calculator_test.cc
@@ -0,0 +1,112 @@
+#include <iostream>
+
+#include "ardour/dsp_load_calculator.h"
+
+#include "dsp_load_calculator_test.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (DSPLoadCalculatorTest);
+
+using namespace std;
+using namespace ARDOUR;
+
+void
+DSPLoadCalculatorTest::basicTest ()
+{
+ DSPLoadCalculator dsp_calc;
+
+ dsp_calc.set_max_time(48000, 512);
+ int64_t dsp_100_pc_48k_us = 10666;
+
+ CPPUNIT_ASSERT(dsp_calc.get_max_time_us() == dsp_100_pc_48k_us);
+
+ // test equivalent of 10% load
+ dsp_calc.set_start_timestamp_us(0);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us/10);
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 0.1f);
+
+ // test equivalent of 50% load and check that the load jumps to 50 percent
+ dsp_calc.set_start_timestamp_us(0);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us/2);
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 0.5f);
+
+ // test equivalent of 100% load
+ dsp_calc.set_start_timestamp_us(0);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us);
+ CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == dsp_100_pc_48k_us);
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0f);
+
+ // test setting the equivalent of 100% twice doesn't lead to a dsp value > 1.0
+ dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us * 2);
+ CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == dsp_100_pc_48k_us);
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0f);
+
+ // test setting the equivalent of 200% clamps the value to 1.0
+ dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us * 3);
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() == 1.0f);
+
+ // test setting the an stop timestamp before the start timestamp is ignored
+ // and the previous dsp value is returned
+ dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us * 2);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us);
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() == 1.0f);
+
+ float dsp_load = dsp_calc.get_dsp_load();
+
+ // test setting the equivalent of beyond the max_timer_error_us is ignored and
+ // the previous dsp value is returned
+ dsp_calc.set_start_timestamp_us (0);
+ dsp_calc.set_stop_timestamp_us (dsp_100_pc_48k_us*10);
+ CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() > dsp_calc.max_timer_error_us());
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() == dsp_load);
+
+ std::cout << std::endl;
+
+ // test the rate of rolloff of the LPF from 100% with load at constant 50%
+ // over the equivalent of 1 second
+ for (int i = 0; i < 1e6 / dsp_100_pc_48k_us; ++i) {
+ dsp_calc.set_start_timestamp_us(0);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us / 2);
+ CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == 5333);
+ std::cout << "DSP 50% load value = " << dsp_calc.get_dsp_load() << std::endl;
+ }
+
+ // test that the LPF is still working after one second of values
+ // TODO need to work out what is required in terms of responsiveness etc
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() > 0.5f);
+
+ // compare 96k to 48k
+ DSPLoadCalculator dsp_calc_96k;
+ dsp_calc_96k.set_max_time(96000, 512);
+ int64_t dsp_100_pc_96k_us = 5333;
+
+ // reset both to 100%
+ dsp_calc.set_start_timestamp_us(dsp_100_pc_48k_us);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us * 2);
+ CPPUNIT_ASSERT(dsp_calc.elapsed_time_us() == dsp_100_pc_48k_us);
+ CPPUNIT_ASSERT(dsp_calc.get_dsp_load() <= 1.0f);
+ dsp_calc_96k.set_start_timestamp_us(dsp_100_pc_96k_us);
+ dsp_calc_96k.set_stop_timestamp_us(dsp_100_pc_96k_us * 2);
+ CPPUNIT_ASSERT(dsp_calc_96k.elapsed_time_us() == dsp_100_pc_96k_us);
+ CPPUNIT_ASSERT(dsp_calc_96k.get_dsp_load() <= 1.0f);
+
+ // test the rate of rolloff of the LPF from 100% with load at constant 50%
+ // over the equivalent of 1 second for 48k and 96k and test for ~equality
+ for (int i = 0; i < 1e6 / dsp_100_pc_96k_us; ++i) {
+ dsp_calc_96k.set_start_timestamp_us(0);
+ dsp_calc_96k.set_stop_timestamp_us(dsp_100_pc_96k_us / 2);
+ if (i % 2 == 0) {
+ dsp_calc.set_start_timestamp_us(0);
+ dsp_calc.set_stop_timestamp_us(dsp_100_pc_48k_us / 2);
+
+ std::cout << "DSP 50% load value 48k = " << dsp_calc.get_dsp_load()
+ << std::endl;
+ std::cout << "DSP 50% load value 96k = " << dsp_calc_96k.get_dsp_load()
+ << std::endl;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(dsp_calc.get_dsp_load(),
+ dsp_calc_96k.get_dsp_load(), 0.001);
+ }
+ }
+
+}
diff --git a/libs/ardour/test/dsp_load_calculator_test.h b/libs/ardour/test/dsp_load_calculator_test.h
new file mode 100644
index 0000000000..3f2ee8359e
--- /dev/null
+++ b/libs/ardour/test/dsp_load_calculator_test.h
@@ -0,0 +1,12 @@
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class DSPLoadCalculatorTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE (DSPLoadCalculatorTest);
+ CPPUNIT_TEST (basicTest);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+ void basicTest ();
+};