Mercurial > hg > svcore
diff data/model/Dense3DModelPeakCache.cpp @ 546:95391b480e17
* Make use of peak cache in spectrogram
author | Chris Cannam |
---|---|
date | Wed, 04 Feb 2009 15:03:42 +0000 |
parents | c603d9439b37 |
children | 1469caaa8e67 |
line wrap: on
line diff
--- a/data/model/Dense3DModelPeakCache.cpp Wed Feb 04 13:33:50 2009 +0000 +++ b/data/model/Dense3DModelPeakCache.cpp Wed Feb 04 15:03:42 2009 +0000 @@ -20,6 +20,8 @@ m_source(source), m_resolution(columnsPerPeak) { + m_coverage.resize(1); // otherwise it is simply invalid + m_cache = new EditableDenseThreeDimensionalModel (source->getSampleRate(), getResolution(), @@ -29,7 +31,7 @@ connect(source, SIGNAL(modelChanged()), this, SLOT(sourceModelChanged())); - connect(source, SIGNAL(modelAboutToBeDeleted()), + connect(source, SIGNAL(aboutToBeDeleted()), this, SLOT(sourceModelAboutToBeDeleted())); } @@ -72,7 +74,14 @@ Dense3DModelPeakCache::sourceModelChanged() { if (!m_source) return; - m_coverage.resize(getWidth()); + if (m_coverage.size() > 0) { + // The last peak may have come from an incomplete read, which + // may since have been filled, so reset it + m_coverage.reset(m_coverage.size()-1); + } + if (getWidth() > m_coverage.size()) { + m_coverage.resize(getWidth()); // clears all bits, which is OK with us + } } void @@ -84,12 +93,14 @@ bool Dense3DModelPeakCache::haveColumn(size_t column) const { - return m_coverage.get(column); + return column < m_coverage.size() && m_coverage.get(column); } void Dense3DModelPeakCache::fillColumn(size_t column) const { + if (column >= m_coverage.size()) m_coverage.resize(column + 1); + Column peak; for (int i = 0; i < m_resolution; ++i) { Column here = m_source->getColumn(column * m_resolution + i); @@ -101,6 +112,7 @@ } } } + m_cache->setColumn(column, peak); m_coverage.set(column); }