changeset 139:1aef2b746c64

More (failing) tests
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 19 May 2014 17:46:40 +0100
parents 7563025cc1b1
children 9bf76fc43844
files test/TestCQFrequency.cpp test/TestCQTime.cpp
diffstat 2 files changed, 66 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/test/TestCQFrequency.cpp	Mon May 19 17:25:08 2014 +0100
+++ b/test/TestCQFrequency.cpp	Mon May 19 17:46:40 2014 +0100
@@ -26,7 +26,7 @@
 // Set up fs/2 = 50, frequency range 10 -> 40 i.e. 2 octaves, fixed
 // duration of 2 seconds
 static const double sampleRate = 100;
-static const double cqmin = 10;
+static const double cqmin = 11.8921;
 static const double cqmax = 40;
 static const double bpo = 4;
 static const int duration = sampleRate * 2;
@@ -37,7 +37,7 @@
 int
 binForFrequency(double freq)
 {
-    int bin = (2 * bpo) - round(bpo * log2(freq / cqmin));
+    int bin = (bpo * 2) - round(bpo * log2(freq / cqmin)) - 1;
     return bin;
 }
 
@@ -48,25 +48,24 @@
     double maxval = 0.0;
     int maxidx = -1;
     int height = column.size();
-    for (int j = 0; j < height; ++j) {
+
+    int nonZeroHeight = ((i % 2 == 1) ? height/2 : height);
+
+    for (int j = 0; j < nonZeroHeight; ++j) {
         if (j == 0 || column[j] > maxval) {
             maxval = column[j];
             maxidx = j;
         }
     }
 
-    int nonZeroHeight = height;
-    if (interp == CQSpectrogram::InterpolateZeros && i % 2 == 1) {
-        nonZeroHeight = height / 2;
-    }
-
     int expected = binForFrequency(freq);
     if (maxval < threshold) {
         return; // ignore these columns at start and end
     } else if (expected < nonZeroHeight && maxidx != expected) {
-        cerr << "ERROR: In column " << i << ", maximum value for frequency "
-             << freq << " found at index " << maxidx << endl
-             << "(expected index " << expected << ")" << endl;
+        cerr << "ERROR: In column " << i << " with interpolation " << interp
+             << ", maximum value for frequency " << freq
+             << "\n       found at index " << maxidx
+             << " (expected index " << expected << ")" << endl;
         cerr << "column contains: ";
         for (int j = 0; j < height; ++j) {
             cerr << column[j] << " ";
@@ -91,8 +90,19 @@
         CQParameters params(sampleRate, cqmin, cqmax, bpo);
         CQSpectrogram cq(params, interp);
 
+        cerr << "cq freq " << freq << ", binForFrequency " << binForFrequency(freq) << endl;
+        
+        cerr << "bin freqs: ";
+        for (int i = 0; i < cq.getBinsPerOctave() * cq.getOctaves(); ++i) {
+            cerr << i << ": " << cq.getBinFrequency(i) << ", ";
+        }
+        cerr << endl;
+
         BOOST_CHECK_EQUAL(cq.getBinsPerOctave(), bpo);
         BOOST_CHECK_EQUAL(cq.getOctaves(), 2);
+        BOOST_CHECK_CLOSE(cq.getBinFrequency(0), 40, 1e-10);
+        BOOST_CHECK_CLOSE(cq.getBinFrequency(4), 20, 1e-10);
+        BOOST_CHECK_CLOSE(cq.getBinFrequency(7), cqmin, 1e-3);
 
         vector<double> input;
         for (int i = 0; i < duration; ++i) {
@@ -114,11 +124,10 @@
 }
 
 BOOST_AUTO_TEST_CASE(freq_11) { testCQFrequency(11); }
-BOOST_AUTO_TEST_CASE(freq_15) { testCQFrequency(15); }
-BOOST_AUTO_TEST_CASE(freq_20) { testCQFrequency(20); }
-BOOST_AUTO_TEST_CASE(freq_25) { testCQFrequency(25); }
-BOOST_AUTO_TEST_CASE(freq_30) { testCQFrequency(30); }
-BOOST_AUTO_TEST_CASE(freq_35) { testCQFrequency(35); }
+BOOST_AUTO_TEST_CASE(freq_16) { testCQFrequency(16); }
+BOOST_AUTO_TEST_CASE(freq_23) { testCQFrequency(23); }
+BOOST_AUTO_TEST_CASE(freq_27) { testCQFrequency(27); }
+BOOST_AUTO_TEST_CASE(freq_33) { testCQFrequency(33); }
 BOOST_AUTO_TEST_CASE(freq_40) { testCQFrequency(40); }
 
 BOOST_AUTO_TEST_SUITE_END()
--- a/test/TestCQTime.cpp	Mon May 19 17:25:08 2014 +0100
+++ b/test/TestCQTime.cpp	Mon May 19 17:46:40 2014 +0100
@@ -43,15 +43,19 @@
 
     for (int k = 0; k < int(interpolationTypes.size()); ++k) {
 
+        CQSpectrogram::Interpolation interp = interpolationTypes[k];
+
         CQParameters params(sampleRate, cqmin, cqmax, bpo);
-        CQSpectrogram cq(params, interpolationTypes[k]);
+        CQSpectrogram cq(params, interp);
 
         BOOST_CHECK_EQUAL(cq.getBinsPerOctave(), bpo);
         BOOST_CHECK_EQUAL(cq.getOctaves(), 2);
 
         //!!! generate input signal
-        vector<double> input;
-
+        vector<double> input(duration, 0.0);
+        int ix = int(floor(t * sampleRate));
+        if (ix >= duration) ix = duration-1;
+        input[ix] = 1.0;
 
         CQSpectrogram::RealBlock output = cq.process(input);
         CQSpectrogram::RealBlock rest = cq.getRemainingOutput();
@@ -60,7 +64,40 @@
         BOOST_CHECK_EQUAL(output[0].size(), 
                           cq.getBinsPerOctave() * cq.getOctaves());
 
-        //!!! test output signal
+        for (int j = 0; j < int(output[0].size()); ++j) {
+
+            int maxidx = -1;
+            double max = 0.0;
+            for (int i = 0; i < int(output.size()); ++i) {
+                double value = output[i][j];
+                if (i == 0 || value > max) {
+                    max = value;
+                    maxidx = i;
+                }
+            }
+
+            int expected = round((ix + cq.getLatency()) / cq.getColumnHop());
+
+            if (maxidx != expected) {
+                cerr << "ERROR: In row " << j << " (bin freq "
+                     << cq.getBinFrequency(j) << "), interpolation " << interp
+                     << ", maximum value for time " << t 
+                     << "\n       found at index " << maxidx 
+                     << " of " << output.size() << " (expected index "
+                     << expected << ")\n       [latency = " << cq.getLatency()
+                     << ", hop = " << cq.getColumnHop() << ", duration = "
+                     << duration << "]" << endl;
+                cerr << "row contains: ";
+                for (int i = 0; i < int(output.size()); ++i) {
+                    if (i == expected) cerr << "*";
+                    if (i == maxidx) cerr << "**";
+                    cerr << output[i][j] << " ";
+                }
+                cerr << endl;
+
+                BOOST_CHECK_EQUAL(maxidx, expected);
+            }
+        }
     }
 }