# HG changeset patch # User Chris Cannam # Date 1559237458 -3600 # Node ID 2de6184b2ce052484589ad520b65aca86a3f0f36 # Parent 64fc3009d0a3772cd390bbb7079cba50481aecd3 Untabify diff -r 64fc3009d0a3 -r 2de6184b2ce0 tests/TestDCT.cpp --- a/tests/TestDCT.cpp Thu May 30 18:28:11 2019 +0100 +++ b/tests/TestDCT.cpp Thu May 30 18:30:58 2019 +0100 @@ -106,13 +106,13 @@ d.forward(in.data(), out.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(expected[i] - out[i], thresh); + BOOST_CHECK_SMALL(expected[i] - out[i], thresh); } d.inverse(out.data(), inv.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(in[i] - inv[i], thresh); + BOOST_CHECK_SMALL(in[i] - inv[i], thresh); } // do it again, just in case some internal state was modified in inverse @@ -120,7 +120,7 @@ d.forward(in.data(), out.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(expected[i] - out[i], thresh); + BOOST_CHECK_SMALL(expected[i] - out[i], thresh); } } @@ -140,13 +140,13 @@ d.forwardUnitary(in.data(), out.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(expected[i] - out[i], thresh); + BOOST_CHECK_SMALL(expected[i] - out[i], thresh); } d.inverseUnitary(out.data(), inv.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(in[i] - inv[i], thresh); + BOOST_CHECK_SMALL(in[i] - inv[i], thresh); } // do it again, just in case some internal state was modified in inverse @@ -154,7 +154,7 @@ d.forwardUnitary(in.data(), out.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(expected[i] - out[i], thresh); + BOOST_CHECK_SMALL(expected[i] - out[i], thresh); } } @@ -174,13 +174,13 @@ d.forwardUnitary(in.data(), out.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(expected[i] - out[i], thresh); + BOOST_CHECK_SMALL(expected[i] - out[i], thresh); } d.inverseUnitary(out.data(), inv.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(in[i] - inv[i], thresh); + BOOST_CHECK_SMALL(in[i] - inv[i], thresh); } // do it again, just in case some internal state was modified in inverse @@ -188,7 +188,7 @@ d.forwardUnitary(in.data(), out.data()); for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(expected[i] - out[i], thresh); + BOOST_CHECK_SMALL(expected[i] - out[i], thresh); } } diff -r 64fc3009d0a3 -r 2de6184b2ce0 tests/TestFFT.cpp --- a/tests/TestFFT.cpp Thu May 30 18:28:11 2019 +0100 +++ b/tests/TestFFT.cpp Thu May 30 18:30:58 2019 +0100 @@ -13,12 +13,12 @@ #define COMPARE_CONST(a, n) \ for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ - BOOST_CHECK_SMALL(a[cmp_i] - n, 1e-14); \ + BOOST_CHECK_SMALL(a[cmp_i] - n, 1e-14); \ } -#define COMPARE_ARRAY(a, b) \ +#define COMPARE_ARRAY(a, b) \ for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ - BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-14); \ + BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-14); \ } //!!! need at least one test with complex time-domain signal @@ -280,7 +280,7 @@ COMPARE_ARRAY(back, rin); COMPARE_ARRAY(backim, iin); } - + BOOST_AUTO_TEST_CASE(sineCosine) { // Sine and cosine mixed @@ -302,7 +302,7 @@ COMPARE_ARRAY(back, in); COMPARE_CONST(backim, 0.0); } - + BOOST_AUTO_TEST_CASE(r_sineCosine) { // Sine and cosine mixed @@ -325,7 +325,7 @@ FFTReal(4).inverse(re, im, back); COMPARE_ARRAY(back, in); } - + BOOST_AUTO_TEST_CASE(c_sineCosine) { double rin[] = { 1, 0, -1, 0 }; diff -r 64fc3009d0a3 -r 2de6184b2ce0 tests/TestFilter.cpp --- a/tests/TestFilter.cpp Thu May 30 18:28:11 2019 +0100 +++ b/tests/TestFilter.cpp Thu May 30 18:30:58 2019 +0100 @@ -38,7 +38,7 @@ double thresh = 1e-12; for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(out[i] - expected[i], thresh); + BOOST_CHECK_SMALL(out[i] - expected[i], thresh); } } @@ -56,20 +56,20 @@ int j = 0; int i = 0; while (j < n) { - if (++i == 4) { - i = 1; - } - if (j + i >= n) { - i = n - j; - } - f.process(in.data() + j, out.data() + j, i); - j += i; + if (++i == 4) { + i = 1; + } + if (j + i >= n) { + i = n - j; + } + f.process(in.data() + j, out.data() + j, i); + j += i; } double thresh = 1e-12; for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(out[i] - expected[i], thresh); + BOOST_CHECK_SMALL(out[i] - expected[i], thresh); } } @@ -88,7 +88,7 @@ double thresh = 1e-4; for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(out[i] - expected[i], thresh); + BOOST_CHECK_SMALL(out[i] - expected[i], thresh); } } diff -r 64fc3009d0a3 -r 2de6184b2ce0 tests/TestMedianFilter.cpp --- a/tests/TestMedianFilter.cpp Thu May 30 18:28:11 2019 +0100 +++ b/tests/TestMedianFilter.cpp Thu May 30 18:30:58 2019 +0100 @@ -18,19 +18,19 @@ // which start out all-zero. So the output median will remain zero // until N/2 elements have been pushed. MedianFilter f(3); - f.push(1); // 0 0 1 + f.push(1); // 0 0 1 BOOST_CHECK_EQUAL(f.get(), 0); BOOST_CHECK_EQUAL(f.get(), 0); - f.push(-3); // 0 1 -3 + f.push(-3); // 0 1 -3 BOOST_CHECK_EQUAL(f.get(), 0); - f.push(5); // 1 -3 5 + f.push(5); // 1 -3 5 BOOST_CHECK_EQUAL(f.get(), 1); - f.push(7); // -3 5 7 + f.push(7); // -3 5 7 BOOST_CHECK_EQUAL(f.get(), 5); BOOST_CHECK_EQUAL(f.get(), 5); - f.push(3); // 5 7 3 + f.push(3); // 5 7 3 BOOST_CHECK_EQUAL(f.get(), 5); - f.push(3); // 7 3 3 + f.push(3); // 7 3 3 BOOST_CHECK_EQUAL(f.get(), 3); } @@ -39,57 +39,57 @@ // Our median does not halve the difference (should it??), it just // returns the next element from the input set MedianFilter f(4); - f.push(1); // 0 0 0 1 + f.push(1); // 0 0 0 1 BOOST_CHECK_EQUAL(f.get(), 0); BOOST_CHECK_EQUAL(f.get(), 0); - f.push(-3); // 0 0 1 -3 + f.push(-3); // 0 0 1 -3 BOOST_CHECK_EQUAL(f.get(), 0); - f.push(5); // 0 1 -3 5 + f.push(5); // 0 1 -3 5 BOOST_CHECK_EQUAL(f.get(), 1); - f.push(7); // 1 -3 5 7 + f.push(7); // 1 -3 5 7 BOOST_CHECK_EQUAL(f.get(), 5); BOOST_CHECK_EQUAL(f.get(), 5); - f.push(3); // -3 5 7 3 + f.push(3); // -3 5 7 3 BOOST_CHECK_EQUAL(f.get(), 5); - f.push(3); // 5 7 3 3 + f.push(3); // 5 7 3 3 BOOST_CHECK_EQUAL(f.get(), 5); } BOOST_AUTO_TEST_CASE(odd75) { MedianFilter f(5, 75.f); - f.push(1); // 0 0 0 0 1 + f.push(1); // 0 0 0 0 1 BOOST_CHECK_EQUAL(f.get(), 0); BOOST_CHECK_EQUAL(f.get(), 0); - f.push(-3); // 0 0 0 1 -3 + f.push(-3); // 0 0 0 1 -3 BOOST_CHECK_EQUAL(f.get(), 0); - f.push(5); // 0 0 1 -3 5 + f.push(5); // 0 0 1 -3 5 BOOST_CHECK_EQUAL(f.get(), 1); - f.push(7); // 0 1 -3 5 7 + f.push(7); // 0 1 -3 5 7 BOOST_CHECK_EQUAL(f.get(), 5); BOOST_CHECK_EQUAL(f.get(), 5); - f.push(3); // 0 -3 5 7 3 + f.push(3); // 0 -3 5 7 3 BOOST_CHECK_EQUAL(f.get(), 5); - f.push(3); // 0 5 7 3 3 + f.push(3); // 0 5 7 3 3 BOOST_CHECK_EQUAL(f.get(), 5); } BOOST_AUTO_TEST_CASE(even75) { MedianFilter f(4, 75.f); - f.push(1); // 0 0 0 1 + f.push(1); // 0 0 0 1 BOOST_CHECK_EQUAL(f.get(), 1); BOOST_CHECK_EQUAL(f.get(), 1); - f.push(-3); // 0 0 1 -3 + f.push(-3); // 0 0 1 -3 BOOST_CHECK_EQUAL(f.get(), 1); - f.push(5); // 0 1 -3 5 + f.push(5); // 0 1 -3 5 BOOST_CHECK_EQUAL(f.get(), 5); - f.push(7); // 1 -3 5 7 + f.push(7); // 1 -3 5 7 BOOST_CHECK_EQUAL(f.get(), 7); BOOST_CHECK_EQUAL(f.get(), 7); - f.push(3); // -3 5 7 3 + f.push(3); // -3 5 7 3 BOOST_CHECK_EQUAL(f.get(), 7); - f.push(3); // 5 7 3 3 + f.push(3); // 5 7 3 3 BOOST_CHECK_EQUAL(f.get(), 7); } diff -r 64fc3009d0a3 -r 2de6184b2ce0 tests/TestPhaseVocoder.cpp --- a/tests/TestPhaseVocoder.cpp Thu May 30 18:28:11 2019 +0100 +++ b/tests/TestPhaseVocoder.cpp Thu May 30 18:30:58 2019 +0100 @@ -18,17 +18,17 @@ #define COMPARE_CONST(a, n) \ for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ - BOOST_CHECK_SMALL(a[cmp_i] - n, 1e-7); \ + BOOST_CHECK_SMALL(a[cmp_i] - n, 1e-7); \ } -#define COMPARE_ARRAY(a, b) \ +#define COMPARE_ARRAY(a, b) \ for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ - BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-7); \ + BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-7); \ } -#define COMPARE_ARRAY_EXACT(a, b) \ +#define COMPARE_ARRAY_EXACT(a, b) \ for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ - BOOST_CHECK_EQUAL(a[cmp_i], b[cmp_i]); \ + BOOST_CHECK_EQUAL(a[cmp_i], b[cmp_i]); \ } BOOST_AUTO_TEST_CASE(fullcycle) @@ -116,9 +116,9 @@ // the first frame if it did). double data[32] = { // 3 x 8-sample frames which we pretend are overlapping - 0, 1, 0, -1, 0, 1, 0, -1, - 1, 1.70710678, 0, -1.70710678, -1, 0.29289322, 0, -0.29289322, - -1, 0.29289322, 0, -0.29289322, 1, 1.70710678, 0, -1.70710678, + 0, 1, 0, -1, 0, 1, 0, -1, + 1, 1.70710678, 0, -1.70710678, -1, 0.29289322, 0, -0.29289322, + -1, 0.29289322, 0, -0.29289322, 1, 1.70710678, 0, -1.70710678, }; PhaseVocoder pvoc(8, 4); diff -r 64fc3009d0a3 -r 2de6184b2ce0 tests/TestResampler.cpp --- a/tests/TestResampler.cpp Thu May 30 18:28:11 2019 +0100 +++ b/tests/TestResampler.cpp Thu May 30 18:30:58 2019 +0100 @@ -22,30 +22,30 @@ void testResamplerOneShot(int sourceRate, - int targetRate, - int n, - double *in, - int m, - double *expected, - int skip) + int targetRate, + int n, + double *in, + int m, + double *expected, + int skip) { vector resampled = Resampler::resample(sourceRate, targetRate, - in, n); + in, n); if (skip == 0) { - BOOST_CHECK_EQUAL(resampled.size(), m); + BOOST_CHECK_EQUAL(resampled.size(), m); } for (int i = 0; i < m; ++i) { - BOOST_CHECK_SMALL(resampled[i + skip] - expected[i], 1e-6); + BOOST_CHECK_SMALL(resampled[i + skip] - expected[i], 1e-6); } } void testResampler(int sourceRate, - int targetRate, - int n, - double *in, - int m, - double *expected) + int targetRate, + int n, + double *in, + int m, + double *expected) { // Here we provide the input in chunks (of varying size) @@ -59,12 +59,12 @@ double *outPadded = new double[m1]; for (int i = 0; i < n1; ++i) { - if (i < n) inPadded[i] = in[i]; - else inPadded[i] = 0.0; + if (i < n) inPadded[i] = in[i]; + else inPadded[i] = 0.0; } for (int i = 0; i < m1; ++i) { - outPadded[i] = -999.0; + outPadded[i] = -999.0; } int chunkSize = 1; @@ -72,22 +72,22 @@ int i = 0; while (true) { - got += r.process(inPadded + i, outPadded + got, chunkSize); - i = i + chunkSize; - chunkSize = chunkSize + 1; - if (i >= n1) { - break; - } else if (i + chunkSize >= n1) { - chunkSize = n1 - i; - } else if (chunkSize > 15) { - chunkSize = 1; - } + got += r.process(inPadded + i, outPadded + got, chunkSize); + i = i + chunkSize; + chunkSize = chunkSize + 1; + if (i >= n1) { + break; + } else if (i + chunkSize >= n1) { + chunkSize = n1 - i; + } else if (chunkSize > 15) { + chunkSize = 1; + } } BOOST_CHECK_EQUAL(got, m1); for (int i = latency; i < m1; ++i) { - BOOST_CHECK_SMALL(outPadded[i] - expected[i-latency], 1e-8); + BOOST_CHECK_SMALL(outPadded[i] - expected[i-latency], 1e-8); } delete[] outPadded; @@ -113,10 +113,10 @@ double in[] = { 0, 0.1, -0.3, -0.4, -0.3, 0, 0.5, 0.2, 0.8, -0.1 }; int n = sizeof(in)/sizeof(in[0]); for (int factor = 2; factor < 10; ++factor) { - vector out = Resampler::resample(6, 6 * factor, in, n); - for (int i = 0; i < n; ++i) { - BOOST_CHECK_SMALL(out[i * factor] - in[i], 1e-5); - } + vector out = Resampler::resample(6, 6 * factor, in, n); + for (int i = 0; i < n; ++i) { + BOOST_CHECK_SMALL(out[i * factor] - in[i], 1e-5); + } } } @@ -127,10 +127,10 @@ double in[1000]; double out[2000]; for (int i = 0; i < 1000; ++i) { - in[i] = sin(i * M_PI / 2.0); + in[i] = sin(i * M_PI / 2.0); } for (int i = 0; i < 2000; ++i) { - out[i] = sin(i * M_PI / 4.0); + out[i] = sin(i * M_PI / 4.0); } testResamplerOneShot(8, 16, 1000, in, 200, out, 512); } @@ -142,10 +142,10 @@ double in[2000]; double out[1000]; for (int i = 0; i < 2000; ++i) { - in[i] = sin(i * M_PI / 8.0); + in[i] = sin(i * M_PI / 8.0); } for (int i = 0; i < 1000; ++i) { - out[i] = sin(i * M_PI / 4.0); + out[i] = sin(i * M_PI / 4.0); } testResamplerOneShot(16, 8, 2000, in, 200, out, 256); } @@ -251,12 +251,12 @@ //!!! todo: hoist, test vector v(n, 0.0); for (int h = 0; h < (rate/4)/freq; ++h) { - double m = h * 2 + 1; - double scale = 1.0 / m; - for (int i = 0; i < n; ++i) { - double s = scale * sin((i * 2.0 * M_PI * m * freq) / rate); - v[i] += s; - } + double m = h * 2 + 1; + double scale = 1.0 / m; + for (int i = 0; i < n; ++i) { + double s = scale * sin((i * 2.0 * M_PI * m * freq) / rate); + v[i] += s; + } } return v; } @@ -268,10 +268,10 @@ int freq = 500; vector square = - squareWave(inrate, freq, inrate); + squareWave(inrate, freq, inrate); vector maybeSquare = - Resampler::resample(inrate, outrate, square.data(), square.size()); + Resampler::resample(inrate, outrate, square.data(), square.size()); BOOST_CHECK_EQUAL(maybeSquare.size(), outrate); @@ -283,13 +283,13 @@ vector inSpectrum(inrate, 0.0); FFTReal(inrate).forwardMagnitude(square.data(), inSpectrum.data()); for (int i = 0; i < (int)inSpectrum.size(); ++i) { - inSpectrum[i] /= inrate; + inSpectrum[i] /= inrate; } vector outSpectrum(outrate, 0.0); FFTReal(outrate).forwardMagnitude(maybeSquare.data(), outSpectrum.data()); for (int i = 0; i < (int)outSpectrum.size(); ++i) { - outSpectrum[i] /= outrate; + outSpectrum[i] /= outrate; } // Don't compare bins any higher than 96% of Nyquist freq of lower sr @@ -297,7 +297,7 @@ lengthOfInterest = lengthOfInterest - (lengthOfInterest / 25); for (int i = 0; i < lengthOfInterest; ++i) { - BOOST_CHECK_SMALL(inSpectrum[i] - outSpectrum[i], 1e-7); + BOOST_CHECK_SMALL(inSpectrum[i] - outSpectrum[i], 1e-7); } } /* @@ -305,9 +305,9 @@ { int rates[] = { 8000, 22050, 44100, 48000 }; for (int i = 0; i < (int)(sizeof(rates)/sizeof(rates[0])); ++i) { - for (int j = 0; j < (int)(sizeof(rates)/sizeof(rates[0])); ++j) { - testSpectrum(rates[i], rates[j]); - } + for (int j = 0; j < (int)(sizeof(rates)/sizeof(rates[0])); ++j) { + testSpectrum(rates[i], rates[j]); + } } } */ diff -r 64fc3009d0a3 -r 2de6184b2ce0 tests/TestWindow.cpp --- a/tests/TestWindow.cpp Thu May 30 18:28:11 2019 +0100 +++ b/tests/TestWindow.cpp Thu May 30 18:30:58 2019 +0100 @@ -16,16 +16,16 @@ using std::cout; using std::endl; -#define COMPARE_ARRAY(a, b) \ +#define COMPARE_ARRAY(a, b) \ for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ - BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-4); \ + BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-4); \ } void testSymmetric(double *d, int n) { for (int i = 0; i <= n/2; ++i) { - BOOST_CHECK_CLOSE(d[i], d[n-i-1], 1e-10); + BOOST_CHECK_CLOSE(d[i], d[n-i-1], 1e-10); } } @@ -37,12 +37,12 @@ // becomes when generated in periodic mode double d[9]; for (int n = 8; n <= 9; ++n) { - for (int wt = (int)FirstWindow; wt <= (int)LastWindow; ++wt) { - for (int i = 0; i < n; ++i) d[i] = 1.0; - Window w((WindowType)wt, n); - w.cut(d); - testSymmetric(d + 1, n - 1); - } + for (int wt = (int)FirstWindow; wt <= (int)LastWindow; ++wt) { + for (int i = 0; i < n; ++i) d[i] = 1.0; + Window w((WindowType)wt, n); + w.cut(d); + testSymmetric(d + 1, n - 1); + } } } @@ -59,7 +59,7 @@ for (int i = 0; i < N; ++i) d0[i] = 0.5 + (1.0 / (N * 2)) * (i + 1); w.cut(d0, d1); for (int i = 0; i < N; ++i) { - BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4); + BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4); } } @@ -90,7 +90,7 @@ testWindow<1>(HammingWindow, e1); double e10[] = { - 0.0800, 0.1679, 0.3979, 0.6821, 0.9121, + 0.0800, 0.1679, 0.3979, 0.6821, 0.9121, 1.0000, 0.9121, 0.6821, 0.3979, 0.1679 }; testWindow<10>(HammingWindow, e10); @@ -179,7 +179,7 @@ for (int i = 0; i < N; ++i) d0[i] = 0.5 + (1.0 / (N * 2)) * (i + 1); w.cut(d0, d1); for (int i = 0; i < N; ++i) { - BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4); + BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4); } }