c@337: c@337: #include "dsp/phasevocoder/PhaseVocoder.h" c@337: c@337: #include "base/Window.h" c@337: c@337: #define BOOST_TEST_DYN_LINK c@337: #define BOOST_TEST_MAIN c@337: c@337: #include c@337: c@337: BOOST_AUTO_TEST_SUITE(TestFFT) c@337: c@337: #define COMPARE_CONST(a, n) \ c@337: for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ c@337: BOOST_CHECK_SMALL(a[cmp_i] - n, 1e-14); \ c@337: } c@337: c@337: #define COMPARE_ARRAY(a, b) \ c@337: for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ c@337: BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-14); \ c@337: } c@337: c@337: #define COMPARE_ARRAY_EXACT(a, b) \ c@337: for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ c@337: BOOST_CHECK_EQUAL(a[cmp_i], b[cmp_i]); \ c@337: } c@337: c@337: BOOST_AUTO_TEST_CASE(fullcycle) c@337: { c@337: // Cosine with one cycle exactly equal to pvoc hopsize. We aren't c@337: // windowing the input frame because (for once) it actually *is* c@337: // just a short part of a continuous infinite sinusoid. c@337: c@337: double frame[] = { 1, 0, -1, 0, 1, 0, -1, 0 }; c@337: c@337: PhaseVocoder pvoc(8); c@337: c@337: // Make these arrays one element too long at each end, so as to c@337: // test for overruns. For frame size 8, we expect 8/2+1 = 5 c@337: // mag/phase pairs. c@337: double mag[] = { 999, 999, 999, 999, 999, 999, 999 }; c@337: double phase[] = { 999, 999, 999, 999, 999, 999, 999 }; c@337: c@337: pvoc.process(frame, mag + 1, phase + 1); c@337: c@337: double magExpected0[] = { 999, 0, 0, 4, 0, 0, 999 }; c@337: COMPARE_ARRAY_EXACT(mag, magExpected0); c@337: c@337: double phaseExpected0[] = { 999, 0, 0, 0, 0, 0, 999 }; c@337: COMPARE_ARRAY_EXACT(phase, phaseExpected0); c@337: c@337: pvoc.process(frame, mag + 1, phase + 1); c@337: c@337: double magExpected1[] = { 999, 0, 0, 4, 0, 0, 999 }; c@337: COMPARE_ARRAY_EXACT(mag, magExpected1); c@337: c@337: double phaseExpected1[] = { 999, 0, 0, 2 * M_PI, 0, 0, 999 }; c@337: COMPARE_ARRAY(phase, phaseExpected1); c@338: c@338: pvoc.process(frame, mag + 1, phase + 1); c@338: c@338: double magExpected2[] = { 999, 0, 0, 4, 0, 0, 999 }; c@338: COMPARE_ARRAY_EXACT(mag, magExpected2); c@338: c@338: double phaseExpected2[] = { 999, 0, 0, 4 * M_PI, 0, 0, 999 }; c@338: COMPARE_ARRAY(phase, phaseExpected2); c@337: } c@337: c@337: BOOST_AUTO_TEST_SUITE_END() c@337: