c@362
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@362
|
2
|
c@362
|
3 #include "Resampler.h"
|
c@362
|
4
|
c@362
|
5 #include <iostream>
|
c@362
|
6
|
c@362
|
7 #include <cmath>
|
c@362
|
8
|
c@362
|
9 #define BOOST_TEST_DYN_LINK
|
c@362
|
10 #define BOOST_TEST_MAIN
|
c@362
|
11
|
c@362
|
12 #include <boost/test/unit_test.hpp>
|
c@362
|
13
|
c@362
|
14 BOOST_AUTO_TEST_SUITE(TestResampler)
|
c@362
|
15
|
c@362
|
16 using std::cout;
|
c@362
|
17 using std::endl;
|
c@363
|
18 using std::vector;
|
c@363
|
19
|
c@363
|
20 void
|
c@363
|
21 testResamplerOneShot(int sourceRate,
|
c@363
|
22 int targetRate,
|
c@363
|
23 int n,
|
c@363
|
24 double *in,
|
c@363
|
25 int m,
|
c@363
|
26 double *expected)
|
c@363
|
27 {
|
c@363
|
28 vector<double> resampled = Resampler::resample(sourceRate, targetRate,
|
c@363
|
29 in, n);
|
c@363
|
30 BOOST_CHECK_EQUAL(resampled.size(), m);
|
c@363
|
31 for (int i = 0; i < m; ++i) {
|
c@363
|
32 BOOST_CHECK_SMALL(resampled[i] - expected[i], 1e-8);
|
c@363
|
33 }
|
c@363
|
34 }
|
c@362
|
35
|
c@362
|
36 void
|
c@362
|
37 testResampler(int sourceRate,
|
c@362
|
38 int targetRate,
|
c@362
|
39 int n,
|
c@362
|
40 double *in,
|
c@362
|
41 int m,
|
c@362
|
42 double *expected)
|
c@362
|
43 {
|
c@363
|
44 //!!! to be useful, this should provide the input in varying-size chunks
|
c@363
|
45
|
c@362
|
46 Resampler r(sourceRate, targetRate);
|
c@362
|
47 int latency = r.getLatency();
|
c@362
|
48 std::cerr << "latency = " << latency << std::endl;
|
c@362
|
49
|
c@362
|
50 int m1 = m + latency;
|
c@362
|
51 int n1 = int((m1 * sourceRate) / targetRate);
|
c@362
|
52
|
c@362
|
53 double *inPadded = new double[n1];
|
c@362
|
54 double *outPadded = new double[m1];
|
c@362
|
55
|
c@362
|
56 for (int i = 0; i < n1; ++i) {
|
c@362
|
57 if (i < n) inPadded[i] = in[i];
|
c@362
|
58 else inPadded[i] = 0.0;
|
c@362
|
59 }
|
c@362
|
60
|
c@362
|
61 for (int i = 0; i < m1; ++i) {
|
c@362
|
62 outPadded[i] = -999.0;
|
c@362
|
63 }
|
c@362
|
64
|
c@362
|
65 int got = r.process(inPadded, outPadded, n1);
|
c@362
|
66
|
c@362
|
67 std::cerr << n1 << " in, " << got << " out" << std::endl;
|
c@362
|
68
|
c@362
|
69 BOOST_CHECK_EQUAL(got, m1);
|
c@362
|
70
|
c@362
|
71 std::cerr << "results including latency padding:" << std::endl;
|
c@362
|
72 for (int i = 0; i < m1; ++i) {
|
c@362
|
73 std::cerr << outPadded[i] << " ";
|
c@362
|
74 if (i % 6 == 5) std::cerr << "\n";
|
c@362
|
75 }
|
c@362
|
76 std::cerr << "\n";
|
c@362
|
77
|
c@362
|
78 for (int i = latency; i < m1; ++i) {
|
c@363
|
79 BOOST_CHECK_SMALL(outPadded[i] - expected[i-latency], 1e-8);
|
c@362
|
80 }
|
c@362
|
81 delete[] outPadded;
|
c@362
|
82 delete[] inPadded;
|
c@362
|
83 }
|
c@362
|
84
|
c@362
|
85 BOOST_AUTO_TEST_CASE(sameRate)
|
c@362
|
86 {
|
c@362
|
87 double d[] = { 0, 0.1, -0.3, -0.4, -0.3, 0, 0.5, 0.2, 0.8, -0.1 };
|
c@363
|
88 testResamplerOneShot(4, 4, 10, d, 10, d);
|
c@362
|
89 testResampler(4, 4, 10, d, 10, d);
|
c@362
|
90 }
|
c@362
|
91
|
c@362
|
92 BOOST_AUTO_TEST_SUITE_END()
|
c@362
|
93
|