From 500c6a1fa7d4727aee15b4908f98307a0907569b Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Mon, 9 Jul 2012 17:51:30 +0100 Subject: [PATCH] Continuing to update for aubio-git (0.4.0?) api --- plugins/Onset.cpp | 38 ++++++++++++++++++++------------------ plugins/Onset.h | 2 +- plugins/Pitch.cpp | 35 +++++++++++++++++++---------------- plugins/Pitch.h | 1 + plugins/Types.cpp | 27 ++++++++++----------------- 5 files changed, 51 insertions(+), 52 deletions(-) diff --git a/plugins/Onset.cpp b/plugins/Onset.cpp index 3e3f8d9..5aa318e 100644 --- a/plugins/Onset.cpp +++ b/plugins/Onset.cpp @@ -30,7 +30,7 @@ Onset::Onset(float inputSampleRate) : m_pv(0), m_peakpick(0), m_onsetdet(0), - m_onsettype(aubio_onset_complex), + m_onsettype(OnsetComplex), m_threshold(0.3), m_silence(-90) { @@ -38,7 +38,7 @@ Onset::Onset(float inputSampleRate) : Onset::~Onset() { - if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet); + if (m_onsetdet) del_aubio_onset(m_onsetdet); if (m_ibuf) del_fvec(m_ibuf); if (m_onset) del_fvec(m_onset); if (m_fftgrain) del_cvec(m_fftgrain); @@ -97,9 +97,14 @@ Onset::initialise(size_t channels, size_t stepSize, size_t blockSize) m_onset = new_fvec(1); m_fftgrain = new_cvec(blockSize); m_pv = new_aubio_pvoc(blockSize, stepSize); - m_peakpick = new_aubio_peakpicker(m_threshold); - - m_onsetdet = new_aubio_onsetdetection(m_onsettype, blockSize); + m_peakpick = new_aubio_peakpicker(); + aubio_peakpicker_set_threshold(m_peakpick, m_threshold); + + m_onsetdet = new_aubio_onset + (const_cast(getAubioNameForOnsetType(m_onsettype)), + blockSize, + stepSize, + lrintf(m_inputSampleRate)); m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize, lrintf(m_inputSampleRate)); @@ -136,7 +141,7 @@ Onset::getParameterDescriptors() const desc.name = "Onset Detection Function Type"; desc.minValue = 0; desc.maxValue = 6; - desc.defaultValue = (int)aubio_onset_complex; + desc.defaultValue = (int)OnsetComplex; desc.isQuantized = true; desc.quantizeStep = 1; desc.valueNames.push_back("Energy Based"); @@ -189,13 +194,13 @@ Onset::setParameter(std::string param, float value) { if (param == "onsettype") { switch (lrintf(value)) { - case 0: m_onsettype = aubio_onset_energy; break; - case 1: m_onsettype = aubio_onset_specdiff; break; - case 2: m_onsettype = aubio_onset_hfc; break; - case 3: m_onsettype = aubio_onset_complex; break; - case 4: m_onsettype = aubio_onset_phase; break; - case 5: m_onsettype = aubio_onset_kl; break; - case 6: m_onsettype = aubio_onset_mkl; break; + case 0: m_onsettype = OnsetEnergy; break; + case 1: m_onsettype = OnsetSpecDiff; break; + case 2: m_onsettype = OnsetHFC; break; + case 3: m_onsettype = OnsetComplex; break; + case 4: m_onsettype = OnsetPhase; break; + case 5: m_onsettype = OnsetKL; break; + case 6: m_onsettype = OnsetMKL; break; } } else if (param == "peakpickthreshold") { m_threshold = value; @@ -238,13 +243,10 @@ Onset::process(const float *const *inputBuffers, Vamp::RealTime timestamp) { for (size_t i = 0; i < m_stepSize; ++i) { - for (size_t j = 0; j < m_channelCount; ++j) { - fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i); - } + fvec_write_sample(m_ibuf, inputBuffers[0][i], i); } - aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain); - aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset); + aubio_onset_do(m_onsetdet, m_ibuf, m_onset); bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick); diff --git a/plugins/Onset.h b/plugins/Onset.h index 80fd0e6..95d94f5 100644 --- a/plugins/Onset.h +++ b/plugins/Onset.h @@ -60,7 +60,7 @@ protected: fvec_t *m_onset; aubio_pvoc_t *m_pv; aubio_peakpicker_t *m_peakpick; - aubio_specdesc_t *m_onsetdet; + aubio_onset_t *m_onsetdet; OnsetType m_onsettype; float m_threshold; float m_silence; diff --git a/plugins/Pitch.cpp b/plugins/Pitch.cpp index 40c310e..f1620c4 100644 --- a/plugins/Pitch.cpp +++ b/plugins/Pitch.cpp @@ -46,6 +46,7 @@ Pitch::~Pitch() { if (m_pitchdet) del_aubio_pitch(m_pitchdet); if (m_ibuf) del_fvec(m_ibuf); + if (m_obuf) del_fvec(m_obuf); } string @@ -96,13 +97,15 @@ Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize) m_blockSize = blockSize; m_ibuf = new_fvec(stepSize); + m_obuf = new_fvec(1); - m_pitchdet = new_aubio_pitchdetection(blockSize, - stepSize, - channels, - lrintf(m_inputSampleRate), - m_pitchtype, - m_pitchmode); + m_pitchdet = new_aubio_pitch + (const_cast(getAubioNameForPitchType(m_pitchtype)), + blockSize, + stepSize, + lrintf(m_inputSampleRate)); + + aubio_pitch_set_unit(m_pitchdet, "freq"); return true; } @@ -134,7 +137,7 @@ Pitch::getParameterDescriptors() const desc.name = "Pitch Detection Function Type"; desc.minValue = 0; desc.maxValue = 4; - desc.defaultValue = (int)aubio_pitch_yinfft; + desc.defaultValue = (int)PitchYinFFT; desc.isQuantized = true; desc.quantizeStep = 1; desc.valueNames.push_back("YIN Frequency Estimator"); @@ -210,11 +213,11 @@ Pitch::setParameter(std::string param, float value) { if (param == "pitchtype") { switch (lrintf(value)) { - case 0: m_pitchtype = aubio_pitch_yin; break; - case 1: m_pitchtype = aubio_pitch_mcomb; break; - case 2: m_pitchtype = aubio_pitch_schmitt; break; - case 3: m_pitchtype = aubio_pitch_fcomb; break; - case 4: m_pitchtype = aubio_pitch_yinfft; break; + case 0: m_pitchtype = PitchYin; break; + case 1: m_pitchtype = PitchMComb; break; + case 2: m_pitchtype = PitchSchmitt; break; + case 3: m_pitchtype = PitchFComb; break; + case 4: m_pitchtype = PitchYinFFT; break; } } else if (param == "minfreq") { m_minfreq = value; @@ -262,12 +265,12 @@ Pitch::process(const float *const *inputBuffers, } for (size_t i = 0; i < m_stepSize; ++i) { - for (size_t j = 0; j < m_channelCount; ++j) { - fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i); - } + fvec_write_sample(m_ibuf, inputBuffers[0][i], i); } - float freq = aubio_pitchdetection(m_pitchdet, m_ibuf); + aubio_pitch_do(m_pitchdet, m_ibuf, m_obuf); + + float freq = m_obuf->data[0]; bool silent = aubio_silence_detection(m_ibuf, m_silence); if (silent) { diff --git a/plugins/Pitch.h b/plugins/Pitch.h index e7b0ec5..86c9b61 100644 --- a/plugins/Pitch.h +++ b/plugins/Pitch.h @@ -56,6 +56,7 @@ public: protected: fvec_t *m_ibuf; + fvec_t *m_obuf; aubio_pitch_t *m_pitchdet; PitchType m_pitchtype; float m_minfreq; diff --git a/plugins/Types.cpp b/plugins/Types.cpp index 6a692b1..c5d9a64 100644 --- a/plugins/Types.cpp +++ b/plugins/Types.cpp @@ -18,26 +18,19 @@ const char *getAubioNameForOnsetType(OnsetType t) { - switch (t) { - case OnsetEnergy: return "energy"; - case OnsetSpecDiff: return "specdiff"; - case OnsetHFC: return "hfc"; - case OnsetComplex: return "complex"; - case OnsetPhase: return "phase"; - case OnsetMKL: return "mkl"; - case OnsetKL: return "kl"; - case OnsetSpecFlux: return "specflux"; - } + // In the same order as the enum elements in the header + static const char *const names[] = { + "energy", "specdiff", "hfc", "complex", "phase", "kl", "mkl", "specflux" + }; + return names[(int)t]; } const char *getAubioNameForPitchType(PitchType t) { - switch (t) { - case PitchMComb: return "mcomb"; - case PitchYinFFT: return "yinfft"; - case PitchYin: return "yin"; - case PitchSchmitt: return "schmitt"; - case PitchFComb: return "fcomb"; - } + // In the same order as the enum elements in the header + static const char *const names[] = { + "yin", "mcomb", "schmitt", "fcomb", "yinfft" + }; + return names[(int)t]; } -- 2.11.0