# HG changeset patch # User Chris Cannam # Date 1434378957 -3600 # Node ID 0c351e061945777946aa58db948be451cdeccabe # Parent 329ddaf7415d9469c3ff957d45defd2f200c82e3 More tests diff -r 329ddaf7415d -r 0c351e061945 data/model/test/TestFFTModel.h --- a/data/model/test/TestFFTModel.h Mon Jun 15 14:35:37 2015 +0100 +++ b/data/model/test/TestFFTModel.h Mon Jun 15 15:35:57 2015 +0100 @@ -48,30 +48,43 @@ vector imags(hs1 + 1, 0.f); reals[hs1] = 999.f; // overrun guards imags[hs1] = 999.f; - fftm.getValuesAt(columnNo, &reals[0], &imags[0]); - for (int i = 0; i < hs1; ++i) { - float eRe = expectedValues[ch][i].real(); - float eIm = expectedValues[ch][i].imag(); - float thresh = 1e-5f; - if (abs(reals[i] - eRe) > thresh || - abs(imags[i] - eIm) > thresh) { - cerr << "ERROR: output is not as expected for column " - << i << " in channel " << ch << endl; - cerr << "expected : "; - for (int j = 0; j < hs1; ++j) { - cerr << expectedValues[ch][j] << " "; + for (int stepThrough = 0; stepThrough <= 1; ++stepThrough) { + if (stepThrough) { + // Read through the columns in order instead of + // randomly accessing the one we want. This is to + // exercise the case where the FFT model saves + // part of each input frame and moves along by + // only the non-overlapping distance + for (int sc = 0; sc < columnNo; ++sc) { + fftm.getValuesAt(sc, &reals[0], &imags[0]); } - cerr << "\nactual : "; - for (int j = 0; j < hs1; ++j) { - cerr << complex(reals[j], imags[j]) << " "; + } + fftm.getValuesAt(columnNo, &reals[0], &imags[0]); + for (int i = 0; i < hs1; ++i) { + float eRe = expectedValues[ch][i].real(); + float eIm = expectedValues[ch][i].imag(); + float thresh = 1e-5f; + if (abs(reals[i] - eRe) > thresh || + abs(imags[i] - eIm) > thresh) { + cerr << "ERROR: output is not as expected for column " + << i << " in channel " << ch << " (stepThrough = " + << stepThrough << ")" << endl; + cerr << "expected : "; + for (int j = 0; j < hs1; ++j) { + cerr << expectedValues[ch][j] << " "; + } + cerr << "\nactual : "; + for (int j = 0; j < hs1; ++j) { + cerr << complex(reals[j], imags[j]) << " "; + } + cerr << endl; } - cerr << endl; + COMPARE_FUZZIER_F(reals[i], eRe); + COMPARE_FUZZIER_F(imags[i], eIm); } - COMPARE_FUZZIER_F(reals[i], eRe); - COMPARE_FUZZIER_F(imags[i], eIm); + QCOMPARE(reals[hs1], 999.f); + QCOMPARE(imags[hs1], 999.f); } - QCOMPARE(reals[hs1], 999.f); - QCOMPARE(imags[hs1], 999.f); } } @@ -113,6 +126,18 @@ { { {}, {}, {}, {}, {} } }, 4); } + void dc_simple_hann_halfoverlap() { + MockWaveModel mwm({ DC }, 16, 4); + test(&mwm, HanningWindow, 8, 4, 8, 0, + { { {}, {}, {}, {}, {} } }, 7); + test(&mwm, HanningWindow, 8, 4, 8, 2, + { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); + test(&mwm, HanningWindow, 8, 4, 8, 3, + { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); + test(&mwm, HanningWindow, 8, 4, 8, 6, + { { {}, {}, {}, {}, {} } }, 7); + } + void sine_simple_rect() { MockWaveModel mwm({ Sine }, 16, 4); // Sine: output is purely imaginary. Note the sign is flipped @@ -188,6 +213,18 @@ { { {}, {}, {}, {}, {} } }, 5); } + void dirac_simple_rect_halfoverlap() { + MockWaveModel mwm({ Dirac }, 16, 4); + test(&mwm, RectangularWindow, 8, 4, 8, 0, + { { {}, {}, {}, {}, {} } }, 7); + test(&mwm, RectangularWindow, 8, 4, 8, 1, + { { { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f } } }, 7); + test(&mwm, RectangularWindow, 8, 4, 8, 2, + { { { 0.5f, 0.f }, { -0.5f, 0.f }, { 0.5f, 0.f }, { -0.5f, 0.f }, { 0.5f, 0.f } } }, 7); + test(&mwm, RectangularWindow, 8, 4, 8, 3, + { { {}, {}, {}, {}, {} } }, 7); + } + }; #endif