From c6252f75ebe67d506a37228c49cb0587228971f3 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Wed, 11 Jul 2012 13:09:15 +0100 Subject: [PATCH] Implement reset functions (fixes #498) --- plugins/Notes.cpp | 26 +++++++++++++++----------- plugins/Onset.cpp | 23 +++++++++++++---------- plugins/Pitch.cpp | 17 ++++++++++------- plugins/Tempo.cpp | 21 ++++++++++++--------- 4 files changed, 50 insertions(+), 37 deletions(-) diff --git a/plugins/Notes.cpp b/plugins/Notes.cpp index e2cbfe5..c8688cd 100644 --- a/plugins/Notes.cpp +++ b/plugins/Notes.cpp @@ -105,10 +105,21 @@ Notes::initialise(size_t channels, size_t stepSize, size_t blockSize) m_onset = new_fvec(1); m_pitch = new_fvec(1); + reset(); + + return true; +} + +void +Notes::reset() +{ + if (m_onsetdet) del_aubio_onset(m_onsetdet); + if (m_pitchdet) del_aubio_pitch(m_pitchdet); + m_onsetdet = new_aubio_onset (const_cast(getAubioNameForOnsetType(m_onsettype)), - blockSize, - stepSize, + m_blockSize, + m_stepSize, lrintf(m_inputSampleRate)); aubio_onset_set_threshold(m_onsetdet, m_threshold); @@ -117,8 +128,8 @@ Notes::initialise(size_t channels, size_t stepSize, size_t blockSize) m_pitchdet = new_aubio_pitch (const_cast(getAubioNameForPitchType(m_pitchtype)), - blockSize, - stepSize, + m_blockSize, + m_stepSize, lrintf(m_inputSampleRate)); aubio_pitch_set_unit(m_pitchdet, const_cast("freq")); @@ -129,13 +140,6 @@ Notes::initialise(size_t channels, size_t stepSize, size_t blockSize) m_currentOnset = Vamp::RealTime::zeroTime; m_haveCurrent = false; m_prevPitch = -1; - - return true; -} - -void -Notes::reset() -{ } size_t diff --git a/plugins/Onset.cpp b/plugins/Onset.cpp index 8d91587..4494b07 100644 --- a/plugins/Onset.cpp +++ b/plugins/Onset.cpp @@ -91,27 +91,30 @@ Onset::initialise(size_t channels, size_t stepSize, size_t blockSize) m_ibuf = new_fvec(stepSize); m_onset = new_fvec(1); + reset(); + + return true; +} + +void +Onset::reset() +{ + if (m_onsetdet) del_aubio_onset(m_onsetdet); + m_onsetdet = new_aubio_onset (const_cast(getAubioNameForOnsetType(m_onsettype)), - blockSize, - stepSize, + m_blockSize, + m_stepSize, lrintf(m_inputSampleRate)); aubio_onset_set_threshold(m_onsetdet, m_threshold); aubio_onset_set_silence(m_onsetdet, m_silence); aubio_onset_set_minioi(m_onsetdet, m_minioi); - m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize, + m_delay = Vamp::RealTime::frame2RealTime(4 * m_stepSize, lrintf(m_inputSampleRate)); m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay; - - return true; -} - -void -Onset::reset() -{ } size_t diff --git a/plugins/Pitch.cpp b/plugins/Pitch.cpp index 95022fa..5fd3730 100644 --- a/plugins/Pitch.cpp +++ b/plugins/Pitch.cpp @@ -100,13 +100,7 @@ Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize) m_ibuf = new_fvec(stepSize); m_obuf = new_fvec(1); - m_pitchdet = new_aubio_pitch - (const_cast(getAubioNameForPitchType(m_pitchtype)), - blockSize, - stepSize, - lrintf(m_inputSampleRate)); - - aubio_pitch_set_unit(m_pitchdet, const_cast("freq")); + reset(); return true; } @@ -114,6 +108,15 @@ Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize) void Pitch::reset() { + if (m_pitchdet) del_aubio_pitch(m_pitchdet); + + m_pitchdet = new_aubio_pitch + (const_cast(getAubioNameForPitchType(m_pitchtype)), + m_blockSize, + m_stepSize, + lrintf(m_inputSampleRate)); + + aubio_pitch_set_unit(m_pitchdet, const_cast("freq")); } size_t diff --git a/plugins/Tempo.cpp b/plugins/Tempo.cpp index 82c38f8..ac106c3 100644 --- a/plugins/Tempo.cpp +++ b/plugins/Tempo.cpp @@ -94,23 +94,26 @@ Tempo::initialise(size_t channels, size_t stepSize, size_t blockSize) m_delay = Vamp::RealTime::frame2RealTime(3 * stepSize, lrintf(m_inputSampleRate)); + reset(); + + return true; +} + +void +Tempo::reset() +{ + if (m_tempo) del_aubio_tempo(m_tempo); + m_lastBeat = Vamp::RealTime::zeroTime - m_delay - m_delay; m_tempo = new_aubio_tempo (const_cast(getAubioNameForOnsetType(m_onsettype)), - blockSize, - stepSize, + m_blockSize, + m_stepSize, lrintf(m_inputSampleRate)); aubio_tempo_set_silence(m_tempo, m_silence); aubio_tempo_set_threshold(m_tempo, m_threshold); - - return true; -} - -void -Tempo::reset() -{ } size_t -- 2.11.0