Mercurial > hg > svgui
changeset 92:23d1e37bbfb4
* Make a single base Thread class for RT and non-RT threads
* Pull ResizeableBitmap out from the MatrixFile's ColumnBitmap
* Reorder SpectrogramLayer::paint somewhat so as to improve cache hit ratio
in the FFT file cache
author | Chris Cannam |
---|---|
date | Mon, 08 May 2006 16:44:47 +0000 |
parents | ed01c1261b55 |
children | 05c41701dc6c |
files | layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h |
diffstat | 2 files changed, 58 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Mon May 08 13:51:16 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Mon May 08 16:44:47 2006 +0000 @@ -27,13 +27,14 @@ #include <QPixmap> #include <QRect> #include <QTimer> +#include <QApplication> #include <iostream> #include <cassert> #include <cmath> -#define DEBUG_SPECTROGRAM_REPAINT 1 +//#define DEBUG_SPECTROGRAM_REPAINT 1 static double mod(double x, double y) { @@ -1748,6 +1749,13 @@ bool recreateWholePixmapCache = true; +// if (stillCacheing) { + x0 = rect.left(); + x1 = rect.right() + 1; + y0 = rect.top(); + y1 = rect.bottom() + 1; +// } + if (!m_pixmapCacheInvalid) { //!!! This cache may have been obsoleted entirely by the @@ -1832,14 +1840,14 @@ #endif } } - +/* if (stillCacheing) { x0 = rect.left(); x1 = rect.right() + 1; y0 = rect.top(); y1 = rect.bottom() + 1; } - +*/ int w = x1 - x0; int h = y1 - y0; @@ -1848,9 +1856,6 @@ QImage scaled(w, h, QImage::Format_RGB32); scaled.fill(m_colourMap.getColour(0).rgb()); - float ymag[h]; - float ydiv[h]; - int sr = m_model->getSampleRate(); size_t bins = m_windowSize / 2; @@ -1869,12 +1874,21 @@ float minFreq = (float(minbin) * sr) / m_windowSize; float maxFreq = (float(bins) * sr) / m_windowSize; + float ymag[h]; + float ydiv[h]; + float yval[bins + 1]; + size_t increment = getWindowIncrement(); bool logarithmic = (m_frequencyScale == LogFrequencyScale); m_mutex.unlock(); + for (size_t q = minbin; q <= bins; ++q) { + float f0 = (float(q) * sr) / m_windowSize; + yval[q] = v->getYForFrequency(f0, minFreq, maxFreq, logarithmic); + } + for (int x = 0; x < w; ++x) { m_mutex.lock(); @@ -1907,33 +1921,28 @@ s1i = s0i; } } - - bool haveColumn = false; - for (size_t s = s0i; s <= s1i; ++s) { - if (m_cache->haveColumnAt(s)) { - haveColumn = true; - break; - } - } - if (!haveColumn) { - m_mutex.unlock(); - continue; - } - - for (size_t q = minbin; q < bins; ++q) { - - float f0 = (float(q) * sr) / m_windowSize; - float f1 = (float(q + 1) * sr) / m_windowSize; - - float y0 = 0, y1 = 0; - - if (m_binDisplay != PeakFrequencies) { - y0 = v->getYForFrequency(f1, minFreq, maxFreq, logarithmic); - y1 = v->getYForFrequency(f0, minFreq, maxFreq, logarithmic); - } - - for (int s = s0i; s <= s1i; ++s) { - + + for (int s = s0i; s <= s1i; ++s) { + + if (!m_cache->haveColumnAt(s)) continue; + + for (size_t q = minbin; q < bins; ++q) { + +// float f0 = (float(q) * sr) / m_windowSize; +// float f1 = (float(q + 1) * sr) / m_windowSize; + +// float y0 = 0, y1 = 0; + + float y0 = yval[q + 1]; + float y1 = yval[q]; + + +/* + if (m_binDisplay != PeakFrequencies) { + y0 = v->getYForFrequency(f1, minFreq, maxFreq, logarithmic); + y1 = v->getYForFrequency(f0, minFreq, maxFreq, logarithmic); + } +*/ if (m_binDisplay == PeakBins || m_binDisplay == PeakFrequencies) { if (!m_cache->isLocalPeak(s, q)) continue; @@ -1949,7 +1958,8 @@ s < int(m_cache->getWidth()) - 1) { bool steady = false; - f0 = f1 = calculateFrequency(q, +// f0 = f1 = calculateFrequency(q, + float f = calculateFrequency(q, m_windowSize, increment, sr, @@ -1958,12 +1968,23 @@ steady); y0 = y1 = v->getYForFrequency - (f0, minFreq, maxFreq, logarithmic); +// (f0, minFreq, maxFreq, logarithmic); + (f, minFreq, maxFreq, logarithmic); } int y0i = int(y0 + 0.001); int y1i = int(y1); + float value; + + if (m_colourScale == PhaseColourScale) { + value = m_cache->getPhaseAt(s, q); + } else if (m_normalizeColumns) { + value = m_cache->getNormalizedMagnitudeAt(s, q) * m_gain; + } else { + value = m_cache->getMagnitudeAt(s, q) * m_gain; + } + for (int y = y0i; y <= y1i; ++y) { if (y < 0 || y >= h) continue; @@ -1971,17 +1992,6 @@ float yprop = sprop; if (y == y0i) yprop *= (y + 1) - y0; if (y == y1i) yprop *= y1 - y; - - float value; - - if (m_colourScale == PhaseColourScale) { - value = m_cache->getPhaseAt(s, q); - } else if (m_normalizeColumns) { - value = m_cache->getNormalizedMagnitudeAt(s, q) * m_gain; - } else { - value = m_cache->getMagnitudeAt(s, q) * m_gain; - } - ymag[y] += yprop * value; ydiv[y] += yprop; }
--- a/layer/SpectrogramLayer.h Mon May 08 13:51:16 2006 +0000 +++ b/layer/SpectrogramLayer.h Mon May 08 16:44:47 2006 +0000 @@ -19,7 +19,7 @@ #include "base/Layer.h" #include "base/Window.h" #include "base/RealTime.h" -#include "base/NonRTThread.h" +#include "base/Thread.h" #include "model/PowerOfSqrtTwoZoomConstraint.h" #include "model/DenseTimeValueModel.h" @@ -240,7 +240,7 @@ FFTCacheBase *m_writeCache; bool m_cacheInvalid; - class CacheFillThread : public NonRTThread + class CacheFillThread : public Thread { public: CacheFillThread(SpectrogramLayer &layer) :