Mercurial > hg > svcore
diff data/model/test/TestFFTModel.h @ 1744:b92bdcd4954b by-id
Update FFT model to ById
author | Chris Cannam |
---|---|
date | Tue, 02 Jul 2019 11:49:28 +0100 |
parents | 0e9840a381b5 |
children | 6d09d68165a4 |
line wrap: on
line diff
--- a/data/model/test/TestFFTModel.h Mon Jul 01 14:16:12 2019 +0100 +++ b/data/model/test/TestFFTModel.h Tue Jul 02 11:49:28 2019 +0100 @@ -35,7 +35,7 @@ Q_OBJECT private: - void test(DenseTimeValueModel *model, + void test(ModelId model, // a DenseTimeValueModel WindowType window, int windowSize, int windowIncrement, int fftSize, int columnNo, vector<vector<complex<float>>> expectedValues, int expectedWidth) { @@ -88,6 +88,16 @@ } } + ModelId makeMock(std::vector<Sort> sorts, int length, int pad) { + auto mwm = std::make_shared<MockWaveModel>(sorts, length, pad); + ModelById::add(mwm); + return mwm->getId(); + } + + void releaseMock(ModelId id) { + ModelById::release(id); + } + private slots: // NB. FFTModel columns are centred on the sample frame, and in @@ -101,153 +111,163 @@ // are those of our expected signal. void dc_simple_rect() { - MockWaveModel mwm({ DC }, 16, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 0, + auto mwm = makeMock({ DC }, 16, 4); + test(mwm, RectangularWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 1, + test(mwm, RectangularWindow, 8, 8, 8, 1, { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 2, + test(mwm, RectangularWindow, 8, 8, 8, 2, { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 3, + test(mwm, RectangularWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} } }, 4); + releaseMock(mwm); } void dc_simple_hann() { // The Hann window function is a simple sinusoid with period // equal to twice the window size, and it halves the DC energy - MockWaveModel mwm({ DC }, 16, 4); - test(&mwm, HanningWindow, 8, 8, 8, 0, + auto mwm = makeMock({ DC }, 16, 4); + test(mwm, HanningWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} } }, 4); - test(&mwm, HanningWindow, 8, 8, 8, 1, + test(mwm, HanningWindow, 8, 8, 8, 1, { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); - test(&mwm, HanningWindow, 8, 8, 8, 2, + test(mwm, HanningWindow, 8, 8, 8, 2, { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); - test(&mwm, HanningWindow, 8, 8, 8, 3, + test(mwm, HanningWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} } }, 4); + releaseMock(mwm); } void dc_simple_hann_halfoverlap() { - MockWaveModel mwm({ DC }, 16, 4); - test(&mwm, HanningWindow, 8, 4, 8, 0, + auto mwm = makeMock({ DC }, 16, 4); + test(mwm, HanningWindow, 8, 4, 8, 0, { { {}, {}, {}, {}, {} } }, 7); - test(&mwm, HanningWindow, 8, 4, 8, 2, + test(mwm, HanningWindow, 8, 4, 8, 2, { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); - test(&mwm, HanningWindow, 8, 4, 8, 3, + test(mwm, HanningWindow, 8, 4, 8, 3, { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); - test(&mwm, HanningWindow, 8, 4, 8, 6, + test(mwm, HanningWindow, 8, 4, 8, 6, { { {}, {}, {}, {}, {} } }, 7); + releaseMock(mwm); } void sine_simple_rect() { - MockWaveModel mwm({ Sine }, 16, 4); + auto mwm = makeMock({ Sine }, 16, 4); // Sine: output is purely imaginary. Note the sign is flipped // (normally the first half of the output would have negative // sign for a sine starting at 0) because the model does an // FFT shift to centre the phase - test(&mwm, RectangularWindow, 8, 8, 8, 0, + test(mwm, RectangularWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 1, + test(mwm, RectangularWindow, 8, 8, 8, 1, { { {}, { 0.f, 2.f }, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 2, + test(mwm, RectangularWindow, 8, 8, 8, 2, { { {}, { 0.f, 2.f }, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 3, + test(mwm, RectangularWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} } }, 4); + releaseMock(mwm); } void cosine_simple_rect() { - MockWaveModel mwm({ Cosine }, 16, 4); + auto mwm = makeMock({ Cosine }, 16, 4); // Cosine: output is purely real. Note the sign is flipped // because the model does an FFT shift to centre the phase - test(&mwm, RectangularWindow, 8, 8, 8, 0, + test(mwm, RectangularWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 1, + test(mwm, RectangularWindow, 8, 8, 8, 1, { { {}, { -2.f, 0.f }, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 2, + test(mwm, RectangularWindow, 8, 8, 8, 2, { { {}, { -2.f, 0.f }, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 3, + test(mwm, RectangularWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} } }, 4); + releaseMock(mwm); } void twochan_simple_rect() { - MockWaveModel mwm({ Sine, Cosine }, 16, 4); + auto mwm = makeMock({ Sine, Cosine }, 16, 4); // Test that the two channels are read and converted separately - test(&mwm, RectangularWindow, 8, 8, 8, 0, + test(mwm, RectangularWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} }, { {}, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 1, + test(mwm, RectangularWindow, 8, 8, 8, 1, { { {}, { 0.f, 2.f }, {}, {}, {} }, { {}, { -2.f, 0.f }, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 2, + test(mwm, RectangularWindow, 8, 8, 8, 2, { { {}, { 0.f, 2.f }, {}, {}, {} }, { {}, { -2.f, 0.f }, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 3, + test(mwm, RectangularWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} }, { {}, {}, {}, {}, {} } }, 4); + releaseMock(mwm); } void nyquist_simple_rect() { - MockWaveModel mwm({ Nyquist }, 16, 4); + auto mwm = makeMock({ Nyquist }, 16, 4); // Again, the sign is flipped. This has the same amount of // energy as the DC example - test(&mwm, RectangularWindow, 8, 8, 8, 0, + test(mwm, RectangularWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 1, + test(mwm, RectangularWindow, 8, 8, 8, 1, { { {}, {}, {}, {}, { -4.f, 0.f } } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 2, + test(mwm, RectangularWindow, 8, 8, 8, 2, { { {}, {}, {}, {}, { -4.f, 0.f } } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 3, + test(mwm, RectangularWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} } }, 4); + releaseMock(mwm); } void dirac_simple_rect() { - MockWaveModel mwm({ Dirac }, 16, 4); + auto mwm = makeMock({ Dirac }, 16, 4); // The window scales by 0.5 and some signs are flipped. Only // column 1 has any data (the single impulse). - test(&mwm, RectangularWindow, 8, 8, 8, 0, + test(mwm, RectangularWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 1, + test(mwm, RectangularWindow, 8, 8, 8, 1, { { { 0.5f, 0.f }, { -0.5f, 0.f }, { 0.5f, 0.f }, { -0.5f, 0.f }, { 0.5f, 0.f } } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 2, + test(mwm, RectangularWindow, 8, 8, 8, 2, { { {}, {}, {}, {}, {} } }, 4); - test(&mwm, RectangularWindow, 8, 8, 8, 3, + test(mwm, RectangularWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} } }, 4); + releaseMock(mwm); } void dirac_simple_rect_2() { - MockWaveModel mwm({ Dirac }, 16, 8); + auto mwm = makeMock({ Dirac }, 16, 8); // With 8 samples padding, the FFT shift places the first // Dirac impulse at the start of column 1, thus giving all // positive values - test(&mwm, RectangularWindow, 8, 8, 8, 0, + test(mwm, RectangularWindow, 8, 8, 8, 0, { { {}, {}, {}, {}, {} } }, 5); - test(&mwm, RectangularWindow, 8, 8, 8, 1, + test(mwm, RectangularWindow, 8, 8, 8, 1, { { { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f } } }, 5); - test(&mwm, RectangularWindow, 8, 8, 8, 2, + test(mwm, RectangularWindow, 8, 8, 8, 2, { { {}, {}, {}, {}, {} } }, 5); - test(&mwm, RectangularWindow, 8, 8, 8, 3, + test(mwm, RectangularWindow, 8, 8, 8, 3, { { {}, {}, {}, {}, {} } }, 5); - test(&mwm, RectangularWindow, 8, 8, 8, 4, + test(mwm, RectangularWindow, 8, 8, 8, 4, { { {}, {}, {}, {}, {} } }, 5); + releaseMock(mwm); } void dirac_simple_rect_halfoverlap() { - MockWaveModel mwm({ Dirac }, 16, 4); - test(&mwm, RectangularWindow, 8, 4, 8, 0, + auto mwm = makeMock({ Dirac }, 16, 4); + test(mwm, RectangularWindow, 8, 4, 8, 0, { { {}, {}, {}, {}, {} } }, 7); - test(&mwm, RectangularWindow, 8, 4, 8, 1, + 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, + 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, + test(mwm, RectangularWindow, 8, 4, 8, 3, { { {}, {}, {}, {}, {} } }, 7); + releaseMock(mwm); } };