diff vamp/CQChromaVamp.cpp @ 147:1060a19e2334

Report validity of CQKernel construction, and avoid NaN values for invalid parameters. Also documentation.
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 10 Jul 2014 12:19:39 +0100
parents 1e33f719dde1
children 242bf7bc38ce
line wrap: on
line diff
--- a/vamp/CQChromaVamp.cpp	Fri Jun 20 10:33:11 2014 +0100
+++ b/vamp/CQChromaVamp.cpp	Thu Jul 10 12:19:39 2014 +0100
@@ -223,13 +223,17 @@
     // appropriate number of octaves.
     m_minFrequency = midiPitchLimitFreq / pow(2, m_octaveCount + 1);
 
-    cerr << "lowest octave: " << m_lowestOctave << ", highest octave: "
-         << highestOctave << ", limit midi pitch: " << midiPitchLimit
-         << ", min freq " << m_minFrequency << ", max freq " << m_maxFrequency
-         << endl;
+//    cerr << "lowest octave: " << m_lowestOctave << ", highest octave: "
+//         << highestOctave << ", limit midi pitch: " << midiPitchLimit
+//         << ", min freq " << m_minFrequency << ", max freq " << m_maxFrequency
+//         << endl;
 
-    CQParameters p(m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo);
-    m_cq = new CQSpectrogram(p, CQSpectrogram::InterpolateLinear);
+    reset();
+
+    if (!m_cq || !m_cq->isValid()) {
+        cerr << "CQVamp::initialise: Constant-Q parameters not valid! Not initialising" << endl;
+        return false;
+    }
 
     return true;
 }
@@ -237,12 +241,14 @@
 void
 CQChromaVamp::reset()
 {
-    if (m_cq) {
-	delete m_cq;
-        CQParameters p(m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo);
-        m_cq = new CQSpectrogram(p, CQSpectrogram::InterpolateLinear);
-    }
+    cerr << "reset: rate " << m_inputSampleRate << ", minf " << m_minFrequency << ", maxf " << m_maxFrequency << ", bpo " << m_bpo << endl;
+
+    delete m_cq;
+    CQParameters p(m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo);
+    m_cq = new CQSpectrogram(p, CQSpectrogram::InterpolateLinear);
+
     m_haveStartTime = false;
+    m_startTime = Vamp::RealTime::zeroTime;
     m_columnCount = 0;
 }
 
@@ -344,6 +350,7 @@
         // fold and invert to put low frequencies at the start
 
         int thisHeight = cqout[i].size();
+
 	for (int j = 0; j < thisHeight; ++j) {
 	    column[m_bpo - (j % m_bpo) - 1] += cqout[i][j];
 	}