# HG changeset patch # User Chris Cannam # Date 1136912642 0 # Node ID ab83c415a6cdd12cb4d2e775c84b778fd1baf3e0 # Parent 2a4f26e85b4cbb602ea9c7362f687dfdbd7b1f50 * Backed out partially complete changes to make the spectrogram only store results up to the requested max frequency. The speed improvement was minimal at the expense of annoyance when changing frequency limit, and although it did save memory, it wasn't yet reliable and fixing it is not a high enough priority. diff -r 2a4f26e85b4c -r ab83c415a6cd layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Tue Jan 10 16:33:16 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Tue Jan 10 17:04:02 2006 +0000 @@ -42,7 +42,6 @@ m_frequencyScale(LinearFrequencyScale), m_cache(0), m_cacheInvalid(true), - m_maxCachedFrequency(0), m_pixmapCache(0), m_pixmapCacheInvalid(true), m_fillThread(0), @@ -463,19 +462,13 @@ if (m_maxFrequency == mf) return; m_mutex.lock(); - - // don't need to invalidate main cache here... - + // don't need to invalidate main cache here m_pixmapCacheInvalid = true; m_maxFrequency = mf; emit layerParametersChanged(); m_mutex.unlock(); - - // ... but we do still need to do this, in case m_maxFrequency - // now > m_maxCachedFrequency - fillCache(); } size_t @@ -731,8 +724,6 @@ for (size_t i = 0; i < m_windowSize / 2; ++i) { - if (int(i) >= m_cache->height()) break; - int value = 0; if (m_colourScale == PhaseColourScale) { @@ -741,6 +732,7 @@ value = int((phase * 128 / M_PI) + 128); } else { + double mag = sqrt(output[i][0] * output[i][0] + output[i][1] * output[i][1]); mag /= m_windowSize / 2; @@ -773,7 +765,7 @@ break; } - if (column < m_cache->width()) { + if (column < m_cache->width() && (int)i < m_cache->height()) { m_cache->setPixel(column, i, value + 1); // 0 is "unset" } } @@ -795,9 +787,7 @@ // std::cerr << "SpectrogramLayer::CacheFillThread::run in loop" << std::endl; - if (m_layer.m_model && - (m_layer.m_cacheInvalid || - m_layer.m_maxFrequency > m_layer.m_maxCachedFrequency)) { + if (m_layer.m_model && m_layer.m_cacheInvalid) { // std::cerr << "SpectrogramLayer::CacheFillThread::run: something to do" << std::endl; @@ -805,11 +795,6 @@ m_layer.m_condition.wait(&m_layer.m_mutex, 100); } - size_t minFreq = 0; - if (!m_layer.m_cacheInvalid) { - minFreq = m_layer.m_maxCachedFrequency; - } - m_layer.m_cachedInitialVisibleArea = false; m_layer.m_cacheInvalid = false; m_fillExtent = 0; @@ -837,15 +822,9 @@ } delete m_layer.m_cache; - size_t bins = windowSize / 2; - if (m_layer.m_maxFrequency > 0) { - int sr = m_layer.m_model->getSampleRate(); - bins = int((double(m_layer.m_maxFrequency) * windowSize) / sr + 0.1); - if (bins > windowSize / 2) bins = windowSize / 2; - } m_layer.m_cache = new QImage((end - start) / windowIncrement + 1, - bins, //!!! - QImage::Format_Indexed8); + windowSize / 2, + QImage::Format_Indexed8); m_layer.setCacheColourmap(); @@ -859,12 +838,12 @@ fftw_malloc(windowSize * sizeof(fftw_complex)); fftw_plan plan = fftw_plan_dft_r2c_1d(windowSize, input, - output, FFTW_MEASURE); + output, FFTW_ESTIMATE); Window windower(m_layer.m_windowType, m_layer.m_windowSize); if (!plan) { - std::cerr << "WARNING: fftw_plan(" << windowSize << ") failed!" << std::endl; + std::cerr << "WARNING: fftw_plan_dft_r2c_1d(" << windowSize << ") failed!" << std::endl; fftw_free(input); fftw_free(output); m_layer.m_mutex.lock(); diff -r 2a4f26e85b4c -r ab83c415a6cd layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Tue Jan 10 16:33:16 2006 +0000 +++ b/layer/SpectrogramLayer.h Tue Jan 10 17:04:02 2006 +0000 @@ -165,7 +165,6 @@ QImage *m_cache; bool m_cacheInvalid; - size_t m_maxCachedFrequency; mutable QPixmap *m_pixmapCache; mutable bool m_pixmapCacheInvalid;