Mercurial > hg > constant-q-cpp
comparison test/TestCQFrequency.cpp @ 133:16822c41b9af
Crop some excessively optimistic tests. We now fail the same two cases as the yeti implementation does.
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 19 May 2014 12:47:45 +0100 |
parents | c188cade44f8 |
children | cb0f0e317a33 |
comparison
equal
deleted
inserted
replaced
132:c188cade44f8 | 133:16822c41b9af |
---|---|
19 | 19 |
20 BOOST_AUTO_TEST_SUITE(TestCQFrequency) | 20 BOOST_AUTO_TEST_SUITE(TestCQFrequency) |
21 | 21 |
22 // The principle here is to feed a single windowed sinusoid into a | 22 // The principle here is to feed a single windowed sinusoid into a |
23 // small CQ transform and check that the output has its peak bin at | 23 // small CQ transform and check that the output has its peak bin at |
24 // the correct frequency. We can repeat for different frequencies both | 24 // the correct frequency. |
25 // inside and outside the frequency range supported by the CQ. We | |
26 // should also repeat for CQSpectrogram outputs as well as the raw CQ. | |
27 | 25 |
28 // Set up fs/2 = 50, frequency range 10 -> 40 i.e. 2 octaves, fixed | 26 // Set up fs/2 = 50, frequency range 10 -> 40 i.e. 2 octaves, fixed |
29 // duration of 2 seconds | 27 // duration of 2 seconds |
30 static const double sampleRate = 100; | 28 static const double sampleRate = 100; |
31 static const double cqmin = 10; | 29 static const double cqmin = 10; |
38 | 36 |
39 int | 37 int |
40 binForFrequency(double freq) | 38 binForFrequency(double freq) |
41 { | 39 { |
42 int bin = (2 * bpo) - round(bpo * log2(freq / cqmin)); | 40 int bin = (2 * bpo) - round(bpo * log2(freq / cqmin)); |
43 cerr << "binForFrequency: " << freq << " -> " << bin << endl; | |
44 return bin; | 41 return bin; |
45 } | 42 } |
46 | 43 |
47 void | 44 void |
48 checkCQFreqColumn(int i, vector<double> column, double freq) | 45 checkCQFreqColumn(int i, vector<double> column, double freq) |
54 if (j == 0 || column[j] > maxval) { | 51 if (j == 0 || column[j] > maxval) { |
55 maxval = column[j]; | 52 maxval = column[j]; |
56 maxidx = j; | 53 maxidx = j; |
57 } | 54 } |
58 } | 55 } |
59 cerr << "maxval = " << maxval << " at " << maxidx << endl; | |
60 int expected = binForFrequency(freq); | 56 int expected = binForFrequency(freq); |
61 if (maxval < threshold) { | 57 if (maxval < threshold) { |
62 return; // ignore these columns at start and end | 58 return; // ignore these columns at start and end |
63 } else if (expected < 0 || expected >= height) { | |
64 cerr << "maxval = " << maxval << endl; | |
65 BOOST_CHECK(maxval < threshold); | |
66 } else { | 59 } else { |
60 if (maxidx != expected) { | |
61 cerr << "ERROR: In column " << i << ", maximum value for frequency " | |
62 << freq << " found at index " << maxidx << endl | |
63 << "(expected index " << expected << ")" << endl; | |
64 cerr << "column contains: "; | |
65 for (int j = 0; j < height; ++j) { | |
66 cerr << column[j] << " "; | |
67 } | |
68 cerr << endl; | |
69 } | |
67 BOOST_CHECK_EQUAL(maxidx, expected); | 70 BOOST_CHECK_EQUAL(maxidx, expected); |
68 } | 71 } |
69 } | 72 } |
70 | 73 |
71 void | 74 void |
92 for (int i = 0; i < int(output.size()); ++i) { | 95 for (int i = 0; i < int(output.size()); ++i) { |
93 checkCQFreqColumn(i, output[i], freq); | 96 checkCQFreqColumn(i, output[i], freq); |
94 } | 97 } |
95 } | 98 } |
96 | 99 |
97 BOOST_AUTO_TEST_CASE(freq_5) { testCQFrequency(5); } | 100 BOOST_AUTO_TEST_CASE(freq_11) { testCQFrequency(11); } |
98 BOOST_AUTO_TEST_CASE(freq_10) { testCQFrequency(10); } | |
99 BOOST_AUTO_TEST_CASE(freq_15) { testCQFrequency(15); } | 101 BOOST_AUTO_TEST_CASE(freq_15) { testCQFrequency(15); } |
100 BOOST_AUTO_TEST_CASE(freq_20) { testCQFrequency(20); } | 102 BOOST_AUTO_TEST_CASE(freq_20) { testCQFrequency(20); } |
101 BOOST_AUTO_TEST_CASE(freq_25) { testCQFrequency(25); } | 103 BOOST_AUTO_TEST_CASE(freq_25) { testCQFrequency(25); } |
102 BOOST_AUTO_TEST_CASE(freq_30) { testCQFrequency(30); } | 104 BOOST_AUTO_TEST_CASE(freq_30) { testCQFrequency(30); } |
103 BOOST_AUTO_TEST_CASE(freq_35) { testCQFrequency(35); } | 105 BOOST_AUTO_TEST_CASE(freq_35) { testCQFrequency(35); } |
104 BOOST_AUTO_TEST_CASE(freq_40) { testCQFrequency(40); } | 106 BOOST_AUTO_TEST_CASE(freq_40) { testCQFrequency(40); } |
105 BOOST_AUTO_TEST_CASE(freq_45) { testCQFrequency(45); } | |
106 BOOST_AUTO_TEST_CASE(freq_50) { testCQFrequency(50); } | |
107 | 107 |
108 BOOST_AUTO_TEST_SUITE_END() | 108 BOOST_AUTO_TEST_SUITE_END() |
109 | 109 |