Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
545:c603d9439b37 | 546:95391b480e17 |
---|---|
18 Dense3DModelPeakCache::Dense3DModelPeakCache(DenseThreeDimensionalModel *source, | 18 Dense3DModelPeakCache::Dense3DModelPeakCache(DenseThreeDimensionalModel *source, |
19 size_t columnsPerPeak) : | 19 size_t columnsPerPeak) : |
20 m_source(source), | 20 m_source(source), |
21 m_resolution(columnsPerPeak) | 21 m_resolution(columnsPerPeak) |
22 { | 22 { |
23 m_coverage.resize(1); // otherwise it is simply invalid | |
24 | |
23 m_cache = new EditableDenseThreeDimensionalModel | 25 m_cache = new EditableDenseThreeDimensionalModel |
24 (source->getSampleRate(), | 26 (source->getSampleRate(), |
25 getResolution(), | 27 getResolution(), |
26 source->getHeight(), | 28 source->getHeight(), |
27 EditableDenseThreeDimensionalModel::NoCompression, | 29 EditableDenseThreeDimensionalModel::NoCompression, |
28 false); | 30 false); |
29 | 31 |
30 connect(source, SIGNAL(modelChanged()), | 32 connect(source, SIGNAL(modelChanged()), |
31 this, SLOT(sourceModelChanged())); | 33 this, SLOT(sourceModelChanged())); |
32 connect(source, SIGNAL(modelAboutToBeDeleted()), | 34 connect(source, SIGNAL(aboutToBeDeleted()), |
33 this, SLOT(sourceModelAboutToBeDeleted())); | 35 this, SLOT(sourceModelAboutToBeDeleted())); |
34 | 36 |
35 } | 37 } |
36 | 38 |
37 Dense3DModelPeakCache::~Dense3DModelPeakCache() | 39 Dense3DModelPeakCache::~Dense3DModelPeakCache() |
70 | 72 |
71 void | 73 void |
72 Dense3DModelPeakCache::sourceModelChanged() | 74 Dense3DModelPeakCache::sourceModelChanged() |
73 { | 75 { |
74 if (!m_source) return; | 76 if (!m_source) return; |
75 m_coverage.resize(getWidth()); | 77 if (m_coverage.size() > 0) { |
78 // The last peak may have come from an incomplete read, which | |
79 // may since have been filled, so reset it | |
80 m_coverage.reset(m_coverage.size()-1); | |
81 } | |
82 if (getWidth() > m_coverage.size()) { | |
83 m_coverage.resize(getWidth()); // clears all bits, which is OK with us | |
84 } | |
76 } | 85 } |
77 | 86 |
78 void | 87 void |
79 Dense3DModelPeakCache::sourceModelAboutToBeDeleted() | 88 Dense3DModelPeakCache::sourceModelAboutToBeDeleted() |
80 { | 89 { |
82 } | 91 } |
83 | 92 |
84 bool | 93 bool |
85 Dense3DModelPeakCache::haveColumn(size_t column) const | 94 Dense3DModelPeakCache::haveColumn(size_t column) const |
86 { | 95 { |
87 return m_coverage.get(column); | 96 return column < m_coverage.size() && m_coverage.get(column); |
88 } | 97 } |
89 | 98 |
90 void | 99 void |
91 Dense3DModelPeakCache::fillColumn(size_t column) const | 100 Dense3DModelPeakCache::fillColumn(size_t column) const |
92 { | 101 { |
102 if (column >= m_coverage.size()) m_coverage.resize(column + 1); | |
103 | |
93 Column peak; | 104 Column peak; |
94 for (int i = 0; i < m_resolution; ++i) { | 105 for (int i = 0; i < m_resolution; ++i) { |
95 Column here = m_source->getColumn(column * m_resolution + i); | 106 Column here = m_source->getColumn(column * m_resolution + i); |
96 if (i == 0) { | 107 if (i == 0) { |
97 peak = here; | 108 peak = here; |
99 for (int j = 0; j < peak.size() && j < here.size(); ++j) { | 110 for (int j = 0; j < peak.size() && j < here.size(); ++j) { |
100 if (here[j] > peak[j]) peak[j] = here[j]; | 111 if (here[j] > peak[j]) peak[j] = here[j]; |
101 } | 112 } |
102 } | 113 } |
103 } | 114 } |
115 | |
104 m_cache->setColumn(column, peak); | 116 m_cache->setColumn(column, peak); |
105 m_coverage.set(column); | 117 m_coverage.set(column); |
106 } | 118 } |
107 | 119 |
108 | 120 |