changeset 143:c66f0f78b315

A few more kernel tests
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 20 May 2014 11:44:43 +0100
parents b043b6cee17a
children 88b8d34bfc77
files test/TestCQKernel.cpp test/test-inverse.sh
diffstat 2 files changed, 58 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/TestCQKernel.cpp	Tue May 20 11:30:55 2014 +0100
+++ b/test/TestCQKernel.cpp	Tue May 20 11:44:43 2014 +0100
@@ -15,15 +15,52 @@
 
 #include <boost/test/unit_test.hpp>
 
+static int rate = 123;
+static int max = 60;
+static int min = 12;
+static int bpo = 4;
+
 BOOST_AUTO_TEST_SUITE(TestCQKernel)
 
 // Just some simple tests on kernel construction -- make sure it's the
 // right size, etc
 
-BOOST_AUTO_TEST_CASE(rate) {
-    CQParameters params(123, 12, 65, 4);
+BOOST_AUTO_TEST_CASE(sampleRate) {
+    CQParameters params(rate, min, max, bpo);
     CQKernel k(params);
-    BOOST_CHECK_EQUAL(k.getProperties().sampleRate, 123);
+    BOOST_CHECK_EQUAL(k.getProperties().sampleRate, rate);
+}
+
+BOOST_AUTO_TEST_CASE(binsPerOctave) {
+    CQParameters params(rate, min, max, bpo);
+    CQKernel k(params);
+    BOOST_CHECK_EQUAL(k.getProperties().binsPerOctave, bpo);
+}
+
+BOOST_AUTO_TEST_CASE(maxFrequency) {
+    CQParameters params(rate, min, max, bpo);
+    CQKernel k(params);
+    BOOST_CHECK_EQUAL(k.getProperties().maxFrequency, max);
+}
+
+BOOST_AUTO_TEST_CASE(minFrequency) {
+    CQParameters params(rate, min, max, bpo);
+    CQKernel k(params);
+    BOOST_CHECK_CLOSE(k.getProperties().minFrequency,
+		      (max / 2.0) * pow(2, 1.0/bpo),
+		      1e-8);
+}
+
+BOOST_AUTO_TEST_CASE(atomsPerFrame) {
+    CQParameters params(rate, min, max, bpo);
+    CQKernel k(params);
+    BOOST_CHECK_EQUAL(k.getProperties().atomsPerFrame, 5);
+}
+
+BOOST_AUTO_TEST_CASE(fftSize) {
+    CQParameters params(rate, min, max, bpo);
+    CQKernel k(params);
+    BOOST_CHECK_EQUAL(k.getProperties().fftSize, 32);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
--- a/test/test-inverse.sh	Tue May 20 11:30:55 2014 +0100
+++ b/test/test-inverse.sh	Tue May 20 11:44:43 2014 +0100
@@ -1,5 +1,20 @@
 #!/bin/bash
+
+# Test that the forward-inverse CQ transform produces the same output
+# (to a given noise level, and within the appropriate frequency range)
+# as its input.
+#
+# This requires the program "processfile" to be compiled and in the
+# same directory, and an audio file filtered-whitenoise-480-14600.wav
+# to be in the subdir "data". The audio file contains white noise
+# band-limited to the 480-14600Hz range. This is fed as input to a
+# forward-inverse CQ chain restricted to the range 465-14700 Hz (5
+# octaves); the processfile program calculates the output and performs
+# a sample-by-sample diff against the input. We then check that the
+# diff is below a suitable noise floor.
+
 mydir=`dirname "$0"`
+
 process="$mydir/processfile"
 if [ ! -x "$process" ]; then
     echo "ERROR: $mydir/processfile not found or not executable"
@@ -10,11 +25,14 @@
     echo "ERROR: Test file $infile not found"
     exit 1
 fi
+
 outfile="/tmp/$$.out.wav"
 difffile="/tmp/$$.diff.wav"
 logfile="/tmp/$$.log.txt"
 trap "rm -f ${outfile} ${difffile} ${logfile}" 0
+
 "$process" -x 14700 -n 465 -b 36 "$infile" "$outfile" "$difffile" 2>&1 | tee "$logfile" || exit 1
+
 int_db=`grep 'max diff' "$logfile" | sed 's/^[^(]*(//' | sed 's/[^0-9-].*//'`
 good=`expr "$int_db" "<" "-20"`
 if [ "$good" == "1" ]; then