Mercurial > hg > constant-q-cpp
comparison test/TestCQTime.cpp @ 135:cb0f0e317a33
Different interpolation types; start on timing tests
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 19 May 2014 13:02:08 +0100 |
parents | |
children | 1aef2b746c64 |
comparison
equal
deleted
inserted
replaced
134:7b48d7ae41e4 | 135:cb0f0e317a33 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 #include "cq/CQSpectrogram.h" | |
4 | |
5 #include "dsp/Window.h" | |
6 | |
7 #include <cmath> | |
8 #include <vector> | |
9 #include <iostream> | |
10 | |
11 using std::vector; | |
12 using std::cerr; | |
13 using std::endl; | |
14 | |
15 #define BOOST_TEST_DYN_LINK | |
16 #define BOOST_TEST_MAIN | |
17 | |
18 #include <boost/test/unit_test.hpp> | |
19 | |
20 BOOST_AUTO_TEST_SUITE(TestCQTime) | |
21 | |
22 // Principle: Run a Dirac impulse through the CQ transform and check | |
23 // that its output has all the peak bins aligned correctly in time. | |
24 | |
25 // Set up fs/2 = 50, frequency range 10 -> 40 i.e. 2 octaves, fixed | |
26 // duration of 2 seconds | |
27 static const double sampleRate = 100; | |
28 static const double cqmin = 10; | |
29 static const double cqmax = 40; | |
30 static const double bpo = 4; | |
31 static const int duration = sampleRate * 2; | |
32 | |
33 // Threshold below which to ignore a column completely | |
34 static const double threshold = 0.08; | |
35 | |
36 void | |
37 testCQTime(double t) | |
38 { | |
39 vector<CQSpectrogram::Interpolation> interpolationTypes; | |
40 interpolationTypes.push_back(CQSpectrogram::InterpolateZeros); | |
41 interpolationTypes.push_back(CQSpectrogram::InterpolateHold); | |
42 interpolationTypes.push_back(CQSpectrogram::InterpolateLinear); | |
43 | |
44 for (int k = 0; k < int(interpolationTypes.size()); ++k) { | |
45 | |
46 CQParameters params(sampleRate, cqmin, cqmax, bpo); | |
47 CQSpectrogram cq(params, interpolationTypes[k]); | |
48 | |
49 BOOST_CHECK_EQUAL(cq.getBinsPerOctave(), bpo); | |
50 BOOST_CHECK_EQUAL(cq.getOctaves(), 2); | |
51 | |
52 //!!! generate input signal | |
53 vector<double> input; | |
54 | |
55 | |
56 CQSpectrogram::RealBlock output = cq.process(input); | |
57 CQSpectrogram::RealBlock rest = cq.getRemainingOutput(); | |
58 output.insert(output.end(), rest.begin(), rest.end()); | |
59 | |
60 BOOST_CHECK_EQUAL(output[0].size(), | |
61 cq.getBinsPerOctave() * cq.getOctaves()); | |
62 | |
63 //!!! test output signal | |
64 } | |
65 } | |
66 | |
67 BOOST_AUTO_TEST_CASE(time_zero) { testCQTime(0); } | |
68 BOOST_AUTO_TEST_CASE(time_half) { testCQTime(0.5); } | |
69 BOOST_AUTO_TEST_CASE(time_one) { testCQTime(1.0); } | |
70 BOOST_AUTO_TEST_CASE(time_two) { testCQTime(2.0); } | |
71 | |
72 BOOST_AUTO_TEST_SUITE_END() | |
73 |