changeset 7:dfec65a1ca6b

Fixes to tests
author Chris Cannam
date Wed, 16 Oct 2013 08:16:23 +0100
parents f55097c5d69f
children 94c1cadc6caf
files garage-resampler/Makefile garage-resampler/TestResampler.cpp
diffstat 2 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/garage-resampler/Makefile	Tue Oct 15 18:27:19 2013 +0100
+++ b/garage-resampler/Makefile	Wed Oct 16 08:16:23 2013 +0100
@@ -8,7 +8,7 @@
 
 TESTS	:= test-resampler
 
-VG	:= valgrind
+#VG	:= valgrind
 
 all: $(TESTS)
 	@for t in $(TESTS); do echo "Running $$t"; $(VG) ./"$$t" || exit 1; done
--- a/garage-resampler/TestResampler.cpp	Tue Oct 15 18:27:19 2013 +0100
+++ b/garage-resampler/TestResampler.cpp	Wed Oct 16 08:16:23 2013 +0100
@@ -151,15 +151,16 @@
 }
 
 vector<double>
-squareWave(int rate, int freq, int n)
+squareWave(int rate, double freq, int n)
 {
     //!!! todo: hoist, test
     vector<double> v(n, 0.0);
     for (int h = 0; h < (rate/4)/freq; ++h) {
 	double m = h * 2 + 1;
-	double scale = 1 / m;
+	double scale = 1.0 / m;
 	for (int i = 0; i < n; ++i) {
-	    v[i] += scale * sin(i * 2 * M_PI * freq / rate);
+	    double s = scale * sin((i * 2.0 * M_PI * m * freq) / rate);
+	    v[i] += s;
 	}
     }
     return v;
@@ -190,14 +191,33 @@
 
     vector<double> inSpectrum(inrate, 0.0);
     FFTReal(inrate).forwardMagnitude(square.data(), inSpectrum.data());
+    for (int i = 0; i < inSpectrum.size(); ++i) {
+	inSpectrum[i] /= inrate;
+    }
 
     vector<double> outSpectrum(outrate, 0.0);
     FFTReal(outrate).forwardMagnitude(maybeSquare.data(), outSpectrum.data());
+    for (int i = 0; i < outSpectrum.size(); ++i) {
+	outSpectrum[i] /= outrate;
+    }
 
     // Don't compare bins any higher than 99% of Nyquist freq of lower sr
     int lengthOfInterest = (inrate < outrate ? inrate : outrate) / 2;
     lengthOfInterest = lengthOfInterest - (lengthOfInterest / 100);
+/*
+    std::cerr << "inSpectrum:" << std::endl;
+    for (int i = 0; i < lengthOfInterest; ++i) {
+	if (i % 5 == 0) std::cerr << std::endl << i << ": ";
+	std::cerr << inSpectrum[i] << " ";
+    }
 
+    std::cerr << "\noutSpectrum:" << std::endl;
+    for (int i = 0; i < lengthOfInterest; ++i) {
+	if (i % 5 == 0) std::cerr << std::endl << i << ": ";
+	std::cerr << outSpectrum[i] << " ";
+    }
+    std::cerr << std::endl;
+*/
     for (int i = 0; i < lengthOfInterest; ++i) {
 	BOOST_CHECK_SMALL(inSpectrum[i] - outSpectrum[i], 1e-7);
     }