Mercurial > hg > svgui
diff layer/SpectrogramLayer.cpp @ 280:3c402c6052f6
* Pull peak-picker out of SpectrumLayer and into FFTModel; use combined
peak-picker and frequency estimator for SpectrogramLayer (makes the
peak frequency spectrogram a bit quicker)
* Add more information to spectrum and spectrogram crosshairs
author | Chris Cannam |
---|---|
date | Wed, 04 Jul 2007 15:29:16 +0000 |
parents | 47fe0352861e |
children | 4edaff85875d |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Tue Jul 03 18:56:27 2007 +0000 +++ b/layer/SpectrogramLayer.cpp Wed Jul 04 15:29:16 2007 +0000 @@ -2071,15 +2071,25 @@ MagnitudeRange mag; + FFTModel::PeakSet peaks; + if (m_binDisplay == PeakFrequencies && + s < int(fft->getWidth()) - 1) { + peaks = fft->getPeakFrequencies(FFTModel::AllPeaks, + s, + minbin, maxbin - 1); + } + for (size_t q = minbin; q < maxbin; ++q) { float y0 = yval[q + 1]; float y1 = yval[q]; - if (m_binDisplay == PeakBins || - m_binDisplay == PeakFrequencies) { + if (m_binDisplay == PeakBins) { if (!fft->isLocalPeak(s, q)) continue; } + if (m_binDisplay == PeakFrequencies) { + if (peaks.find(q) == peaks.end()) continue; + } if (m_threshold != 0.f && !fft->isOverThreshold(s, q, m_threshold * (m_fftSize/2))) { @@ -2090,14 +2100,9 @@ if (s == s0i) sprop *= (s + 1) - s0; if (s == s1i) sprop *= s1 - s; - if (m_binDisplay == PeakFrequencies && - s < int(fft->getWidth()) - 1) { - - float f = 0; - fft->estimateStableFrequency(s, q, f); - + if (m_binDisplay == PeakFrequencies) { y0 = y1 = v->getYForFrequency - (f, displayMinFreq, displayMaxFreq, logarithmic); + (peaks[q], displayMinFreq, displayMaxFreq, logarithmic); } int y0i = int(y0 + 0.001); @@ -2466,16 +2471,29 @@ int sw = getVerticalScaleWidth(v, paint); - QRect label(sw, cursorPos.y() - paint.fontMetrics().ascent() - 2, - paint.fontMetrics().width("123456 Hz") + 2, - paint.fontMetrics().height()); - extents.push_back(label); + QRect freq(sw, cursorPos.y() - paint.fontMetrics().ascent() - 2, + paint.fontMetrics().width("123456 Hz") + 2, + paint.fontMetrics().height()); + extents.push_back(freq); QRect pitch(sw, cursorPos.y() + 2, paint.fontMetrics().width("C#10+50c") + 2, paint.fontMetrics().height()); extents.push_back(pitch); + QRect rt(cursorPos.x(), + v->height() - paint.fontMetrics().height() - 2, + paint.fontMetrics().width("1234.567 s"), + paint.fontMetrics().height()); + extents.push_back(rt); + + int w(paint.fontMetrics().width("1234567890") + 2); + QRect frame(cursorPos.x() - w - 2, + v->height() - paint.fontMetrics().height() - 2, + w, + paint.fontMetrics().height()); + extents.push_back(frame); + return true; } @@ -2507,12 +2525,20 @@ View::OutlinedText); } - /*!!! - long frame = getFrameForX(cursorPos.x()); + long frame = v->getFrameForX(cursorPos.x()); RealTime rt = RealTime::frame2RealTime(frame, m_model->getSampleRate()); - QString timeLabel = rt.toText(true).c_str(); - ... - */ + QString rtLabel = QString("%1 s").arg(rt.toText(true).c_str()); + QString frameLabel = QString("%1").arg(frame); + v->drawVisibleText(paint, + cursorPos.x() - paint.fontMetrics().width(frameLabel) - 2, + v->height() - 2, + frameLabel, + View::OutlinedText); + v->drawVisibleText(paint, + cursorPos.x() + 2, + v->height() - 2, + rtLabel, + View::OutlinedText); int harmonic = 2;