annotate layer/SpectrumLayer.cpp @ 275:bbe57afe9d7d

* avoid trying to calculate fft from incomplete decoded audio file in spectrum
author Chris Cannam
date Mon, 02 Jul 2007 14:57:01 +0000
parents b9380f679f70
children 8acd30ed735c
rev   line source
Chris@133 1
Chris@133 2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@133 3
Chris@133 4 /*
Chris@133 5 Sonic Visualiser
Chris@133 6 An audio file viewer and annotation editor.
Chris@133 7 Centre for Digital Music, Queen Mary, University of London.
Chris@195 8 This file copyright 2006-2007 QMUL.
Chris@133 9
Chris@133 10 This program is free software; you can redistribute it and/or
Chris@133 11 modify it under the terms of the GNU General Public License as
Chris@133 12 published by the Free Software Foundation; either version 2 of the
Chris@133 13 License, or (at your option) any later version. See the file
Chris@133 14 COPYING included with this distribution for more information.
Chris@133 15 */
Chris@133 16
Chris@133 17 #include "SpectrumLayer.h"
Chris@133 18
Chris@133 19 #include "data/model/FFTModel.h"
Chris@133 20 #include "view/View.h"
Chris@153 21 #include "base/AudioLevel.h"
Chris@153 22 #include "base/Preferences.h"
Chris@167 23 #include "base/RangeMapper.h"
Chris@254 24 #include "ColourMapper.h"
Chris@254 25
Chris@254 26 #include <QPainter>
Chris@133 27
Chris@133 28 SpectrumLayer::SpectrumLayer() :
Chris@193 29 m_originModel(0),
Chris@153 30 m_channel(-1),
Chris@153 31 m_channelSet(false),
Chris@153 32 m_windowSize(1024),
Chris@153 33 m_windowType(HanningWindow),
Chris@275 34 m_windowHopLevel(2),
Chris@275 35 m_newFFTNeeded(true)
Chris@133 36 {
Chris@153 37 Preferences *prefs = Preferences::getInstance();
Chris@153 38 connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@153 39 this, SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@153 40 setWindowType(prefs->getWindowType());
Chris@195 41
Chris@195 42 setBinScale(LogBins);
Chris@133 43 }
Chris@133 44
Chris@133 45 SpectrumLayer::~SpectrumLayer()
Chris@133 46 {
Chris@193 47 //!!! delete parent's model
Chris@193 48 // for (size_t i = 0; i < m_fft.size(); ++i) delete m_fft[i];
Chris@133 49 }
Chris@133 50
Chris@133 51 void
Chris@133 52 SpectrumLayer::setModel(DenseTimeValueModel *model)
Chris@133 53 {
Chris@193 54 if (m_originModel == model) return;
Chris@193 55 m_originModel = model;
Chris@275 56 //!!! setupFFT();
Chris@153 57 }
Chris@153 58
Chris@153 59 void
Chris@193 60 SpectrumLayer::setupFFT()
Chris@153 61 {
Chris@193 62 FFTModel *oldFFT = dynamic_cast<FFTModel *>
Chris@193 63 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
Chris@153 64
Chris@193 65 if (oldFFT) {
Chris@193 66 setSliceableModel(0);
Chris@193 67 delete oldFFT;
Chris@153 68 }
Chris@153 69
Chris@193 70 FFTModel *newFFT = new FFTModel(m_originModel,
Chris@193 71 m_channel,
Chris@193 72 m_windowType,
Chris@193 73 m_windowSize,
Chris@193 74 getWindowIncrement(),
Chris@193 75 m_windowSize,
Chris@193 76 true);
Chris@153 77
Chris@193 78 setSliceableModel(newFFT);
Chris@193 79
Chris@254 80 m_biasCurve.clear();
Chris@254 81 for (size_t i = 0; i < m_windowSize; ++i) {
Chris@254 82 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f));
Chris@254 83 }
Chris@254 84
Chris@193 85 newFFT->resume();
Chris@153 86 }
Chris@153 87
Chris@153 88 void
Chris@153 89 SpectrumLayer::setChannel(int channel)
Chris@153 90 {
Chris@153 91 m_channelSet = true;
Chris@153 92
Chris@193 93 FFTModel *fft = dynamic_cast<FFTModel *>
Chris@193 94 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
Chris@193 95
Chris@153 96 if (m_channel == channel) {
Chris@193 97 if (fft) fft->resume();
Chris@153 98 return;
Chris@153 99 }
Chris@153 100
Chris@153 101 m_channel = channel;
Chris@153 102
Chris@275 103 //!!! if (!fft) setupFFT();
Chris@153 104
Chris@153 105 emit layerParametersChanged();
Chris@133 106 }
Chris@133 107
Chris@153 108 Layer::PropertyList
Chris@153 109 SpectrumLayer::getProperties() const
Chris@153 110 {
Chris@193 111 PropertyList list = SliceLayer::getProperties();
Chris@153 112 list.push_back("Window Size");
Chris@153 113 list.push_back("Window Increment");
Chris@153 114 return list;
Chris@153 115 }
Chris@153 116
Chris@153 117 QString
Chris@153 118 SpectrumLayer::getPropertyLabel(const PropertyName &name) const
Chris@153 119 {
Chris@153 120 if (name == "Window Size") return tr("Window Size");
Chris@153 121 if (name == "Window Increment") return tr("Window Overlap");
Chris@193 122 return SliceLayer::getPropertyLabel(name);
Chris@153 123 }
Chris@153 124
Chris@153 125 Layer::PropertyType
Chris@153 126 SpectrumLayer::getPropertyType(const PropertyName &name) const
Chris@153 127 {
Chris@193 128 if (name == "Window Size") return ValueProperty;
Chris@193 129 if (name == "Window Increment") return ValueProperty;
Chris@193 130 return SliceLayer::getPropertyType(name);
Chris@153 131 }
Chris@153 132
Chris@153 133 QString
Chris@153 134 SpectrumLayer::getPropertyGroupName(const PropertyName &name) const
Chris@153 135 {
Chris@153 136 if (name == "Window Size" ||
Chris@153 137 name == "Window Increment") return tr("Window");
Chris@193 138 return SliceLayer::getPropertyGroupName(name);
Chris@153 139 }
Chris@153 140
Chris@153 141 int
Chris@153 142 SpectrumLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@216 143 int *min, int *max, int *deflt) const
Chris@153 144 {
Chris@216 145 int val = 0;
Chris@153 146
Chris@216 147 int garbage0, garbage1, garbage2;
Chris@153 148 if (!min) min = &garbage0;
Chris@153 149 if (!max) max = &garbage1;
Chris@216 150 if (!deflt) deflt = &garbage2;
Chris@153 151
Chris@193 152 if (name == "Window Size") {
Chris@153 153
Chris@153 154 *min = 0;
Chris@254 155 *max = 15;
Chris@216 156 *deflt = 5;
Chris@153 157
Chris@216 158 val = 0;
Chris@153 159 int ws = m_windowSize;
Chris@216 160 while (ws > 32) { ws >>= 1; val ++; }
Chris@153 161
Chris@153 162 } else if (name == "Window Increment") {
Chris@153 163
Chris@153 164 *min = 0;
Chris@153 165 *max = 5;
Chris@216 166 *deflt = 2;
Chris@153 167
Chris@216 168 val = m_windowHopLevel;
Chris@153 169
Chris@153 170 } else {
Chris@193 171
Chris@216 172 val = SliceLayer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@153 173 }
Chris@153 174
Chris@216 175 return val;
Chris@153 176 }
Chris@153 177
Chris@153 178 QString
Chris@153 179 SpectrumLayer::getPropertyValueLabel(const PropertyName &name,
Chris@153 180 int value) const
Chris@153 181 {
Chris@153 182 if (name == "Window Size") {
Chris@153 183 return QString("%1").arg(32 << value);
Chris@153 184 }
Chris@153 185 if (name == "Window Increment") {
Chris@153 186 switch (value) {
Chris@153 187 default:
Chris@153 188 case 0: return tr("None");
Chris@153 189 case 1: return tr("25 %");
Chris@153 190 case 2: return tr("50 %");
Chris@153 191 case 3: return tr("75 %");
Chris@153 192 case 4: return tr("87.5 %");
Chris@153 193 case 5: return tr("93.75 %");
Chris@153 194 }
Chris@153 195 }
Chris@193 196 return SliceLayer::getPropertyValueLabel(name, value);
Chris@153 197 }
Chris@153 198
Chris@167 199 RangeMapper *
Chris@167 200 SpectrumLayer::getNewPropertyRangeMapper(const PropertyName &name) const
Chris@167 201 {
Chris@193 202 return SliceLayer::getNewPropertyRangeMapper(name);
Chris@167 203 }
Chris@167 204
Chris@133 205 void
Chris@153 206 SpectrumLayer::setProperty(const PropertyName &name, int value)
Chris@133 207 {
Chris@193 208 if (name == "Window Size") {
Chris@153 209 setWindowSize(32 << value);
Chris@153 210 } else if (name == "Window Increment") {
Chris@153 211 setWindowHopLevel(value);
Chris@193 212 } else {
Chris@193 213 SliceLayer::setProperty(name, value);
Chris@153 214 }
Chris@153 215 }
Chris@153 216
Chris@153 217 void
Chris@153 218 SpectrumLayer::setWindowSize(size_t ws)
Chris@153 219 {
Chris@153 220 if (m_windowSize == ws) return;
Chris@153 221 m_windowSize = ws;
Chris@275 222 //!!! setupFFT();
Chris@275 223 m_newFFTNeeded = true;
Chris@153 224 emit layerParametersChanged();
Chris@153 225 }
Chris@153 226
Chris@153 227 void
Chris@153 228 SpectrumLayer::setWindowHopLevel(size_t v)
Chris@153 229 {
Chris@153 230 if (m_windowHopLevel == v) return;
Chris@153 231 m_windowHopLevel = v;
Chris@275 232 //!!! setupFFT();
Chris@275 233 m_newFFTNeeded = true;
Chris@153 234 emit layerParametersChanged();
Chris@153 235 }
Chris@153 236
Chris@153 237 void
Chris@153 238 SpectrumLayer::setWindowType(WindowType w)
Chris@153 239 {
Chris@153 240 if (m_windowType == w) return;
Chris@153 241 m_windowType = w;
Chris@275 242 //!!! setupFFT();
Chris@275 243 m_newFFTNeeded = true;
Chris@153 244 emit layerParametersChanged();
Chris@153 245 }
Chris@153 246
Chris@153 247 void
Chris@153 248 SpectrumLayer::preferenceChanged(PropertyContainer::PropertyName name)
Chris@153 249 {
Chris@153 250 if (name == "Window Type") {
Chris@153 251 setWindowType(Preferences::getInstance()->getWindowType());
Chris@153 252 return;
Chris@153 253 }
Chris@153 254 }
Chris@153 255
Chris@133 256 bool
Chris@248 257 SpectrumLayer::getValueExtents(float &, float &, bool &, QString &) const
Chris@133 258 {
Chris@133 259 return false;
Chris@133 260 }
Chris@133 261
Chris@254 262 float
Chris@265 263 SpectrumLayer::getXForBin(int bin, int totalBins, float w) const
Chris@265 264 {
Chris@265 265 if (!m_sliceableModel) return SliceLayer::getXForBin(bin, totalBins, w);
Chris@265 266
Chris@265 267 float sampleRate = m_sliceableModel->getSampleRate();
Chris@265 268 float binfreq = (sampleRate * bin) / (totalBins * 2);
Chris@265 269
Chris@265 270 return getXForFrequency(binfreq, w);
Chris@265 271 }
Chris@265 272
Chris@265 273 int
Chris@265 274 SpectrumLayer::getBinForX(float x, int totalBins, float w) const
Chris@265 275 {
Chris@265 276 if (!m_sliceableModel) return SliceLayer::getBinForX(x, totalBins, w);
Chris@265 277
Chris@265 278 float sampleRate = m_sliceableModel->getSampleRate();
Chris@265 279 float binfreq = getFrequencyForX(x, w);
Chris@265 280
Chris@265 281 return int((binfreq * totalBins * 2) / sampleRate);
Chris@265 282 }
Chris@265 283
Chris@265 284 float
Chris@254 285 SpectrumLayer::getFrequencyForX(float x, float w) const
Chris@254 286 {
Chris@254 287 float freq = 0;
Chris@254 288
Chris@254 289 int sampleRate = m_sliceableModel->getSampleRate();
Chris@254 290
Chris@254 291 float maxfreq = float(sampleRate) / 2;
Chris@254 292
Chris@254 293 switch (m_binScale) {
Chris@254 294
Chris@254 295 case LinearBins:
Chris@254 296 freq = ((x * maxfreq) / w);
Chris@254 297 break;
Chris@254 298
Chris@254 299 case LogBins:
Chris@254 300 freq = powf(10.f, (x * log10f(maxfreq)) / w);
Chris@254 301 break;
Chris@254 302
Chris@254 303 case InvertedLogBins:
Chris@254 304 freq = maxfreq - powf(10.f, ((w - x) * log10f(maxfreq)) / w);
Chris@254 305 break;
Chris@254 306 }
Chris@254 307
Chris@254 308 return freq;
Chris@254 309 }
Chris@254 310
Chris@254 311 float
Chris@254 312 SpectrumLayer::getXForFrequency(float freq, float w) const
Chris@254 313 {
Chris@254 314 float x = 0;
Chris@254 315
Chris@254 316 int sampleRate = m_sliceableModel->getSampleRate();
Chris@254 317
Chris@254 318 float maxfreq = float(sampleRate) / 2;
Chris@254 319
Chris@254 320 switch (m_binScale) {
Chris@254 321
Chris@254 322 case LinearBins:
Chris@254 323 x = (freq * w) / maxfreq;
Chris@254 324 break;
Chris@254 325
Chris@254 326 case LogBins:
Chris@254 327 x = (log10f(freq) * w) / log10f(maxfreq);
Chris@254 328 break;
Chris@254 329
Chris@254 330 case InvertedLogBins:
Chris@274 331 if (maxfreq == freq) x = w;
Chris@274 332 else x = w - (log10f(maxfreq - freq) * w) / log10f(maxfreq);
Chris@254 333 break;
Chris@254 334 }
Chris@254 335
Chris@254 336 return x;
Chris@254 337 }
Chris@254 338
Chris@260 339 bool
Chris@267 340 SpectrumLayer::getXScaleValue(const View *v, int x,
Chris@260 341 float &value, QString &unit) const
Chris@260 342 {
Chris@267 343 if (m_xorigins.find(v) == m_xorigins.end()) return false;
Chris@267 344 int xorigin = m_xorigins.find(v)->second;
Chris@267 345 value = getFrequencyForX(x - xorigin, v->width() - xorigin - 1);
Chris@260 346 unit = "Hz";
Chris@260 347 return true;
Chris@260 348 }
Chris@260 349
Chris@264 350 bool
Chris@274 351 SpectrumLayer::getYScaleValue(const View *v, int y,
Chris@274 352 float &value, QString &unit) const
Chris@274 353 {
Chris@274 354 value = getValueForY(y, v);
Chris@274 355
Chris@274 356 if (m_energyScale == dBScale || m_energyScale == MeterScale) {
Chris@274 357
Chris@274 358 float thresh = -80.f;
Chris@274 359
Chris@274 360 if (value > 0.f) {
Chris@274 361 value = 10.f * log10f(value);
Chris@274 362 if (value < thresh) value = thresh;
Chris@274 363 } else value = thresh;
Chris@274 364
Chris@274 365 unit = "dBV";
Chris@274 366
Chris@274 367 } else {
Chris@274 368 unit = "V";
Chris@274 369 }
Chris@274 370
Chris@274 371 return true;
Chris@274 372 }
Chris@274 373
Chris@274 374 bool
Chris@274 375 SpectrumLayer::getYScaleDifference(const View *v, int y0, int y1,
Chris@274 376 float &diff, QString &unit) const
Chris@274 377 {
Chris@274 378 bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit);
Chris@274 379 if (rv && (unit == "dBV")) unit = "dB";
Chris@274 380 return rv;
Chris@274 381 }
Chris@274 382
Chris@274 383
Chris@274 384 bool
Chris@264 385 SpectrumLayer::getCrosshairExtents(View *v, QPainter &paint,
Chris@264 386 QPoint cursorPos,
Chris@264 387 std::vector<QRect> &extents) const
Chris@264 388 {
Chris@264 389 QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y());
Chris@264 390 extents.push_back(vertical);
Chris@264 391
Chris@264 392 QRect horizontal(0, cursorPos.y(), v->width(), 12);
Chris@264 393 extents.push_back(horizontal);
Chris@264 394
Chris@264 395 QRect label(cursorPos.x(), v->height() - paint.fontMetrics().height(),
Chris@264 396 paint.fontMetrics().width("123456 Hz") + 2,
Chris@264 397 paint.fontMetrics().height());
Chris@264 398 extents.push_back(label);
Chris@264 399
Chris@264 400 return true;
Chris@264 401 }
Chris@264 402
Chris@254 403 void
Chris@254 404 SpectrumLayer::paintCrosshairs(View *v, QPainter &paint,
Chris@254 405 QPoint cursorPos) const
Chris@254 406 {
Chris@254 407 paint.save();
Chris@254 408
Chris@254 409 ColourMapper mapper(m_colourMap, 0, 1);
Chris@254 410 paint.setPen(mapper.getContrastingColour());
Chris@254 411
Chris@254 412 int xorigin = m_xorigins[v];
Chris@254 413 int w = v->width() - xorigin - 1;
Chris@254 414
Chris@254 415 paint.drawLine(xorigin, cursorPos.y(), v->width(), cursorPos.y());
Chris@254 416 paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->height());
Chris@254 417
Chris@254 418 float fundamental = getFrequencyForX(cursorPos.x() - xorigin, w);
Chris@254 419
Chris@264 420 paint.drawText(cursorPos.x() + 2, v->height() - 2,
Chris@264 421 QString("%1 Hz").arg(fundamental));
Chris@264 422
Chris@254 423 int harmonic = 2;
Chris@254 424
Chris@254 425 while (harmonic < 100) {
Chris@254 426
Chris@254 427 float hx = lrintf(getXForFrequency(fundamental * harmonic, w));
Chris@254 428 hx += xorigin;
Chris@254 429
Chris@254 430 if (hx < xorigin || hx > v->width()) break;
Chris@254 431
Chris@254 432 int len = 7;
Chris@254 433
Chris@254 434 if (harmonic % 2 == 0) {
Chris@254 435 if (harmonic % 4 == 0) {
Chris@254 436 len = 12;
Chris@254 437 } else {
Chris@254 438 len = 10;
Chris@254 439 }
Chris@254 440 }
Chris@254 441
Chris@254 442 paint.drawLine(int(hx),
Chris@254 443 cursorPos.y(),
Chris@254 444 int(hx),
Chris@254 445 cursorPos.y() + len);
Chris@254 446
Chris@254 447 ++harmonic;
Chris@254 448 }
Chris@254 449
Chris@254 450 paint.restore();
Chris@254 451 }
Chris@254 452
Chris@199 453 QString
Chris@199 454 SpectrumLayer::getFeatureDescription(View *v, QPoint &p) const
Chris@199 455 {
Chris@199 456 if (!m_sliceableModel) return "";
Chris@199 457
Chris@199 458 int minbin = 0, maxbin = 0, range = 0;
Chris@199 459 QString genericDesc = SliceLayer::getFeatureDescription
Chris@199 460 (v, p, false, minbin, maxbin, range);
Chris@199 461
Chris@199 462 if (genericDesc == "") return "";
Chris@199 463
Chris@199 464 float minvalue = 0.f;
Chris@248 465 if (minbin < int(m_values.size())) minvalue = m_values[minbin];
Chris@199 466
Chris@199 467 float maxvalue = minvalue;
Chris@248 468 if (maxbin < int(m_values.size())) maxvalue = m_values[maxbin];
Chris@199 469
Chris@199 470 if (minvalue > maxvalue) std::swap(minvalue, maxvalue);
Chris@199 471
Chris@199 472 QString binstr;
Chris@199 473 QString hzstr;
Chris@199 474 int minfreq = lrintf((minbin * m_sliceableModel->getSampleRate()) /
Chris@199 475 m_windowSize);
Chris@199 476 int maxfreq = lrintf((std::max(maxbin, minbin+1)
Chris@199 477 * m_sliceableModel->getSampleRate()) /
Chris@199 478 m_windowSize);
Chris@199 479
Chris@199 480 if (maxbin != minbin) {
Chris@199 481 binstr = tr("%1 - %2").arg(minbin+1).arg(maxbin+1);
Chris@199 482 } else {
Chris@199 483 binstr = QString("%1").arg(minbin+1);
Chris@199 484 }
Chris@199 485 if (minfreq != maxfreq) {
Chris@199 486 hzstr = tr("%1 - %2 Hz").arg(minfreq).arg(maxfreq);
Chris@199 487 } else {
Chris@199 488 hzstr = tr("%1 Hz").arg(minfreq);
Chris@199 489 }
Chris@199 490
Chris@199 491 QString valuestr;
Chris@199 492 if (maxvalue != minvalue) {
Chris@199 493 valuestr = tr("%1 - %2").arg(minvalue).arg(maxvalue);
Chris@199 494 } else {
Chris@199 495 valuestr = QString("%1").arg(minvalue);
Chris@199 496 }
Chris@199 497
Chris@199 498 QString dbstr;
Chris@199 499 float mindb = AudioLevel::multiplier_to_dB(minvalue);
Chris@199 500 float maxdb = AudioLevel::multiplier_to_dB(maxvalue);
Chris@199 501 QString mindbstr;
Chris@199 502 QString maxdbstr;
Chris@199 503 if (mindb == AudioLevel::DB_FLOOR) {
Chris@199 504 mindbstr = tr("-Inf");
Chris@199 505 } else {
Chris@199 506 mindbstr = QString("%1").arg(lrintf(mindb));
Chris@199 507 }
Chris@199 508 if (maxdb == AudioLevel::DB_FLOOR) {
Chris@199 509 maxdbstr = tr("-Inf");
Chris@199 510 } else {
Chris@199 511 maxdbstr = QString("%1").arg(lrintf(maxdb));
Chris@199 512 }
Chris@199 513 if (lrintf(mindb) != lrintf(maxdb)) {
Chris@199 514 dbstr = tr("%1 - %2").arg(mindbstr).arg(maxdbstr);
Chris@199 515 } else {
Chris@199 516 dbstr = tr("%1").arg(mindbstr);
Chris@199 517 }
Chris@199 518
Chris@199 519 QString description;
Chris@199 520
Chris@248 521 if (range > int(m_sliceableModel->getResolution())) {
Chris@199 522 description = tr("%1\nBin:\t%2 (%3)\n%4 value:\t%5\ndB:\t%6")
Chris@199 523 .arg(genericDesc)
Chris@199 524 .arg(binstr)
Chris@199 525 .arg(hzstr)
Chris@199 526 .arg(m_samplingMode == NearestSample ? tr("First") :
Chris@199 527 m_samplingMode == SampleMean ? tr("Mean") : tr("Peak"))
Chris@199 528 .arg(valuestr)
Chris@199 529 .arg(dbstr);
Chris@199 530 } else {
Chris@199 531 description = tr("%1\nBin:\t%2 (%3)\nValue:\t%4\ndB:\t%5")
Chris@199 532 .arg(genericDesc)
Chris@199 533 .arg(binstr)
Chris@199 534 .arg(hzstr)
Chris@199 535 .arg(valuestr)
Chris@199 536 .arg(dbstr);
Chris@199 537 }
Chris@199 538
Chris@199 539 return description;
Chris@199 540 }
Chris@199 541
Chris@254 542 void
Chris@275 543 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const
Chris@275 544 {
Chris@275 545 if (!m_originModel || !m_originModel->isOK() ||
Chris@275 546 !m_originModel->isReady()) return;
Chris@275 547
Chris@275 548 if (m_newFFTNeeded) {
Chris@275 549 const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh
Chris@275 550 m_newFFTNeeded = false;
Chris@275 551 }
Chris@275 552
Chris@275 553 SliceLayer::paint(v, paint, rect);
Chris@275 554 }
Chris@275 555
Chris@275 556 void
Chris@254 557 SpectrumLayer::getBiasCurve(BiasCurve &curve) const
Chris@254 558 {
Chris@254 559 curve = m_biasCurve;
Chris@254 560 }
Chris@199 561
Chris@220 562 QString
Chris@220 563 SpectrumLayer::toXmlString(QString indent, QString extraAttributes) const
Chris@220 564 {
Chris@220 565 QString s;
Chris@199 566
Chris@220 567 s += QString("windowSize=\"%1\" "
Chris@220 568 "windowHopLevel=\"%2\"")
Chris@220 569 .arg(m_windowSize)
Chris@220 570 .arg(m_windowHopLevel);
Chris@220 571
Chris@220 572 return SliceLayer::toXmlString(indent, extraAttributes + " " + s);
Chris@220 573 }
Chris@220 574
Chris@220 575 void
Chris@220 576 SpectrumLayer::setProperties(const QXmlAttributes &attributes)
Chris@220 577 {
Chris@220 578 SliceLayer::setProperties(attributes);
Chris@220 579
Chris@220 580 bool ok = false;
Chris@220 581
Chris@220 582 size_t windowSize = attributes.value("windowSize").toUInt(&ok);
Chris@220 583 if (ok) setWindowSize(windowSize);
Chris@220 584
Chris@220 585 size_t windowHopLevel = attributes.value("windowHopLevel").toUInt(&ok);
Chris@220 586 if (ok) setWindowHopLevel(windowHopLevel);
Chris@220 587 }
Chris@220 588
Chris@220 589