Mercurial > hg > svgui
changeset 1169:b5c88c448ca2 3.0-integration
Merge from branch bqfft
author | Chris Cannam |
---|---|
date | Mon, 21 Nov 2016 15:33:08 +0000 |
parents | 236ecb2c0758 (current diff) 6796afa25c88 (diff) |
children | 958e352919a5 |
files | |
diffstat | 1 files changed, 18 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/widgets/WindowShapePreview.cpp Thu Nov 17 17:47:10 2016 +0000 +++ b/widgets/WindowShapePreview.cpp Mon Nov 21 15:33:08 2016 +0000 @@ -22,10 +22,14 @@ #include <QFont> #include <QString> -#include "data/fft/FFTapi.h" +#include <bqfft/FFT.h> +#include <vector> +#include <complex> #include <iostream> +using namespace std; + WindowShapePreview::WindowShapePreview(QWidget *parent) : QFrame(parent), @@ -126,24 +130,25 @@ int fftsize = 512; - float *input = (float *)fftf_malloc(fftsize * sizeof(float)); - fftf_complex *output = - (fftf_complex *)fftf_malloc(fftsize * sizeof(fftf_complex)); - fftf_plan plan = fftf_plan_dft_r2c_1d(fftsize, input, output, - FFTW_ESTIMATE); + breakfastquay::FFT fft(fftsize); + + vector<float> input(fftsize); + vector<complex<float>> output(fftsize/2 + 1); + for (int i = 0; i < fftsize; ++i) input[i] = 0.f; for (int i = 0; i < step * 2; ++i) { input[fftsize/2 - step + i] = windower.getValue(i); } - - fftf_execute(plan); - fftf_destroy_plan(plan); + + fft.forwardInterleaved(input.data(), reinterpret_cast<float *>(output.data())); float maxdb = 0.f; float mindb = 0.f; bool first = true; for (int i = 0; i < fftsize/2; ++i) { - float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; + float power = + output[i].real() * output[i].real() + + output[i].imag() * output[i].imag(); float db = mindb; if (power > 0) { db = 20.f * log10f(power); @@ -176,7 +181,9 @@ // cerr << "maxdb = " << maxdb << ", mindb = " << mindb << ", maxval = " <<maxval << endl; for (int i = 0; i < fftsize/2; ++i) { - float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; + float power = + output[i].real() * output[i].real() + + output[i].imag() * output[i].imag(); float db = 20.f * log10f(power); float val = db + -mindb; if (val < 0) val = 0; @@ -191,9 +198,6 @@ path.addRect(0, 0, w, h + 1); freqPainter.drawPath(path); - fftf_free(input); - fftf_free(output); - freqPainter.setFont(font); label = tr("dB / freq"); freqPainter.drawText(w - freqPainter.fontMetrics().width(label) - 4,