comparison tests/TestPhaseVocoder.cpp @ 337:df6ee7f3e3db

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