diff dsp/rateconversion/TestResampler.cpp @ 363:2fe2ab316c8e

Add one-shot resample function
author Chris Cannam <c.cannam@qmul.ac.uk>
date Sun, 13 Oct 2013 12:47:50 +0100
parents 3953f3ef1b62
children 7fe0da91e9c3
line wrap: on
line diff
--- a/dsp/rateconversion/TestResampler.cpp	Fri Oct 11 18:00:51 2013 +0100
+++ b/dsp/rateconversion/TestResampler.cpp	Sun Oct 13 12:47:50 2013 +0100
@@ -15,6 +15,23 @@
 
 using std::cout;
 using std::endl;
+using std::vector;
+
+void
+testResamplerOneShot(int sourceRate,
+		     int targetRate,
+		     int n,
+		     double *in,
+		     int m,
+		     double *expected)
+{
+    vector<double> resampled = Resampler::resample(sourceRate, targetRate,
+						   in, n);
+    BOOST_CHECK_EQUAL(resampled.size(), m);
+    for (int i = 0; i < m; ++i) {
+	BOOST_CHECK_SMALL(resampled[i] - expected[i], 1e-8);
+    }
+}
 
 void
 testResampler(int sourceRate,
@@ -24,6 +41,8 @@
 	      int m,
 	      double *expected)
 {
+//!!! to be useful, this should provide the input in varying-size chunks
+
     Resampler r(sourceRate, targetRate);
     int latency = r.getLatency();
     std::cerr << "latency = " << latency << std::endl;
@@ -57,7 +76,7 @@
     std::cerr << "\n";
 
     for (int i = latency; i < m1; ++i) {
-	BOOST_CHECK_CLOSE(outPadded[i], expected[i-latency], 1e-8);
+	BOOST_CHECK_SMALL(outPadded[i] - expected[i-latency], 1e-8);
     }
     delete[] outPadded;
     delete[] inPadded;
@@ -66,6 +85,7 @@
 BOOST_AUTO_TEST_CASE(sameRate)
 {
     double d[] = { 0, 0.1, -0.3, -0.4, -0.3, 0, 0.5, 0.2, 0.8, -0.1 };
+    testResamplerOneShot(4, 4, 10, d, 10, d);
     testResampler(4, 4, 10, d, 10, d);
 }