c@337
|
1
|
c@337
|
2 #include "dsp/phasevocoder/PhaseVocoder.h"
|
c@337
|
3
|
c@337
|
4 #include "base/Window.h"
|
c@337
|
5
|
c@337
|
6 #define BOOST_TEST_DYN_LINK
|
c@337
|
7 #define BOOST_TEST_MAIN
|
c@337
|
8
|
c@337
|
9 #include <boost/test/unit_test.hpp>
|
c@337
|
10
|
c@337
|
11 BOOST_AUTO_TEST_SUITE(TestFFT)
|
c@337
|
12
|
c@337
|
13 #define COMPARE_CONST(a, n) \
|
c@337
|
14 for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \
|
c@337
|
15 BOOST_CHECK_SMALL(a[cmp_i] - n, 1e-14); \
|
c@337
|
16 }
|
c@337
|
17
|
c@337
|
18 #define COMPARE_ARRAY(a, b) \
|
c@337
|
19 for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \
|
c@337
|
20 BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-14); \
|
c@337
|
21 }
|
c@337
|
22
|
c@337
|
23 #define COMPARE_ARRAY_EXACT(a, b) \
|
c@337
|
24 for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \
|
c@337
|
25 BOOST_CHECK_EQUAL(a[cmp_i], b[cmp_i]); \
|
c@337
|
26 }
|
c@337
|
27
|
c@337
|
28 BOOST_AUTO_TEST_CASE(fullcycle)
|
c@337
|
29 {
|
c@337
|
30 // Cosine with one cycle exactly equal to pvoc hopsize. We aren't
|
c@337
|
31 // windowing the input frame because (for once) it actually *is*
|
c@337
|
32 // just a short part of a continuous infinite sinusoid.
|
c@337
|
33
|
c@337
|
34 double frame[] = { 1, 0, -1, 0, 1, 0, -1, 0 };
|
c@337
|
35
|
c@337
|
36 PhaseVocoder pvoc(8);
|
c@337
|
37
|
c@337
|
38 // Make these arrays one element too long at each end, so as to
|
c@337
|
39 // test for overruns. For frame size 8, we expect 8/2+1 = 5
|
c@337
|
40 // mag/phase pairs.
|
c@337
|
41 double mag[] = { 999, 999, 999, 999, 999, 999, 999 };
|
c@337
|
42 double phase[] = { 999, 999, 999, 999, 999, 999, 999 };
|
c@337
|
43
|
c@337
|
44 pvoc.process(frame, mag + 1, phase + 1);
|
c@337
|
45
|
c@337
|
46 double magExpected0[] = { 999, 0, 0, 4, 0, 0, 999 };
|
c@337
|
47 COMPARE_ARRAY_EXACT(mag, magExpected0);
|
c@337
|
48
|
c@337
|
49 double phaseExpected0[] = { 999, 0, 0, 0, 0, 0, 999 };
|
c@337
|
50 COMPARE_ARRAY_EXACT(phase, phaseExpected0);
|
c@337
|
51
|
c@337
|
52 pvoc.process(frame, mag + 1, phase + 1);
|
c@337
|
53
|
c@337
|
54 double magExpected1[] = { 999, 0, 0, 4, 0, 0, 999 };
|
c@337
|
55 COMPARE_ARRAY_EXACT(mag, magExpected1);
|
c@337
|
56
|
c@337
|
57 double phaseExpected1[] = { 999, 0, 0, 2 * M_PI, 0, 0, 999 };
|
c@337
|
58 COMPARE_ARRAY(phase, phaseExpected1);
|
c@337
|
59 }
|
c@337
|
60
|
c@337
|
61 BOOST_AUTO_TEST_SUITE_END()
|
c@337
|
62
|