comparison widgets/WindowShapePreview.cpp @ 908:4a578a360011 cxx11

More type fixes
author Chris Cannam
date Tue, 10 Mar 2015 13:22:10 +0000
parents 1a0dfcbffaf1
children 6645b6b8356f
comparison
equal deleted inserted replaced
907:28d05ae8741c 908:4a578a360011
30 #include <alloca.h> 30 #include <alloca.h>
31 #endif 31 #endif
32 32
33 WindowShapePreview::WindowShapePreview(QWidget *parent) : 33 WindowShapePreview::WindowShapePreview(QWidget *parent) :
34 QFrame(parent), 34 QFrame(parent),
35 m_windowType(WindowType(999)) 35 m_windowType(HanningWindow)
36 { 36 {
37 QHBoxLayout *layout = new QHBoxLayout; 37 QHBoxLayout *layout = new QHBoxLayout;
38 layout->setMargin(0); 38 layout->setMargin(0);
39 setLayout(layout); 39 setLayout(layout);
40 m_windowTimeExampleLabel = new QLabel; 40 m_windowTimeExampleLabel = new QLabel;
49 49
50 void 50 void
51 WindowShapePreview::updateLabels() 51 WindowShapePreview::updateLabels()
52 { 52 {
53 int step = 24; 53 int step = 24;
54 int peak = 48; 54 float peak = 48;
55 int w = step * 4, h = 64; 55 int w = step * 4, h = 64;
56 WindowType type = m_windowType; 56 WindowType type = m_windowType;
57 Window<float> windower = Window<float>(type, step * 2); 57 Window<float> windower = Window<float>(type, step * 2);
58 58
59 QPixmap timeLabel(w, h + 1); 59 QPixmap timeLabel(w, h + 1);
60 timeLabel.fill(Qt::white); 60 timeLabel.fill(Qt::white);
61 QPainter timePainter(&timeLabel); 61 QPainter timePainter(&timeLabel);
62 62
63 QPainterPath path; 63 QPainterPath path;
64 64
65 path.moveTo(0, h - peak + 1); 65 path.moveTo(0, float(h) - peak + 1);
66 path.lineTo(w, h - peak + 1); 66 path.lineTo(w, float(h) - peak + 1);
67 67
68 timePainter.setPen(Qt::gray); 68 timePainter.setPen(Qt::gray);
69 timePainter.setRenderHint(QPainter::Antialiasing, true); 69 timePainter.setRenderHint(QPainter::Antialiasing, true);
70 timePainter.drawPath(path); 70 timePainter.drawPath(path);
71 71
82 for (int i = 0; i < step * 2; ++i) { 82 for (int i = 0; i < step * 2; ++i) {
83 acc[j * step + i] += windower.getValue(i); 83 acc[j * step + i] += windower.getValue(i);
84 } 84 }
85 } 85 }
86 for (int i = 0; i < w; ++i) { 86 for (int i = 0; i < w; ++i) {
87 int y = h - int(peak * acc[i] + 0.001) + 1; 87 int y = h - int(peak * acc[i] + 0.001f) + 1;
88 if (i == 0) path.moveTo(i, y); 88 if (i == 0) path.moveTo(i, y);
89 else path.lineTo(i, y); 89 else path.lineTo(i, y);
90 } 90 }
91 91
92 timePainter.drawPath(path); 92 timePainter.drawPath(path);
148 bool first = true; 148 bool first = true;
149 for (int i = 0; i < fftsize/2; ++i) { 149 for (int i = 0; i < fftsize/2; ++i) {
150 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; 150 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1];
151 float db = mindb; 151 float db = mindb;
152 if (power > 0) { 152 if (power > 0) {
153 db = 20 * log10(power); 153 db = 20.f * log10f(power);
154 if (first || db > maxdb) maxdb = db; 154 if (first || db > maxdb) maxdb = db;
155 if (first || db < mindb) mindb = db; 155 if (first || db < mindb) mindb = db;
156 first = false; 156 first = false;
157 } 157 }
158 } 158 }
165 165
166 float maxval = maxdb + -mindb; 166 float maxval = maxdb + -mindb;
167 167
168 // float ly = h - ((-80.f + -mindb) / maxval) * peak + 1; 168 // float ly = h - ((-80.f + -mindb) / maxval) * peak + 1;
169 169
170 path.moveTo(0, h - peak + 1); 170 path.moveTo(0, float(h) - peak + 1);
171 path.lineTo(fw, h - peak + 1); 171 path.lineTo(fw, float(h) - peak + 1);
172 172
173 freqPainter.setPen(Qt::gray); 173 freqPainter.setPen(Qt::gray);
174 freqPainter.setRenderHint(QPainter::Antialiasing, true); 174 freqPainter.setRenderHint(QPainter::Antialiasing, true);
175 freqPainter.drawPath(path); 175 freqPainter.drawPath(path);
176 176
179 179
180 // cerr << "maxdb = " << maxdb << ", mindb = " << mindb << ", maxval = " <<maxval << endl; 180 // cerr << "maxdb = " << maxdb << ", mindb = " << mindb << ", maxval = " <<maxval << endl;
181 181
182 for (int i = 0; i < fftsize/2; ++i) { 182 for (int i = 0; i < fftsize/2; ++i) {
183 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; 183 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1];
184 float db = 20 * log10(power); 184 float db = 20.f * log10f(power);
185 float val = db + -mindb; 185 float val = db + -mindb;
186 if (val < 0) val = 0; 186 if (val < 0) val = 0;
187 float norm = val / maxval; 187 float norm = val / maxval;
188 float x = (fw / float(fftsize/2)) * i; 188 float x = (float(fw) / float(fftsize/2)) * float(i);
189 float y = h - norm * peak + 1; 189 float y = float(h) - norm * peak + 1;
190 if (i == 0) path.moveTo(x, y); 190 if (i == 0) path.moveTo(x, y);
191 else path.lineTo(x, y); 191 else path.lineTo(x, y);
192 } 192 }
193 193
194 freqPainter.setRenderHint(QPainter::Antialiasing, true); 194 freqPainter.setRenderHint(QPainter::Antialiasing, true);