Mercurial > hg > svgui
changeset 483:18f38f564d7c
* reorganise function for faster data retrieval
author | Chris Cannam |
---|---|
date | Wed, 04 Feb 2009 13:09:02 +0000 |
parents | 7f1ed4bfea1e |
children | a926fca1f280 |
files | layer/SpectrogramLayer.cpp |
diffstat | 1 files changed, 41 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Wed Feb 04 12:13:16 2009 +0000 +++ b/layer/SpectrogramLayer.cpp Wed Feb 04 13:09:02 2009 +0000 @@ -2421,39 +2421,41 @@ int psx = -1; float values[maxbin - minbin + 1]; + float peaks[h]; for (int x = 0; x < w; ++x) { if (binforx[x] < 0) continue; - for (int y = 0; y < h; ++y) { - - unsigned char peakpix = 0; - - int sx0 = binforx[x]; - int sx1 = sx0; - if (x+1 < w) sx1 = binforx[x+1]; - if (sx0 < 0) sx0 = sx1 - 1; - if (sx0 < 0) continue; - if (sx1 <= sx0) sx1 = sx0 + 1; + int sx0 = binforx[x]; + int sx1 = sx0; + if (x+1 < w) sx1 = binforx[x+1]; + if (sx0 < 0) sx0 = sx1 - 1; + if (sx0 < 0) continue; + if (sx1 <= sx0) sx1 = sx0 + 1; + + for (int y = 0; y < h; ++y) peaks[y] = 0.f; - for (int sx = sx0; sx < sx1; ++sx) { - - if (sx < 0 || sx >= int(fft->getWidth())) continue; - - if (!m_synchronous) { - if (!fft->isColumnAvailable(sx)) { + for (int sx = sx0; sx < sx1; ++sx) { + + if (sx < 0 || sx >= int(fft->getWidth())) continue; + + if (!m_synchronous) { + if (!fft->isColumnAvailable(sx)) { #ifdef DEBUG_SPECTROGRAM_REPAINT - std::cerr << "Met unavailable column at col " << sx << std::endl; + std::cerr << "Met unavailable column at col " << sx << std::endl; #endif - return false; - } + return false; } - - if (sx != psx) { - fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); - psx = sx; - } + } + + if (sx != psx) { + cerr << "Retrieving column " << sx << endl; + fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); + psx = sx; + } + + for (int y = 0; y < h; ++y) { int sy0 = binfory[y]; int sy1 = sy0; @@ -2468,8 +2470,6 @@ //!!! magnitudes here, we can just use peak of the //!!! float values - float peak = 0.f; - for (int sy = sy0; sy < sy1; ++sy) { float value = values[sy - minbin]; @@ -2486,19 +2486,24 @@ if (pix > peakpix) peakpix = pix; // cerr <<x<<","<<y<<" -> "<<sx<<","<<sy<<" -> "<<values[sy]<<" -> "<<(int)pix<< endl; */ - if (value > peak) peak = value; //!!! not right for phase! + if (value > peaks[y]) peaks[y] = value; //!!! not right for phase! } - - if (m_colourScale != PhaseColourScale) { - if (!m_normalizeColumns) { - peak /= (m_fftSize/2.f); - } + } + } + + for (int y = 0; y < h; ++y) { + + float peak = peaks[y]; + + if (m_colourScale != PhaseColourScale) { + if (!m_normalizeColumns) { + peak /= (m_fftSize/2.f); + } //!!! mag.sample(value); - peak *= m_gain; - } - - peakpix = getDisplayValue(v, peak); + peak *= m_gain; } + + unsigned char peakpix = getDisplayValue(v, peak); m_drawBuffer.setPixel(x, h-y-1, peakpix); }