# HG changeset patch # User Chris Cannam # Date 1147860156 0 # Node ID 4bfe0cf6e20af8dc4b38bff7e9e239390a8d0d7b # Parent 76c1a7bd04169eb29909e384c33111965c1f3aa0 * Compensate for 4*stepSize delay in onset detection with returned timestamps * Discard onsets that occur within 4*stepSize of previous onset diff -r 76c1a7bd0416 -r 4bfe0cf6e20a plugins/Onset.cpp --- a/plugins/Onset.cpp Tue May 16 15:43:21 2006 +0000 +++ b/plugins/Onset.cpp Wed May 17 10:02:36 2006 +0000 @@ -91,6 +91,11 @@ m_peakpick = new_aubio_peakpicker(m_threshold); m_onsetdet = new_aubio_onsetdetection(m_onsettype, blockSize, channels); + + m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize, + lrintf(m_inputSampleRate)); + + m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay; return true; } @@ -109,7 +114,7 @@ size_t Onset::getPreferredBlockSize() const { - return 2*getPreferredStepSize(); + return 2 * getPreferredStepSize(); } Onset::ParameterList @@ -201,7 +206,8 @@ d.description = "Onsets"; d.hasFixedBinCount = true; d.binCount = 0; - d.sampleType = OutputDescriptor::OneSamplePerStep; + d.sampleType = OutputDescriptor::VariableSampleRate; + d.sampleRate = 0; list.push_back(d); d = OutputDescriptor(); @@ -219,7 +225,7 @@ } Onset::FeatureSet -Onset::process(float **inputBuffers, Vamp::RealTime /* timestamp */) +Onset::process(float **inputBuffers, Vamp::RealTime timestamp) { for (size_t i = 0; i < m_stepSize; ++i) { for (size_t j = 0; j < m_channelCount; ++j) { @@ -241,9 +247,13 @@ FeatureSet returnFeatures; if (isonset) { - Feature onsettime; - onsettime.hasTimestamp = false; - returnFeatures[0].push_back(onsettime); + if (timestamp - m_lastOnset >= m_delay) { + Feature onsettime; + onsettime.hasTimestamp = true; + onsettime.timestamp = timestamp - m_delay; + returnFeatures[0].push_back(onsettime); + m_lastOnset = timestamp; + } } Feature feature; for (size_t j = 0; j < m_channelCount; ++j) { diff -r 76c1a7bd0416 -r 4bfe0cf6e20a plugins/Onset.h --- a/plugins/Onset.h Tue May 16 15:43:21 2006 +0000 +++ b/plugins/Onset.h Wed May 17 10:02:36 2006 +0000 @@ -63,6 +63,8 @@ size_t m_stepSize; size_t m_blockSize; size_t m_channelCount; + Vamp::RealTime m_delay; + Vamp::RealTime m_lastOnset; };