changeset 1:ab83c415a6cd

* 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.
author Chris Cannam
date Tue, 10 Jan 2006 17:04:02 +0000
parents 2a4f26e85b4c
children 77dad696d740
files layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h
diffstat 2 files changed, 8 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- 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<double> 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();
--- 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;