Mercurial > hg > svgui
comparison widgets/WindowShapePreview.cpp @ 202:cec1f78fbfca
* Add non-fftw3 fft alternative
author | Chris Cannam |
---|---|
date | Fri, 09 Feb 2007 11:32:34 +0000 |
parents | 5ec6b60658d8 |
children | be5c35d3f409 |
comparison
equal
deleted
inserted
replaced
201:1ab31723825d | 202:cec1f78fbfca |
---|---|
20 #include <QPainter> | 20 #include <QPainter> |
21 #include <QPainterPath> | 21 #include <QPainterPath> |
22 #include <QFont> | 22 #include <QFont> |
23 #include <QString> | 23 #include <QString> |
24 | 24 |
25 #include <fftw3.h> | 25 #include "data/fft/FFTapi.h" |
26 | 26 |
27 #include <iostream> | 27 #include <iostream> |
28 | 28 |
29 WindowShapePreview::WindowShapePreview(QWidget *parent) : | 29 WindowShapePreview::WindowShapePreview(QWidget *parent) : |
30 QFrame(parent), | 30 QFrame(parent), |
119 QPainter freqPainter(&freqLabel); | 119 QPainter freqPainter(&freqLabel); |
120 path = QPainterPath(); | 120 path = QPainterPath(); |
121 | 121 |
122 int fftsize = 512; | 122 int fftsize = 512; |
123 | 123 |
124 float *input = (float *)fftwf_malloc(fftsize * sizeof(float)); | 124 float *input = (float *)fftf_malloc(fftsize * sizeof(float)); |
125 fftwf_complex *output = | 125 fftf_complex *output = |
126 (fftwf_complex *)fftwf_malloc(fftsize * sizeof(fftwf_complex)); | 126 (fftf_complex *)fftf_malloc(fftsize * sizeof(fftf_complex)); |
127 fftwf_plan plan = fftwf_plan_dft_r2c_1d(fftsize, input, output, | 127 fftf_plan plan = fftf_plan_dft_r2c_1d(fftsize, input, output, |
128 FFTW_ESTIMATE); | 128 FFTW_ESTIMATE); |
129 for (int i = 0; i < fftsize; ++i) input[i] = 0.f; | 129 for (int i = 0; i < fftsize; ++i) input[i] = 0.f; |
130 for (int i = 0; i < step * 2; ++i) { | 130 for (int i = 0; i < step * 2; ++i) { |
131 input[fftsize/2 - step + i] = windower.getValue(i); | 131 input[fftsize/2 - step + i] = windower.getValue(i); |
132 } | 132 } |
133 | 133 |
134 fftwf_execute(plan); | 134 fftf_execute(plan); |
135 fftwf_destroy_plan(plan); | 135 fftf_destroy_plan(plan); |
136 | 136 |
137 float maxdb = 0.f; | 137 float maxdb = 0.f; |
138 float mindb = 0.f; | 138 float mindb = 0.f; |
139 bool first = true; | 139 bool first = true; |
140 for (int i = 0; i < fftsize/2; ++i) { | 140 for (int i = 0; i < fftsize/2; ++i) { |
184 | 184 |
185 freqPainter.setRenderHint(QPainter::Antialiasing, true); | 185 freqPainter.setRenderHint(QPainter::Antialiasing, true); |
186 path.addRect(0, 0, fw, h + 1); | 186 path.addRect(0, 0, fw, h + 1); |
187 freqPainter.drawPath(path); | 187 freqPainter.drawPath(path); |
188 | 188 |
189 fftwf_free(input); | 189 fftf_free(input); |
190 fftwf_free(output); | 190 fftf_free(output); |
191 | 191 |
192 freqPainter.setFont(font); | 192 freqPainter.setFont(font); |
193 label = tr("dB / freq"); | 193 label = tr("dB / freq"); |
194 freqPainter.drawText(fw - freqPainter.fontMetrics().width(label) - 4, | 194 freqPainter.drawText(fw - freqPainter.fontMetrics().width(label) - 4, |
195 freqPainter.fontMetrics().ascent() + 1, label); | 195 freqPainter.fontMetrics().ascent() + 1, label); |