From: Chris Cannam Date: Wed, 17 May 2006 10:02:36 +0000 (+0000) Subject: * Compensate for 4*stepSize delay in onset detection with returned timestamps X-Git-Tag: hgimport~47 X-Git-Url: https://git.aubio.org/?p=vamp-aubio-plugins.git;a=commitdiff_plain;h=8311697d56d35a35408a81a41c90ad712bee6d45;hp=e20f267267ec3610d3f5314906197fd2819e80c3 * Compensate for 4*stepSize delay in onset detection with returned timestamps * Discard onsets that occur within 4*stepSize of previous onset --- diff --git a/plugins/Onset.cpp b/plugins/Onset.cpp index c4bc76a..def541f 100644 --- a/plugins/Onset.cpp +++ b/plugins/Onset.cpp @@ -91,6 +91,11 @@ Onset::initialise(size_t channels, size_t stepSize, size_t blockSize) 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 @@ Onset::getPreferredStepSize() const size_t Onset::getPreferredBlockSize() const { - return 2*getPreferredStepSize(); + return 2 * getPreferredStepSize(); } Onset::ParameterList @@ -201,7 +206,8 @@ Onset::getOutputDescriptors() const 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::getOutputDescriptors() const } 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 @@ Onset::process(float **inputBuffers, Vamp::RealTime /* timestamp */) 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 --git a/plugins/Onset.h b/plugins/Onset.h index 895cce6..bf80065 100644 --- a/plugins/Onset.h +++ b/plugins/Onset.h @@ -63,6 +63,8 @@ protected: size_t m_stepSize; size_t m_blockSize; size_t m_channelCount; + Vamp::RealTime m_delay; + Vamp::RealTime m_lastOnset; };