Mercurial > hg > qm-dsp
comparison 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 |
comparison
equal
deleted
inserted
replaced
362:3953f3ef1b62 | 363:2fe2ab316c8e |
---|---|
13 | 13 |
14 BOOST_AUTO_TEST_SUITE(TestResampler) | 14 BOOST_AUTO_TEST_SUITE(TestResampler) |
15 | 15 |
16 using std::cout; | 16 using std::cout; |
17 using std::endl; | 17 using std::endl; |
18 using std::vector; | |
19 | |
20 void | |
21 testResamplerOneShot(int sourceRate, | |
22 int targetRate, | |
23 int n, | |
24 double *in, | |
25 int m, | |
26 double *expected) | |
27 { | |
28 vector<double> resampled = Resampler::resample(sourceRate, targetRate, | |
29 in, n); | |
30 BOOST_CHECK_EQUAL(resampled.size(), m); | |
31 for (int i = 0; i < m; ++i) { | |
32 BOOST_CHECK_SMALL(resampled[i] - expected[i], 1e-8); | |
33 } | |
34 } | |
18 | 35 |
19 void | 36 void |
20 testResampler(int sourceRate, | 37 testResampler(int sourceRate, |
21 int targetRate, | 38 int targetRate, |
22 int n, | 39 int n, |
23 double *in, | 40 double *in, |
24 int m, | 41 int m, |
25 double *expected) | 42 double *expected) |
26 { | 43 { |
44 //!!! to be useful, this should provide the input in varying-size chunks | |
45 | |
27 Resampler r(sourceRate, targetRate); | 46 Resampler r(sourceRate, targetRate); |
28 int latency = r.getLatency(); | 47 int latency = r.getLatency(); |
29 std::cerr << "latency = " << latency << std::endl; | 48 std::cerr << "latency = " << latency << std::endl; |
30 | 49 |
31 int m1 = m + latency; | 50 int m1 = m + latency; |
55 if (i % 6 == 5) std::cerr << "\n"; | 74 if (i % 6 == 5) std::cerr << "\n"; |
56 } | 75 } |
57 std::cerr << "\n"; | 76 std::cerr << "\n"; |
58 | 77 |
59 for (int i = latency; i < m1; ++i) { | 78 for (int i = latency; i < m1; ++i) { |
60 BOOST_CHECK_CLOSE(outPadded[i], expected[i-latency], 1e-8); | 79 BOOST_CHECK_SMALL(outPadded[i] - expected[i-latency], 1e-8); |
61 } | 80 } |
62 delete[] outPadded; | 81 delete[] outPadded; |
63 delete[] inPadded; | 82 delete[] inPadded; |
64 } | 83 } |
65 | 84 |
66 BOOST_AUTO_TEST_CASE(sameRate) | 85 BOOST_AUTO_TEST_CASE(sameRate) |
67 { | 86 { |
68 double d[] = { 0, 0.1, -0.3, -0.4, -0.3, 0, 0.5, 0.2, 0.8, -0.1 }; | 87 double d[] = { 0, 0.1, -0.3, -0.4, -0.3, 0, 0.5, 0.2, 0.8, -0.1 }; |
88 testResamplerOneShot(4, 4, 10, d, 10, d); | |
69 testResampler(4, 4, 10, d, 10, d); | 89 testResampler(4, 4, 10, d, 10, d); |
70 } | 90 } |
71 | 91 |
72 BOOST_AUTO_TEST_SUITE_END() | 92 BOOST_AUTO_TEST_SUITE_END() |
73 | 93 |