# HG changeset patch # User Chris Cannam # Date 1233752942 0 # Node ID 18f38f564d7c9062ace9f19da58d54d5f09af88b # Parent 7f1ed4bfea1e0e7ca2fd2bab30eaf1854c3219df * reorganise function for faster data retrieval diff -r 7f1ed4bfea1e -r 18f38f564d7c layer/SpectrogramLayer.cpp --- 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 < "< "< "<<(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); }