set negative timestamps to zero
[vamp-aubio-plugins.git] / plugins / Notes.cpp
index 05f7189..39ad0f2 100644 (file)
@@ -112,6 +112,8 @@ Notes::initialise(size_t channels, size_t stepSize, size_t blockSize)
                                           m_pitchmode);
 
     m_count = 0;
+    m_delay = Vamp::RealTime::frame2RealTime((4 + m_median) * m_stepSize,
+                                       lrintf(m_inputSampleRate));
     m_currentOnset = Vamp::RealTime::zeroTime;
     m_haveCurrent = false;
 
@@ -324,9 +326,8 @@ Notes::pushNote(FeatureSet &fs, const Vamp::RealTime &offTime)
 
     Feature feature;
     feature.hasTimestamp = true;
-    feature.timestamp = m_currentOnset -
-        Vamp::RealTime::frame2RealTime((4 + m_median) * m_stepSize,
-                                       m_inputSampleRate);
+    if (m_currentOnset < m_delay) m_currentOnset = m_delay;
+    feature.timestamp = m_currentOnset - m_delay;
     feature.values.push_back(median);
 //    feature.values.push_back(FLOOR(aubio_freqtomidi(median) + 0.5));
     feature.values.push_back