Mercurial > hg > svcore
changeset 1099:0c351e061945 simple-fft-model
More tests
author | Chris Cannam |
---|---|
date | Mon, 15 Jun 2015 15:35:57 +0100 |
parents | 329ddaf7415d |
children | 5cbf71022679 |
files | data/model/test/TestFFTModel.h |
diffstat | 1 files changed, 57 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- 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<float> 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<float>(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<float>(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