changeset 33:a2301c902711

Continuing to update for aubio-git (0.4.0?) api
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 09 Jul 2012 17:51:30 +0100
parents 8a20f3488d88
children 0f40399ca1ff
files plugins/Onset.cpp plugins/Onset.h plugins/Pitch.cpp plugins/Pitch.h plugins/Types.cpp
diffstat 5 files changed, 50 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/Onset.cpp	Mon Jul 09 15:50:30 2012 +0100
+++ b/plugins/Onset.cpp	Mon Jul 09 17:51:30 2012 +0100
@@ -30,7 +30,7 @@
     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()
 {
-    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 @@
     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_peakpick = new_aubio_peakpicker();
+    aubio_peakpicker_set_threshold(m_peakpick, m_threshold);
 
-    m_onsetdet = new_aubio_onsetdetection(m_onsettype, blockSize);
+    m_onsetdet = new_aubio_onset
+        (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
+         blockSize,
+         stepSize,
+         lrintf(m_inputSampleRate));
     
     m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize,
                                              lrintf(m_inputSampleRate));
@@ -136,7 +141,7 @@
     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 @@
 {
     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 @@
                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);
 
--- a/plugins/Onset.h	Mon Jul 09 15:50:30 2012 +0100
+++ b/plugins/Onset.h	Mon Jul 09 17:51:30 2012 +0100
@@ -60,7 +60,7 @@
     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;
--- a/plugins/Pitch.cpp	Mon Jul 09 15:50:30 2012 +0100
+++ b/plugins/Pitch.cpp	Mon Jul 09 17:51:30 2012 +0100
@@ -46,6 +46,7 @@
 {
     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 @@
     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<char *>(getAubioNameForPitchType(m_pitchtype)),
+         blockSize,
+         stepSize,
+         lrintf(m_inputSampleRate));
+
+    aubio_pitch_set_unit(m_pitchdet, "freq");
 
     return true;
 }
@@ -134,7 +137,7 @@
     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 @@
 {
     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 @@
     }
 
     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) {
--- a/plugins/Pitch.h	Mon Jul 09 15:50:30 2012 +0100
+++ b/plugins/Pitch.h	Mon Jul 09 17:51:30 2012 +0100
@@ -56,6 +56,7 @@
 
 protected:
     fvec_t *m_ibuf;
+    fvec_t *m_obuf;
     aubio_pitch_t *m_pitchdet;
     PitchType m_pitchtype;
     float m_minfreq;
--- a/plugins/Types.cpp	Mon Jul 09 15:50:30 2012 +0100
+++ b/plugins/Types.cpp	Mon Jul 09 17:51:30 2012 +0100
@@ -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];
 }