changeset 142:b043b6cee17a

Start kernel test file, add inverse test script
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 20 May 2014 11:30:55 +0100
parents 0650826128d1
children c66f0f78b315
files Makefile.inc test/TestCQKernel.cpp test/TestCQTime.cpp test/data/filtered-whitenoise-480-14600.wav test/test-inverse.sh test/test.cpp
diffstat 6 files changed, 62 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.inc	Tue May 20 11:03:08 2014 +0100
+++ b/Makefile.inc	Tue May 20 11:30:55 2014 +0100
@@ -68,12 +68,13 @@
 	$(VAMP_DIR)/Pitch.cpp
 
 TEST_SOURCES	:= \
-	$(TEST_DIR)/TestCQFrequency.cpp \
-	$(TEST_DIR)/TestCQTime.cpp \
 	$(TEST_DIR)/TestFFT.cpp \
 	$(TEST_DIR)/TestMathUtilities.cpp \
 	$(TEST_DIR)/TestResampler.cpp \
-	$(TEST_DIR)/TestWindow.cpp
+	$(TEST_DIR)/TestWindow.cpp \
+	$(TEST_DIR)/TestCQKernel.cpp \
+	$(TEST_DIR)/TestCQFrequency.cpp \
+	$(TEST_DIR)/TestCQTime.cpp
 
 HEADERS	     := $(LIB_HEADERS) $(VAMP_HEADERS)
 SOURCES	     := $(LIB_SOURCES) $(VAMP_SOURCES)
@@ -93,7 +94,7 @@
 LIBS	:= $(VAMPSDK_DIR)/libvamp-sdk.a -lpthread
 
 all: $(LIB) $(PLUGIN) $(TEST_TARGETS) $(PF)
-	for t in $(TEST_TARGETS); do echo; echo "Running $$t"; $(VALGRIND) ./"$$t" || exit 1; done
+	for t in $(TEST_TARGETS); do echo; echo "Running $$t"; $(VALGRIND) ./"$$t" || exit 1; done && echo && $(VALGRIND) "./test/test-inverse.sh" && echo 'Tests complete'
 
 $(PLUGIN):	$(OBJECTS)
 	$(CXX) -o $@ $^ $(LIBS) $(PLUGIN_LDFLAGS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/TestCQKernel.cpp	Tue May 20 11:30:55 2014 +0100
@@ -0,0 +1,30 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+#include "cq/CQKernel.h"
+
+#include <cmath>
+#include <vector>
+#include <iostream>
+
+using std::vector;
+using std::cerr;
+using std::endl;
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+
+#include <boost/test/unit_test.hpp>
+
+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);
+    CQKernel k(params);
+    BOOST_CHECK_EQUAL(k.getProperties().sampleRate, 123);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
--- a/test/TestCQTime.cpp	Tue May 20 11:03:08 2014 +0100
+++ b/test/TestCQTime.cpp	Tue May 20 11:30:55 2014 +0100
@@ -51,7 +51,6 @@
         BOOST_CHECK_EQUAL(cq.getBinsPerOctave(), bpo);
         BOOST_CHECK_EQUAL(cq.getOctaves(), 2);
 
-        //!!! generate input signal
         vector<double> input(duration, 0.0);
         int ix = int(floor(t * sampleRate));
         if (ix >= duration) ix = duration-1;
Binary file test/data/filtered-whitenoise-480-14600.wav has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-inverse.sh	Tue May 20 11:30:55 2014 +0100
@@ -0,0 +1,27 @@
+#!/bin/bash
+mydir=`dirname "$0"`
+process="$mydir/processfile"
+if [ ! -x "$process" ]; then
+    echo "ERROR: $mydir/processfile not found or not executable"
+    exit 1
+fi
+infile="$mydir/data/filtered-whitenoise-480-14600.wav"
+if [ ! -f "$infile" ]; then
+    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
+    echo "Forward-inverse process is satisfactory"
+    exit 0
+else
+    echo "Forward-inverse not OK: Rounded dB value $int_db is too high -- should be < -20"
+    exit 1
+fi
+
--- a/test/test.cpp	Tue May 20 11:03:08 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/*
-    Constant-Q library
-    Copyright (c) 2013-2014 Queen Mary, University of London
-
-    Permission is hereby granted, free of charge, to any person
-    obtaining a copy of this software and associated documentation
-    files (the "Software"), to deal in the Software without
-    restriction, including without limitation the rights to use, copy,
-    modify, merge, publish, distribute, sublicense, and/or sell copies
-    of the Software, and to permit persons to whom the Software is
-    furnished to do so, subject to the following conditions:
-
-    The above copyright notice and this permission notice shall be
-    included in all copies or substantial portions of the Software.
-
-    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
-    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-    Except as contained in this notice, the names of the Centre for
-    Digital Music; Queen Mary, University of London; and Chris Cannam
-    shall not be used in advertising or otherwise to promote the sale,
-    use or other dealings in this Software without prior written
-    authorization.
-*/
-
-#include "CQSpectrogram.h"
-
-#include <iostream>
-#include <vector>
-
-using std::vector;
-using std::cerr;
-using std::cout;
-using std::endl;
-
-#include <cstdio>
-
-int main(int argc, char **argv)
-{
-    vector<double> in;
-
-    for (int i = 0; i < 64; ++i) {
-//	if (i == 0) in.push_back(1);
-//	else in.push_back(0);
-	in.push_back(sin(i * M_PI / 2.0));
-    }
-
-    CQParameters params(8, 1, 4, 4);
-    CQSpectrogram k(params, CQSpectrogram::InterpolateZeros);
-
-    vector<vector<double> > out = k.process(in);
-    vector<vector<double> > rest = k.getRemainingOutput();
-
-    out.insert(out.end(), rest.begin(), rest.end());
-
-    cerr << "got " << out.size() << " back (" << out[0].size() << " in each?)" << endl;
-
-    for (int b = 0; b < (int)out.size() / 8; ++b) {
-	printf("\nColumns %d to %d:\n\n", b * 8, b * 8 + 7);
-	for (int j = int(out[0].size()) - 1; j >= 0; --j) {
-	    for (int i = 0; i < 8; ++i) {
-		if (i + b * 8 < (int)out.size()) {
-		    double v = out[i + b * 8][j];
-		    if (v < 0.0001) printf("  0      ");
-		    else printf("  %.4f ", out[i + b * 8][j]);
-		}
-	    }
-	    printf("\n");
-	}
-    }
-}
-