* Add frequency range limits, frequency-wrap option, and silence
[vamp-aubio-plugins.git] / plugins / Tempo.cpp
index 5fc3cc6..5ebf25e 100644 (file)
@@ -22,6 +22,8 @@ using std::vector;
 using std::cerr;
 using std::endl;
 
+//#define HAVE_AUBIO_LOCKED_TEMPO_HACK
+
 Tempo::Tempo(float inputSampleRate) :
     Plugin(inputSampleRate),
     m_ibuf(0),
@@ -55,21 +57,27 @@ Tempo::~Tempo()
 }
 
 string
-Tempo::getName() const
+Tempo::getIdentifier() const
 {
     return "aubiotempo";
 }
 
 string
-Tempo::getDescription() const
+Tempo::getName() const
 {
     return "Aubio Tempo Detector";
 }
 
 string
+Tempo::getDescription() const
+{
+    return "Estimate the musical tempo and track beat positions";
+}
+
+string
 Tempo::getMaker() const
 {
-    return "Paul Brossier (plugin by Chris Cannam)";
+    return "Paul Brossier (method by Matthew Davies, plugin by Chris Cannam)";
 }
 
 int
@@ -136,8 +144,8 @@ Tempo::getParameterDescriptors() const
     ParameterList list;
     
     ParameterDescriptor desc;
-    desc.name = "onsettype";
-    desc.description = "Onset Detection Function Type";
+    desc.identifier = "onsettype";
+    desc.name = "Onset Detection Function Type";
     desc.minValue = 0;
     desc.maxValue = 6;
     desc.defaultValue = (int)aubio_onset_complex;
@@ -153,8 +161,8 @@ Tempo::getParameterDescriptors() const
     list.push_back(desc);
 
     desc = ParameterDescriptor();
-    desc.name = "peakpickthreshold";
-    desc.description = "Peak Picker Threshold";
+    desc.identifier = "peakpickthreshold";
+    desc.name = "Peak Picker Threshold";
     desc.minValue = 0;
     desc.maxValue = 1;
     desc.defaultValue = 0.3;
@@ -162,8 +170,8 @@ Tempo::getParameterDescriptors() const
     list.push_back(desc);
 
     desc = ParameterDescriptor();
-    desc.name = "silencethreshold";
-    desc.description = "Silence Threshold";
+    desc.identifier = "silencethreshold";
+    desc.name = "Silence Threshold";
     desc.minValue = -120;
     desc.maxValue = 0;
     desc.defaultValue = -90;
@@ -214,20 +222,32 @@ Tempo::getOutputDescriptors() const
     OutputList list;
 
     OutputDescriptor d;
-    d.name = "beats";
+    d.identifier = "beats";
+    d.name = "Beats";
     d.unit = "";
-    d.description = "Beats";
     d.hasFixedBinCount = true;
     d.binCount = 0;
     d.sampleType = OutputDescriptor::VariableSampleRate;
     d.sampleRate = 0;
     list.push_back(d);
 
+#ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK
+    d.identifier = "tempo";
+    d.name = "Tempo";
+    d.unit = "bpm";
+    d.hasFixedBinCount = true;
+    d.binCount = 1;
+    d.hasKnownExtents = false;
+    d.isQuantized = false;
+    d.sampleType = OutputDescriptor::OneSamplePerStep;
+    list.push_back(d);
+#endif
+
     return list;
 }
 
 Tempo::FeatureSet
-Tempo::process(float **inputBuffers, Vamp::RealTime timestamp)
+Tempo::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) {
@@ -238,8 +258,16 @@ Tempo::process(float **inputBuffers, Vamp::RealTime timestamp)
     aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
     aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
 
+#ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK
+    float locked_tempo = 0;
+#endif
+
     if ( m_btcounter == m_btstep - 1 ) {
+#ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK
+        aubio_beattracking_do(m_beattracking,m_dfframe,m_btout,&locked_tempo);
+#else
         aubio_beattracking_do(m_beattracking,m_dfframe,m_btout);
+#endif
         /* rotate dfframe */
         for (size_t i = 0 ; i < m_winlen - m_btstep; i++ ) 
                 m_dfframe->data[0][i] = m_dfframe->data[0][i+m_btstep];
@@ -253,7 +281,6 @@ Tempo::process(float **inputBuffers, Vamp::RealTime timestamp)
         &(m_dfframe->data[0][m_winlen - m_btstep + m_btcounter]));
     bool istactus = 0;
 
-
     /* check if any of the predicted beat correspond to the current time */
     for (size_t i = 1; i < m_btout->data[0][0]; i++ ) { 
             if (m_btcounter == m_btout->data[0][i]) {
@@ -279,6 +306,17 @@ Tempo::process(float **inputBuffers, Vamp::RealTime timestamp)
         }
     }
 
+#ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK
+    if (locked_tempo >= 30 && locked_tempo <= 206) {
+        if (locked_tempo > 145) locked_tempo /= 2;
+        std::cerr << "Locked tempo: " << locked_tempo << std::endl;
+        Feature tempo;
+        tempo.hasTimestamp = false;
+        tempo.values.push_back(locked_tempo);
+        returnFeatures[1].push_back(tempo);
+    }
+#endif
+
     return returnFeatures;
 }