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