comparison plugins/SimilarityPlugin.cpp @ 60:90fa946fda40

* Add key strength plot to key detector * Fix vector overrun in similarity plugin if some empty frames have been encountered * Fix uninitialised m_count in MFCC plugin * Doc update
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 01 Feb 2008 16:47:39 +0000
parents ee9d180a5ad6
children 12516e68c81e
comparison
equal deleted inserted replaced
59:af3ec1585323 60:90fa946fda40
146 m_blockSize = blockSize; 146 m_blockSize = blockSize;
147 m_channels = channels; 147 m_channels = channels;
148 148
149 m_lastNonEmptyFrame = std::vector<int>(m_channels); 149 m_lastNonEmptyFrame = std::vector<int>(m_channels);
150 for (int i = 0; i < m_channels; ++i) m_lastNonEmptyFrame[i] = -1; 150 for (int i = 0; i < m_channels; ++i) m_lastNonEmptyFrame[i] = -1;
151
152 m_emptyFrameCount = std::vector<int>(m_channels);
153 for (int i = 0; i < m_channels; ++i) m_emptyFrameCount[i] = 0;
154
151 m_frameNo = 0; 155 m_frameNo = 0;
152 156
153 int decimationFactor = getDecimationFactor(); 157 int decimationFactor = getDecimationFactor();
154 if (decimationFactor > 1) { 158 if (decimationFactor > 1) {
155 m_decimator = new Decimator(m_blockSize, decimationFactor); 159 m_decimator = new Decimator(m_blockSize, decimationFactor);
202 206
203 if (needRhythm()) { 207 if (needRhythm()) {
204 m_rhythmClipFrames = 208 m_rhythmClipFrames =
205 int(ceil((m_rhythmClipDuration * m_processRate) 209 int(ceil((m_rhythmClipDuration * m_processRate)
206 / m_rhythmClipFrameSize)); 210 / m_rhythmClipFrameSize));
207 std::cerr << "SimilarityPlugin::initialise: rhythm clip is " 211 // std::cerr << "SimilarityPlugin::initialise: rhythm clip requires "
208 << m_rhythmClipFrames << " frames of size " 212 // << m_rhythmClipFrames << " frames of size "
209 << m_rhythmClipFrameSize << " at process rate " 213 // << m_rhythmClipFrameSize << " at process rate "
210 << m_processRate << " ( = " 214 // << m_processRate << " ( = "
211 << (float(m_rhythmClipFrames * m_rhythmClipFrameSize) / m_processRate) << " sec )" 215 // << (float(m_rhythmClipFrames * m_rhythmClipFrameSize) / m_processRate) << " sec )"
212 << std::endl; 216 // << std::endl;
213 217
214 MFCCConfig config(m_processRate); 218 MFCCConfig config(m_processRate);
215 config.fftsize = m_rhythmClipFrameSize; 219 config.fftsize = m_rhythmClipFrameSize;
216 config.nceps = m_featureColumnSize - 1; 220 config.nceps = m_featureColumnSize - 1;
217 config.want_c0 = true; 221 config.want_c0 = true;
241 m_values[i].clear(); 245 m_values[i].clear();
242 } 246 }
243 247
244 for (int i = 0; i < m_rhythmValues.size(); ++i) { 248 for (int i = 0; i < m_rhythmValues.size(); ++i) {
245 m_rhythmValues[i].clear(); 249 m_rhythmValues[i].clear();
250 }
251
252 for (int i = 0; i < m_lastNonEmptyFrame.size(); ++i) {
253 m_lastNonEmptyFrame[i] = -1;
254 }
255
256 for (int i = 0; i < m_emptyFrameCount.size(); ++i) {
257 m_emptyFrameCount[i] = 0;
246 } 258 }
247 259
248 m_done = false; 260 m_done = false;
249 } 261 }
250 262
534 } 546 }
535 m_rhythmValues[c].push_back(mf); 547 m_rhythmValues[c].push_back(mf);
536 } 548 }
537 } 549 }
538 } 550 }
551 m_emptyFrameCount[c]++;
539 continue; 552 continue;
540 } 553 }
541 554
542 m_lastNonEmptyFrame[c] = m_frameNo; 555 m_lastNonEmptyFrame[c] = m_frameNo;
543 556
643 int count; 656 int count;
644 657
645 // We want to take values up to, but not including, the 658 // We want to take values up to, but not including, the
646 // last non-empty frame (which may be partial) 659 // last non-empty frame (which may be partial)
647 660
648 int sz = m_lastNonEmptyFrame[i]; 661 int sz = m_lastNonEmptyFrame[i] - m_emptyFrameCount[i];
649 if (sz < 0) sz = 0; 662 if (sz < 0) sz = 0;
663 if (sz >= m_values[i].size()) sz = m_values[i].size()-1;
650 664
651 count = 0; 665 count = 0;
652 for (int k = 0; k < sz; ++k) { 666 for (int k = 0; k < sz; ++k) {
653 double val = m_values[i][k][j]; 667 double val = m_values[i][k][j];
654 if (isnan(val) || isinf(val)) continue; 668 if (isnan(val) || isinf(val)) continue;
750 SimilarityPlugin::FeatureMatrix 764 SimilarityPlugin::FeatureMatrix
751 SimilarityPlugin::calculateRhythmic(FeatureSet &returnFeatures) 765 SimilarityPlugin::calculateRhythmic(FeatureSet &returnFeatures)
752 { 766 {
753 if (!needRhythm()) return FeatureMatrix(); 767 if (!needRhythm()) return FeatureMatrix();
754 768
769 // std::cerr << "SimilarityPlugin::initialise: rhythm clip for channel 0 contains "
770 // << m_rhythmValues[0].size() << " frames of size "
771 // << m_rhythmClipFrameSize << " at process rate "
772 // << m_processRate << " ( = "
773 // << (float(m_rhythmValues[0].size() * m_rhythmClipFrameSize) / m_processRate) << " sec )"
774 // << std::endl;
775
755 BeatSpectrum bscalc; 776 BeatSpectrum bscalc;
756 CosineDistance cd; 777 CosineDistance cd;
757 778
758 // Our rhythm feature matrix is a deque of vectors for practical 779 // Our rhythm feature matrix is a deque of vectors for practical
759 // reasons, but BeatSpectrum::process wants a vector of vectors 780 // reasons, but BeatSpectrum::process wants a vector of vectors