mirror of
https://github.com/cookiengineer/audacity
synced 2026-04-25 07:23:44 +02:00
Move library tree where it belongs
This commit is contained in:
247
lib-src/libvamp/examples/AmplitudeFollower.cpp
Normal file
247
lib-src/libvamp/examples/AmplitudeFollower.cpp
Normal file
@@ -0,0 +1,247 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
This file copyright 2006 Dan Stowell.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#include "AmplitudeFollower.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
/**
|
||||
* An implementation of SuperCollider's amplitude-follower algorithm
|
||||
* as a simple Vamp plugin.
|
||||
*/
|
||||
|
||||
AmplitudeFollower::AmplitudeFollower(float inputSampleRate) :
|
||||
Plugin(inputSampleRate),
|
||||
m_stepSize(0),
|
||||
m_previn(0.0f),
|
||||
m_clampcoef(0.01f),
|
||||
m_relaxcoef(0.01f)
|
||||
{
|
||||
}
|
||||
|
||||
AmplitudeFollower::~AmplitudeFollower()
|
||||
{
|
||||
}
|
||||
|
||||
string
|
||||
AmplitudeFollower::getIdentifier() const
|
||||
{
|
||||
return "amplitudefollower";
|
||||
}
|
||||
|
||||
string
|
||||
AmplitudeFollower::getName() const
|
||||
{
|
||||
return "Amplitude Follower";
|
||||
}
|
||||
|
||||
string
|
||||
AmplitudeFollower::getDescription() const
|
||||
{
|
||||
return "Track the amplitude of the audio signal";
|
||||
}
|
||||
|
||||
string
|
||||
AmplitudeFollower::getMaker() const
|
||||
{
|
||||
return "Vamp SDK Example Plugins";
|
||||
}
|
||||
|
||||
int
|
||||
AmplitudeFollower::getPluginVersion() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
string
|
||||
AmplitudeFollower::getCopyright() const
|
||||
{
|
||||
return "Code copyright 2006 Dan Stowell; method from SuperCollider. Freely redistributable (BSD license)";
|
||||
}
|
||||
|
||||
bool
|
||||
AmplitudeFollower::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if (channels < getMinChannelCount() ||
|
||||
channels > getMaxChannelCount()) return false;
|
||||
|
||||
m_stepSize = std::min(stepSize, blockSize);
|
||||
|
||||
// Translate the coefficients
|
||||
// from their "convenient" 60dB convergence-time values
|
||||
// to real coefficients
|
||||
m_clampcoef = m_clampcoef==0.0 ? 0.0 : exp(log(0.1)/(m_clampcoef * m_inputSampleRate));
|
||||
m_relaxcoef = m_relaxcoef==0.0 ? 0.0 : exp(log(0.1)/(m_relaxcoef * m_inputSampleRate));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
AmplitudeFollower::reset()
|
||||
{
|
||||
m_previn = 0.0f;
|
||||
}
|
||||
|
||||
AmplitudeFollower::OutputList
|
||||
AmplitudeFollower::getOutputDescriptors() const
|
||||
{
|
||||
OutputList list;
|
||||
|
||||
OutputDescriptor sca;
|
||||
sca.identifier = "amplitude";
|
||||
sca.name = "Amplitude";
|
||||
sca.description = "";
|
||||
sca.unit = "V";
|
||||
sca.hasFixedBinCount = true;
|
||||
sca.binCount = 1;
|
||||
sca.hasKnownExtents = false;
|
||||
sca.isQuantized = false;
|
||||
sca.sampleType = OutputDescriptor::OneSamplePerStep;
|
||||
list.push_back(sca);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
AmplitudeFollower::ParameterList
|
||||
AmplitudeFollower::getParameterDescriptors() const
|
||||
{
|
||||
ParameterList list;
|
||||
|
||||
ParameterDescriptor att;
|
||||
att.identifier = "attack";
|
||||
att.name = "Attack time";
|
||||
att.description = "";
|
||||
att.unit = "s";
|
||||
att.minValue = 0.0f;
|
||||
att.maxValue = 1.f;
|
||||
att.defaultValue = 0.01f;
|
||||
att.isQuantized = false;
|
||||
|
||||
list.push_back(att);
|
||||
|
||||
ParameterDescriptor dec;
|
||||
dec.identifier = "release";
|
||||
dec.name = "Release time";
|
||||
dec.description = "";
|
||||
dec.unit = "s";
|
||||
dec.minValue = 0.0f;
|
||||
dec.maxValue = 1.f;
|
||||
dec.defaultValue = 0.01f;
|
||||
dec.isQuantized = false;
|
||||
|
||||
list.push_back(dec);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void AmplitudeFollower::setParameter(std::string paramid, float newval)
|
||||
{
|
||||
if (paramid == "attack") {
|
||||
m_clampcoef = newval;
|
||||
} else if (paramid == "release") {
|
||||
m_relaxcoef = newval;
|
||||
}
|
||||
}
|
||||
|
||||
float AmplitudeFollower::getParameter(std::string paramid) const
|
||||
{
|
||||
if (paramid == "attack") {
|
||||
return m_clampcoef;
|
||||
} else if (paramid == "release") {
|
||||
return m_relaxcoef;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
AmplitudeFollower::FeatureSet
|
||||
AmplitudeFollower::process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp)
|
||||
{
|
||||
if (m_stepSize == 0) {
|
||||
cerr << "ERROR: AmplitudeFollower::process: "
|
||||
<< "AmplitudeFollower has not been initialised"
|
||||
<< endl;
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
float previn = m_previn;
|
||||
|
||||
FeatureSet returnFeatures;
|
||||
|
||||
float val;
|
||||
float peak = 0.0f;
|
||||
|
||||
for (size_t i = 0; i < m_stepSize; ++i) {
|
||||
|
||||
val = fabs(inputBuffers[0][i]);
|
||||
|
||||
if (val < previn) {
|
||||
val = val + (previn - val) * m_relaxcoef;
|
||||
} else {
|
||||
val = val + (previn - val) * m_clampcoef;
|
||||
}
|
||||
|
||||
if (val > peak) peak = val;
|
||||
previn = val;
|
||||
}
|
||||
|
||||
m_previn = previn;
|
||||
|
||||
// Now store the "feature" (peak amp) for this sample
|
||||
Feature feature;
|
||||
feature.hasTimestamp = false;
|
||||
feature.values.push_back(peak);
|
||||
returnFeatures[0].push_back(feature);
|
||||
|
||||
return returnFeatures;
|
||||
}
|
||||
|
||||
AmplitudeFollower::FeatureSet
|
||||
AmplitudeFollower::getRemainingFeatures()
|
||||
{
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
84
lib-src/libvamp/examples/AmplitudeFollower.h
Normal file
84
lib-src/libvamp/examples/AmplitudeFollower.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
This file copyright 2006 Dan Stowell.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#ifndef _AMPLITUDE_FOLLOWER_PLUGIN_H_
|
||||
#define _AMPLITUDE_FOLLOWER_PLUGIN_H_
|
||||
|
||||
#include "vamp-sdk/Plugin.h"
|
||||
|
||||
/**
|
||||
* Example plugin implementing the SuperCollider amplitude follower
|
||||
* function.
|
||||
*/
|
||||
|
||||
class AmplitudeFollower : public Vamp::Plugin
|
||||
{
|
||||
public:
|
||||
AmplitudeFollower(float inputSampleRate);
|
||||
virtual ~AmplitudeFollower();
|
||||
|
||||
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
||||
void reset();
|
||||
|
||||
InputDomain getInputDomain() const { return TimeDomain; }
|
||||
|
||||
std::string getIdentifier() const;
|
||||
std::string getName() const;
|
||||
std::string getDescription() const;
|
||||
std::string getMaker() const;
|
||||
int getPluginVersion() const;
|
||||
std::string getCopyright() const;
|
||||
|
||||
OutputList getOutputDescriptors() const;
|
||||
|
||||
ParameterList getParameterDescriptors() const;
|
||||
float getParameter(std::string paramid) const;
|
||||
void setParameter(std::string paramid, float newval);
|
||||
|
||||
FeatureSet process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp);
|
||||
|
||||
FeatureSet getRemainingFeatures();
|
||||
|
||||
protected:
|
||||
size_t m_stepSize;
|
||||
float m_previn;
|
||||
float m_clampcoef;
|
||||
float m_relaxcoef;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
724
lib-src/libvamp/examples/FixedTempoEstimator.cpp
Normal file
724
lib-src/libvamp/examples/FixedTempoEstimator.cpp
Normal file
@@ -0,0 +1,724 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006-2008 Chris Cannam and QMUL.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#include "FixedTempoEstimator.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
using Vamp::RealTime;
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
class FixedTempoEstimator::D
|
||||
// this class just avoids us having to declare any data members in the header
|
||||
{
|
||||
public:
|
||||
D(float inputSampleRate);
|
||||
~D();
|
||||
|
||||
size_t getPreferredStepSize() const { return 64; }
|
||||
size_t getPreferredBlockSize() const { return 256; }
|
||||
|
||||
ParameterList getParameterDescriptors() const;
|
||||
float getParameter(string id) const;
|
||||
void setParameter(string id, float value);
|
||||
|
||||
OutputList getOutputDescriptors() const;
|
||||
|
||||
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
||||
void reset();
|
||||
FeatureSet process(const float *const *, RealTime);
|
||||
FeatureSet getRemainingFeatures();
|
||||
|
||||
private:
|
||||
void calculate();
|
||||
FeatureSet assembleFeatures();
|
||||
|
||||
float lag2tempo(int);
|
||||
int tempo2lag(float);
|
||||
|
||||
float m_inputSampleRate;
|
||||
size_t m_stepSize;
|
||||
size_t m_blockSize;
|
||||
|
||||
float m_minbpm;
|
||||
float m_maxbpm;
|
||||
float m_maxdflen;
|
||||
|
||||
float *m_priorMagnitudes;
|
||||
|
||||
size_t m_dfsize;
|
||||
float *m_df;
|
||||
float *m_r;
|
||||
float *m_fr;
|
||||
float *m_t;
|
||||
size_t m_n;
|
||||
|
||||
Vamp::RealTime m_start;
|
||||
Vamp::RealTime m_lasttime;
|
||||
};
|
||||
|
||||
FixedTempoEstimator::D::D(float inputSampleRate) :
|
||||
m_inputSampleRate(inputSampleRate),
|
||||
m_stepSize(0),
|
||||
m_blockSize(0),
|
||||
m_minbpm(50),
|
||||
m_maxbpm(190),
|
||||
m_maxdflen(10),
|
||||
m_priorMagnitudes(0),
|
||||
m_df(0),
|
||||
m_r(0),
|
||||
m_fr(0),
|
||||
m_t(0),
|
||||
m_n(0)
|
||||
{
|
||||
}
|
||||
|
||||
FixedTempoEstimator::D::~D()
|
||||
{
|
||||
delete[] m_priorMagnitudes;
|
||||
delete[] m_df;
|
||||
delete[] m_r;
|
||||
delete[] m_fr;
|
||||
delete[] m_t;
|
||||
}
|
||||
|
||||
FixedTempoEstimator::ParameterList
|
||||
FixedTempoEstimator::D::getParameterDescriptors() const
|
||||
{
|
||||
ParameterList list;
|
||||
|
||||
ParameterDescriptor d;
|
||||
d.identifier = "minbpm";
|
||||
d.name = "Minimum estimated tempo";
|
||||
d.description = "Minimum beat-per-minute value which the tempo estimator is able to return";
|
||||
d.unit = "bpm";
|
||||
d.minValue = 10;
|
||||
d.maxValue = 360;
|
||||
d.defaultValue = 50;
|
||||
d.isQuantized = false;
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "maxbpm";
|
||||
d.name = "Maximum estimated tempo";
|
||||
d.description = "Maximum beat-per-minute value which the tempo estimator is able to return";
|
||||
d.defaultValue = 190;
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "maxdflen";
|
||||
d.name = "Input duration to study";
|
||||
d.description = "Length of audio input, in seconds, which should be taken into account when estimating tempo. There is no need to supply the plugin with any further input once this time has elapsed since the start of the audio. The tempo estimator may use only the first part of this, up to eight times the slowest beat duration: increasing this value further than that is unlikely to improve results.";
|
||||
d.unit = "s";
|
||||
d.minValue = 2;
|
||||
d.maxValue = 40;
|
||||
d.defaultValue = 10;
|
||||
list.push_back(d);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
float
|
||||
FixedTempoEstimator::D::getParameter(string id) const
|
||||
{
|
||||
if (id == "minbpm") {
|
||||
return m_minbpm;
|
||||
} else if (id == "maxbpm") {
|
||||
return m_maxbpm;
|
||||
} else if (id == "maxdflen") {
|
||||
return m_maxdflen;
|
||||
}
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
void
|
||||
FixedTempoEstimator::D::setParameter(string id, float value)
|
||||
{
|
||||
if (id == "minbpm") {
|
||||
m_minbpm = value;
|
||||
} else if (id == "maxbpm") {
|
||||
m_maxbpm = value;
|
||||
} else if (id == "maxdflen") {
|
||||
m_maxdflen = value;
|
||||
}
|
||||
}
|
||||
|
||||
static int TempoOutput = 0;
|
||||
static int CandidatesOutput = 1;
|
||||
static int DFOutput = 2;
|
||||
static int ACFOutput = 3;
|
||||
static int FilteredACFOutput = 4;
|
||||
|
||||
FixedTempoEstimator::OutputList
|
||||
FixedTempoEstimator::D::getOutputDescriptors() const
|
||||
{
|
||||
OutputList list;
|
||||
|
||||
OutputDescriptor d;
|
||||
d.identifier = "tempo";
|
||||
d.name = "Tempo";
|
||||
d.description = "Estimated tempo";
|
||||
d.unit = "bpm";
|
||||
d.hasFixedBinCount = true;
|
||||
d.binCount = 1;
|
||||
d.hasKnownExtents = false;
|
||||
d.isQuantized = false;
|
||||
d.sampleType = OutputDescriptor::VariableSampleRate;
|
||||
d.sampleRate = m_inputSampleRate;
|
||||
d.hasDuration = true; // our returned tempo spans a certain range
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "candidates";
|
||||
d.name = "Tempo candidates";
|
||||
d.description = "Possible tempo estimates, one per bin with the most likely in the first bin";
|
||||
d.unit = "bpm";
|
||||
d.hasFixedBinCount = false;
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "detectionfunction";
|
||||
d.name = "Detection Function";
|
||||
d.description = "Onset detection function";
|
||||
d.unit = "";
|
||||
d.hasFixedBinCount = 1;
|
||||
d.binCount = 1;
|
||||
d.hasKnownExtents = true;
|
||||
d.minValue = 0.0;
|
||||
d.maxValue = 1.0;
|
||||
d.isQuantized = false;
|
||||
d.quantizeStep = 0.0;
|
||||
d.sampleType = OutputDescriptor::FixedSampleRate;
|
||||
if (m_stepSize) {
|
||||
d.sampleRate = m_inputSampleRate / m_stepSize;
|
||||
} else {
|
||||
d.sampleRate = m_inputSampleRate / (getPreferredBlockSize()/2);
|
||||
}
|
||||
d.hasDuration = false;
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "acf";
|
||||
d.name = "Autocorrelation Function";
|
||||
d.description = "Autocorrelation of onset detection function";
|
||||
d.hasKnownExtents = false;
|
||||
d.unit = "r";
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "filtered_acf";
|
||||
d.name = "Filtered Autocorrelation";
|
||||
d.description = "Filtered autocorrelation of onset detection function";
|
||||
d.unit = "r";
|
||||
list.push_back(d);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool
|
||||
FixedTempoEstimator::D::initialise(size_t, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
m_stepSize = stepSize;
|
||||
m_blockSize = blockSize;
|
||||
|
||||
float dfLengthSecs = m_maxdflen;
|
||||
m_dfsize = (dfLengthSecs * m_inputSampleRate) / m_stepSize;
|
||||
|
||||
m_priorMagnitudes = new float[m_blockSize/2];
|
||||
m_df = new float[m_dfsize];
|
||||
|
||||
for (size_t i = 0; i < m_blockSize/2; ++i) {
|
||||
m_priorMagnitudes[i] = 0.f;
|
||||
}
|
||||
for (size_t i = 0; i < m_dfsize; ++i) {
|
||||
m_df[i] = 0.f;
|
||||
}
|
||||
|
||||
m_n = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
FixedTempoEstimator::D::reset()
|
||||
{
|
||||
if (!m_priorMagnitudes) return;
|
||||
|
||||
for (size_t i = 0; i < m_blockSize/2; ++i) {
|
||||
m_priorMagnitudes[i] = 0.f;
|
||||
}
|
||||
for (size_t i = 0; i < m_dfsize; ++i) {
|
||||
m_df[i] = 0.f;
|
||||
}
|
||||
|
||||
delete[] m_r;
|
||||
m_r = 0;
|
||||
|
||||
delete[] m_fr;
|
||||
m_fr = 0;
|
||||
|
||||
delete[] m_t;
|
||||
m_t = 0;
|
||||
|
||||
m_n = 0;
|
||||
|
||||
m_start = RealTime::zeroTime;
|
||||
m_lasttime = RealTime::zeroTime;
|
||||
}
|
||||
|
||||
FixedTempoEstimator::FeatureSet
|
||||
FixedTempoEstimator::D::process(const float *const *inputBuffers, RealTime ts)
|
||||
{
|
||||
FeatureSet fs;
|
||||
|
||||
if (m_stepSize == 0) {
|
||||
cerr << "ERROR: FixedTempoEstimator::process: "
|
||||
<< "FixedTempoEstimator has not been initialised"
|
||||
<< endl;
|
||||
return fs;
|
||||
}
|
||||
|
||||
if (m_n == 0) m_start = ts;
|
||||
m_lasttime = ts;
|
||||
|
||||
if (m_n == m_dfsize) {
|
||||
// If we have seen enough input, do the estimation and return
|
||||
calculate();
|
||||
fs = assembleFeatures();
|
||||
++m_n;
|
||||
return fs;
|
||||
}
|
||||
|
||||
// If we have seen more than enough, just discard and return!
|
||||
if (m_n > m_dfsize) return FeatureSet();
|
||||
|
||||
float value = 0.f;
|
||||
|
||||
// m_df will contain an onset detection function based on the rise
|
||||
// in overall power from one spectral frame to the next --
|
||||
// simplistic but reasonably effective for our purposes.
|
||||
|
||||
for (size_t i = 1; i < m_blockSize/2; ++i) {
|
||||
|
||||
float real = inputBuffers[0][i*2];
|
||||
float imag = inputBuffers[0][i*2 + 1];
|
||||
|
||||
float sqrmag = real * real + imag * imag;
|
||||
value += fabsf(sqrmag - m_priorMagnitudes[i]);
|
||||
|
||||
m_priorMagnitudes[i] = sqrmag;
|
||||
}
|
||||
|
||||
m_df[m_n] = value;
|
||||
|
||||
++m_n;
|
||||
return fs;
|
||||
}
|
||||
|
||||
FixedTempoEstimator::FeatureSet
|
||||
FixedTempoEstimator::D::getRemainingFeatures()
|
||||
{
|
||||
FeatureSet fs;
|
||||
if (m_n > m_dfsize) return fs;
|
||||
calculate();
|
||||
fs = assembleFeatures();
|
||||
++m_n;
|
||||
return fs;
|
||||
}
|
||||
|
||||
float
|
||||
FixedTempoEstimator::D::lag2tempo(int lag)
|
||||
{
|
||||
return 60.f / ((lag * m_stepSize) / m_inputSampleRate);
|
||||
}
|
||||
|
||||
int
|
||||
FixedTempoEstimator::D::tempo2lag(float tempo)
|
||||
{
|
||||
return ((60.f / tempo) * m_inputSampleRate) / m_stepSize;
|
||||
}
|
||||
|
||||
void
|
||||
FixedTempoEstimator::D::calculate()
|
||||
{
|
||||
if (m_r) {
|
||||
cerr << "FixedTempoEstimator::calculate: calculation already happened?" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_n < m_dfsize / 9 &&
|
||||
m_n < (1.0 * m_inputSampleRate) / m_stepSize) { // 1 second
|
||||
cerr << "FixedTempoEstimator::calculate: Input is too short" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// This function takes m_df (the detection function array filled
|
||||
// out in process()) and calculates m_r (the raw autocorrelation)
|
||||
// and m_fr (the filtered autocorrelation from whose peaks tempo
|
||||
// estimates will be taken).
|
||||
|
||||
int n = m_n; // length of actual df array (m_dfsize is the theoretical max)
|
||||
|
||||
m_r = new float[n/2]; // raw autocorrelation
|
||||
m_fr = new float[n/2]; // filtered autocorrelation
|
||||
m_t = new float[n/2]; // averaged tempo estimate for each lag value
|
||||
|
||||
for (int i = 0; i < n/2; ++i) {
|
||||
m_r[i] = 0.f;
|
||||
m_fr[i] = 0.f;
|
||||
m_t[i] = lag2tempo(i);
|
||||
}
|
||||
|
||||
// Calculate the raw autocorrelation of the detection function
|
||||
|
||||
for (int i = 0; i < n/2; ++i) {
|
||||
|
||||
for (int j = i; j < n; ++j) {
|
||||
m_r[i] += m_df[j] * m_df[j - i];
|
||||
}
|
||||
|
||||
m_r[i] /= n - i - 1;
|
||||
}
|
||||
|
||||
// Filter the autocorrelation and average out the tempo estimates
|
||||
|
||||
float related[] = { 0.5, 2, 4, 8 };
|
||||
|
||||
for (int i = 1; i < n/2-1; ++i) {
|
||||
|
||||
m_fr[i] = m_r[i];
|
||||
|
||||
int div = 1;
|
||||
|
||||
for (int j = 0; j < int(sizeof(related)/sizeof(related[0])); ++j) {
|
||||
|
||||
// Check for an obvious peak at each metrically related lag
|
||||
|
||||
int k0 = int(i * related[j] + 0.5);
|
||||
|
||||
if (k0 >= 0 && k0 < int(n/2)) {
|
||||
|
||||
int kmax = 0, kmin = 0;
|
||||
float kvmax = 0, kvmin = 0;
|
||||
bool have = false;
|
||||
|
||||
for (int k = k0 - 1; k <= k0 + 1; ++k) {
|
||||
|
||||
if (k < 0 || k >= n/2) continue;
|
||||
|
||||
if (!have || (m_r[k] > kvmax)) { kmax = k; kvmax = m_r[k]; }
|
||||
if (!have || (m_r[k] < kvmin)) { kmin = k; kvmin = m_r[k]; }
|
||||
|
||||
have = true;
|
||||
}
|
||||
|
||||
// Boost the original lag according to the strongest
|
||||
// value found close to this related lag
|
||||
|
||||
m_fr[i] += m_r[kmax] / 5;
|
||||
|
||||
if ((kmax == 0 || m_r[kmax] > m_r[kmax-1]) &&
|
||||
(kmax == n/2-1 || m_r[kmax] > m_r[kmax+1]) &&
|
||||
kvmax > kvmin * 1.05) {
|
||||
|
||||
// The strongest value close to the related lag is
|
||||
// also a pretty good looking peak, so use it to
|
||||
// improve our tempo estimate for the original lag
|
||||
|
||||
m_t[i] = m_t[i] + lag2tempo(kmax) * related[j];
|
||||
++div;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_t[i] /= div;
|
||||
|
||||
// Finally apply a primitive perceptual weighting (to prefer
|
||||
// tempi of around 120-130)
|
||||
|
||||
float weight = 1.f - fabsf(128.f - lag2tempo(i)) * 0.005;
|
||||
if (weight < 0.f) weight = 0.f;
|
||||
weight = weight * weight * weight;
|
||||
|
||||
m_fr[i] += m_fr[i] * (weight / 3);
|
||||
}
|
||||
}
|
||||
|
||||
FixedTempoEstimator::FeatureSet
|
||||
FixedTempoEstimator::D::assembleFeatures()
|
||||
{
|
||||
FeatureSet fs;
|
||||
if (!m_r) return fs; // No autocorrelation: no results
|
||||
|
||||
Feature feature;
|
||||
feature.hasTimestamp = true;
|
||||
feature.hasDuration = false;
|
||||
feature.label = "";
|
||||
feature.values.clear();
|
||||
feature.values.push_back(0.f);
|
||||
|
||||
char buffer[40];
|
||||
|
||||
int n = m_n;
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
|
||||
// Return the detection function in the DF output
|
||||
|
||||
feature.timestamp = m_start +
|
||||
RealTime::frame2RealTime(i * m_stepSize, m_inputSampleRate);
|
||||
feature.values[0] = m_df[i];
|
||||
feature.label = "";
|
||||
fs[DFOutput].push_back(feature);
|
||||
}
|
||||
|
||||
for (int i = 1; i < n/2; ++i) {
|
||||
|
||||
// Return the raw autocorrelation in the ACF output, each
|
||||
// value labelled according to its corresponding tempo
|
||||
|
||||
feature.timestamp = m_start +
|
||||
RealTime::frame2RealTime(i * m_stepSize, m_inputSampleRate);
|
||||
feature.values[0] = m_r[i];
|
||||
sprintf(buffer, "%.1f bpm", lag2tempo(i));
|
||||
if (i == n/2-1) feature.label = "";
|
||||
else feature.label = buffer;
|
||||
fs[ACFOutput].push_back(feature);
|
||||
}
|
||||
|
||||
float t0 = m_minbpm; // our minimum detected tempo
|
||||
float t1 = m_maxbpm; // our maximum detected tempo
|
||||
|
||||
int p0 = tempo2lag(t1);
|
||||
int p1 = tempo2lag(t0);
|
||||
|
||||
std::map<float, int> candidates;
|
||||
|
||||
for (int i = p0; i <= p1 && i+1 < n/2; ++i) {
|
||||
|
||||
if (m_fr[i] > m_fr[i-1] &&
|
||||
m_fr[i] > m_fr[i+1]) {
|
||||
|
||||
// This is a peak in the filtered autocorrelation: stick
|
||||
// it into the map from filtered autocorrelation to lag
|
||||
// index -- this sorts our peaks by filtered acf value
|
||||
|
||||
candidates[m_fr[i]] = i;
|
||||
}
|
||||
|
||||
// Also return the filtered autocorrelation in its own output
|
||||
|
||||
feature.timestamp = m_start +
|
||||
RealTime::frame2RealTime(i * m_stepSize, m_inputSampleRate);
|
||||
feature.values[0] = m_fr[i];
|
||||
sprintf(buffer, "%.1f bpm", lag2tempo(i));
|
||||
if (i == p1 || i == n/2-2) feature.label = "";
|
||||
else feature.label = buffer;
|
||||
fs[FilteredACFOutput].push_back(feature);
|
||||
}
|
||||
|
||||
if (candidates.empty()) {
|
||||
cerr << "No tempo candidates!" << endl;
|
||||
return fs;
|
||||
}
|
||||
|
||||
feature.hasTimestamp = true;
|
||||
feature.timestamp = m_start;
|
||||
|
||||
feature.hasDuration = true;
|
||||
feature.duration = m_lasttime - m_start;
|
||||
|
||||
// The map contains only peaks and is sorted by filtered acf
|
||||
// value, so the final element in it is our "best" tempo guess
|
||||
|
||||
std::map<float, int>::const_iterator ci = candidates.end();
|
||||
--ci;
|
||||
int maxpi = ci->second;
|
||||
|
||||
if (m_t[maxpi] > 0) {
|
||||
|
||||
// This lag has an adjusted tempo from the averaging process:
|
||||
// use it
|
||||
|
||||
feature.values[0] = m_t[maxpi];
|
||||
|
||||
} else {
|
||||
|
||||
// shouldn't happen -- it would imply that this high value was
|
||||
// not a peak!
|
||||
|
||||
feature.values[0] = lag2tempo(maxpi);
|
||||
cerr << "WARNING: No stored tempo for index " << maxpi << endl;
|
||||
}
|
||||
|
||||
sprintf(buffer, "%.1f bpm", feature.values[0]);
|
||||
feature.label = buffer;
|
||||
|
||||
// Return the best tempo in the main output
|
||||
|
||||
fs[TempoOutput].push_back(feature);
|
||||
|
||||
// And return the other estimates (up to the arbitrarily chosen
|
||||
// number of 10 of them) in the candidates output
|
||||
|
||||
feature.values.clear();
|
||||
feature.label = "";
|
||||
|
||||
while (feature.values.size() < 10) {
|
||||
if (m_t[ci->second] > 0) {
|
||||
feature.values.push_back(m_t[ci->second]);
|
||||
} else {
|
||||
feature.values.push_back(lag2tempo(ci->second));
|
||||
}
|
||||
if (ci == candidates.begin()) break;
|
||||
--ci;
|
||||
}
|
||||
|
||||
fs[CandidatesOutput].push_back(feature);
|
||||
|
||||
return fs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
FixedTempoEstimator::FixedTempoEstimator(float inputSampleRate) :
|
||||
Plugin(inputSampleRate),
|
||||
m_d(new D(inputSampleRate))
|
||||
{
|
||||
}
|
||||
|
||||
FixedTempoEstimator::~FixedTempoEstimator()
|
||||
{
|
||||
delete m_d;
|
||||
}
|
||||
|
||||
string
|
||||
FixedTempoEstimator::getIdentifier() const
|
||||
{
|
||||
return "fixedtempo";
|
||||
}
|
||||
|
||||
string
|
||||
FixedTempoEstimator::getName() const
|
||||
{
|
||||
return "Simple Fixed Tempo Estimator";
|
||||
}
|
||||
|
||||
string
|
||||
FixedTempoEstimator::getDescription() const
|
||||
{
|
||||
return "Study a short section of audio and estimate its tempo, assuming the tempo is constant";
|
||||
}
|
||||
|
||||
string
|
||||
FixedTempoEstimator::getMaker() const
|
||||
{
|
||||
return "Vamp SDK Example Plugins";
|
||||
}
|
||||
|
||||
int
|
||||
FixedTempoEstimator::getPluginVersion() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
string
|
||||
FixedTempoEstimator::getCopyright() const
|
||||
{
|
||||
return "Code copyright 2008 Queen Mary, University of London. Freely redistributable (BSD license)";
|
||||
}
|
||||
|
||||
size_t
|
||||
FixedTempoEstimator::getPreferredStepSize() const
|
||||
{
|
||||
return m_d->getPreferredStepSize();
|
||||
}
|
||||
|
||||
size_t
|
||||
FixedTempoEstimator::getPreferredBlockSize() const
|
||||
{
|
||||
return m_d->getPreferredBlockSize();
|
||||
}
|
||||
|
||||
bool
|
||||
FixedTempoEstimator::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if (channels < getMinChannelCount() ||
|
||||
channels > getMaxChannelCount()) return false;
|
||||
|
||||
return m_d->initialise(channels, stepSize, blockSize);
|
||||
}
|
||||
|
||||
void
|
||||
FixedTempoEstimator::reset()
|
||||
{
|
||||
return m_d->reset();
|
||||
}
|
||||
|
||||
FixedTempoEstimator::ParameterList
|
||||
FixedTempoEstimator::getParameterDescriptors() const
|
||||
{
|
||||
return m_d->getParameterDescriptors();
|
||||
}
|
||||
|
||||
float
|
||||
FixedTempoEstimator::getParameter(std::string id) const
|
||||
{
|
||||
return m_d->getParameter(id);
|
||||
}
|
||||
|
||||
void
|
||||
FixedTempoEstimator::setParameter(std::string id, float value)
|
||||
{
|
||||
m_d->setParameter(id, value);
|
||||
}
|
||||
|
||||
FixedTempoEstimator::OutputList
|
||||
FixedTempoEstimator::getOutputDescriptors() const
|
||||
{
|
||||
return m_d->getOutputDescriptors();
|
||||
}
|
||||
|
||||
FixedTempoEstimator::FeatureSet
|
||||
FixedTempoEstimator::process(const float *const *inputBuffers, RealTime ts)
|
||||
{
|
||||
return m_d->process(inputBuffers, ts);
|
||||
}
|
||||
|
||||
FixedTempoEstimator::FeatureSet
|
||||
FixedTempoEstimator::getRemainingFeatures()
|
||||
{
|
||||
return m_d->getRemainingFeatures();
|
||||
}
|
||||
84
lib-src/libvamp/examples/FixedTempoEstimator.h
Normal file
84
lib-src/libvamp/examples/FixedTempoEstimator.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006-2008 Chris Cannam and QMUL.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#ifndef _FIXED_TEMPO_ESTIMATOR_PLUGIN_H_
|
||||
#define _FIXED_TEMPO_ESTIMATOR_PLUGIN_H_
|
||||
|
||||
#include "vamp-sdk/Plugin.h"
|
||||
|
||||
/**
|
||||
* Example plugin that estimates the tempo of a short fixed-tempo sample.
|
||||
*/
|
||||
|
||||
class FixedTempoEstimator : public Vamp::Plugin
|
||||
{
|
||||
public:
|
||||
FixedTempoEstimator(float inputSampleRate);
|
||||
virtual ~FixedTempoEstimator();
|
||||
|
||||
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
||||
void reset();
|
||||
|
||||
InputDomain getInputDomain() const { return FrequencyDomain; }
|
||||
|
||||
std::string getIdentifier() const;
|
||||
std::string getName() const;
|
||||
std::string getDescription() const;
|
||||
std::string getMaker() const;
|
||||
int getPluginVersion() const;
|
||||
std::string getCopyright() const;
|
||||
|
||||
size_t getPreferredStepSize() const;
|
||||
size_t getPreferredBlockSize() const;
|
||||
|
||||
ParameterList getParameterDescriptors() const;
|
||||
float getParameter(std::string id) const;
|
||||
void setParameter(std::string id, float value);
|
||||
|
||||
OutputList getOutputDescriptors() const;
|
||||
|
||||
FeatureSet process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp);
|
||||
|
||||
FeatureSet getRemainingFeatures();
|
||||
|
||||
protected:
|
||||
class D;
|
||||
D *m_d;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
287
lib-src/libvamp/examples/PercussionOnsetDetector.cpp
Normal file
287
lib-src/libvamp/examples/PercussionOnsetDetector.cpp
Normal file
@@ -0,0 +1,287 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#include "PercussionOnsetDetector.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
PercussionOnsetDetector::PercussionOnsetDetector(float inputSampleRate) :
|
||||
Plugin(inputSampleRate),
|
||||
m_stepSize(0),
|
||||
m_blockSize(0),
|
||||
m_threshold(3),
|
||||
m_sensitivity(40),
|
||||
m_priorMagnitudes(0),
|
||||
m_dfMinus1(0),
|
||||
m_dfMinus2(0)
|
||||
{
|
||||
}
|
||||
|
||||
PercussionOnsetDetector::~PercussionOnsetDetector()
|
||||
{
|
||||
delete[] m_priorMagnitudes;
|
||||
}
|
||||
|
||||
string
|
||||
PercussionOnsetDetector::getIdentifier() const
|
||||
{
|
||||
return "percussiononsets";
|
||||
}
|
||||
|
||||
string
|
||||
PercussionOnsetDetector::getName() const
|
||||
{
|
||||
return "Simple Percussion Onset Detector";
|
||||
}
|
||||
|
||||
string
|
||||
PercussionOnsetDetector::getDescription() const
|
||||
{
|
||||
return "Detect percussive note onsets by identifying broadband energy rises";
|
||||
}
|
||||
|
||||
string
|
||||
PercussionOnsetDetector::getMaker() const
|
||||
{
|
||||
return "Vamp SDK Example Plugins";
|
||||
}
|
||||
|
||||
int
|
||||
PercussionOnsetDetector::getPluginVersion() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
string
|
||||
PercussionOnsetDetector::getCopyright() const
|
||||
{
|
||||
return "Code copyright 2006 Queen Mary, University of London, after Dan Barry et al 2005. Freely redistributable (BSD license)";
|
||||
}
|
||||
|
||||
size_t
|
||||
PercussionOnsetDetector::getPreferredStepSize() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
PercussionOnsetDetector::getPreferredBlockSize() const
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
|
||||
bool
|
||||
PercussionOnsetDetector::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if (channels < getMinChannelCount() ||
|
||||
channels > getMaxChannelCount()) return false;
|
||||
|
||||
m_stepSize = stepSize;
|
||||
m_blockSize = blockSize;
|
||||
|
||||
m_priorMagnitudes = new float[m_blockSize/2];
|
||||
|
||||
for (size_t i = 0; i < m_blockSize/2; ++i) {
|
||||
m_priorMagnitudes[i] = 0.f;
|
||||
}
|
||||
|
||||
m_dfMinus1 = 0.f;
|
||||
m_dfMinus2 = 0.f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
PercussionOnsetDetector::reset()
|
||||
{
|
||||
for (size_t i = 0; i < m_blockSize/2; ++i) {
|
||||
m_priorMagnitudes[i] = 0.f;
|
||||
}
|
||||
|
||||
m_dfMinus1 = 0.f;
|
||||
m_dfMinus2 = 0.f;
|
||||
}
|
||||
|
||||
PercussionOnsetDetector::ParameterList
|
||||
PercussionOnsetDetector::getParameterDescriptors() const
|
||||
{
|
||||
ParameterList list;
|
||||
|
||||
ParameterDescriptor d;
|
||||
d.identifier = "threshold";
|
||||
d.name = "Energy rise threshold";
|
||||
d.description = "Energy rise within a frequency bin necessary to count toward broadband total";
|
||||
d.unit = "dB";
|
||||
d.minValue = 0;
|
||||
d.maxValue = 20;
|
||||
d.defaultValue = 3;
|
||||
d.isQuantized = false;
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "sensitivity";
|
||||
d.name = "Sensitivity";
|
||||
d.description = "Sensitivity of peak detector applied to broadband detection function";
|
||||
d.unit = "%";
|
||||
d.minValue = 0;
|
||||
d.maxValue = 100;
|
||||
d.defaultValue = 40;
|
||||
d.isQuantized = false;
|
||||
list.push_back(d);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
float
|
||||
PercussionOnsetDetector::getParameter(std::string id) const
|
||||
{
|
||||
if (id == "threshold") return m_threshold;
|
||||
if (id == "sensitivity") return m_sensitivity;
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
void
|
||||
PercussionOnsetDetector::setParameter(std::string id, float value)
|
||||
{
|
||||
if (id == "threshold") {
|
||||
if (value < 0) value = 0;
|
||||
if (value > 20) value = 20;
|
||||
m_threshold = value;
|
||||
} else if (id == "sensitivity") {
|
||||
if (value < 0) value = 0;
|
||||
if (value > 100) value = 100;
|
||||
m_sensitivity = value;
|
||||
}
|
||||
}
|
||||
|
||||
PercussionOnsetDetector::OutputList
|
||||
PercussionOnsetDetector::getOutputDescriptors() const
|
||||
{
|
||||
OutputList list;
|
||||
|
||||
OutputDescriptor d;
|
||||
d.identifier = "onsets";
|
||||
d.name = "Onsets";
|
||||
d.description = "Percussive note onset locations";
|
||||
d.unit = "";
|
||||
d.hasFixedBinCount = true;
|
||||
d.binCount = 0;
|
||||
d.hasKnownExtents = false;
|
||||
d.isQuantized = false;
|
||||
d.sampleType = OutputDescriptor::VariableSampleRate;
|
||||
d.sampleRate = m_inputSampleRate;
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "detectionfunction";
|
||||
d.name = "Detection Function";
|
||||
d.description = "Broadband energy rise detection function";
|
||||
d.binCount = 1;
|
||||
d.isQuantized = true;
|
||||
d.quantizeStep = 1.0;
|
||||
d.sampleType = OutputDescriptor::OneSamplePerStep;
|
||||
list.push_back(d);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
PercussionOnsetDetector::FeatureSet
|
||||
PercussionOnsetDetector::process(const float *const *inputBuffers,
|
||||
Vamp::RealTime ts)
|
||||
{
|
||||
if (m_stepSize == 0) {
|
||||
cerr << "ERROR: PercussionOnsetDetector::process: "
|
||||
<< "PercussionOnsetDetector has not been initialised"
|
||||
<< endl;
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (size_t i = 1; i < m_blockSize/2; ++i) {
|
||||
|
||||
float real = inputBuffers[0][i*2];
|
||||
float imag = inputBuffers[0][i*2 + 1];
|
||||
|
||||
float sqrmag = real * real + imag * imag;
|
||||
|
||||
if (m_priorMagnitudes[i] > 0.f) {
|
||||
float diff = 10.f * log10f(sqrmag / m_priorMagnitudes[i]);
|
||||
|
||||
// std::cout << "i=" << i << ", sqrmag=" << sqrmag << ", prior=" << m_priorMagnitudes[i] << ", diff=" << diff << ", threshold=" << m_threshold << " " << (diff >= m_threshold ? "[*]" : "") << std::endl;
|
||||
|
||||
if (diff >= m_threshold) ++count;
|
||||
}
|
||||
|
||||
m_priorMagnitudes[i] = sqrmag;
|
||||
}
|
||||
|
||||
FeatureSet returnFeatures;
|
||||
|
||||
Feature detectionFunction;
|
||||
detectionFunction.hasTimestamp = false;
|
||||
detectionFunction.values.push_back(count);
|
||||
returnFeatures[1].push_back(detectionFunction);
|
||||
|
||||
if (m_dfMinus2 < m_dfMinus1 &&
|
||||
m_dfMinus1 >= count &&
|
||||
m_dfMinus1 > ((100 - m_sensitivity) * m_blockSize) / 200) {
|
||||
|
||||
//std::cout << "result at " << ts << "! (count == " << count << ", prev == " << m_dfMinus1 << ")" << std::endl;
|
||||
|
||||
Feature onset;
|
||||
onset.hasTimestamp = true;
|
||||
onset.timestamp = ts - Vamp::RealTime::frame2RealTime
|
||||
(m_stepSize, int(m_inputSampleRate + 0.5));
|
||||
returnFeatures[0].push_back(onset);
|
||||
}
|
||||
|
||||
m_dfMinus2 = m_dfMinus1;
|
||||
m_dfMinus1 = count;
|
||||
|
||||
return returnFeatures;
|
||||
}
|
||||
|
||||
PercussionOnsetDetector::FeatureSet
|
||||
PercussionOnsetDetector::getRemainingFeatures()
|
||||
{
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
90
lib-src/libvamp/examples/PercussionOnsetDetector.h
Normal file
90
lib-src/libvamp/examples/PercussionOnsetDetector.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#ifndef _PERCUSSION_ONSET_DETECTOR_PLUGIN_H_
|
||||
#define _PERCUSSION_ONSET_DETECTOR_PLUGIN_H_
|
||||
|
||||
#include "vamp-sdk/Plugin.h"
|
||||
|
||||
/**
|
||||
* Example plugin that detects percussive events.
|
||||
*/
|
||||
|
||||
class PercussionOnsetDetector : public Vamp::Plugin
|
||||
{
|
||||
public:
|
||||
PercussionOnsetDetector(float inputSampleRate);
|
||||
virtual ~PercussionOnsetDetector();
|
||||
|
||||
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
||||
void reset();
|
||||
|
||||
InputDomain getInputDomain() const { return FrequencyDomain; }
|
||||
|
||||
std::string getIdentifier() const;
|
||||
std::string getName() const;
|
||||
std::string getDescription() const;
|
||||
std::string getMaker() const;
|
||||
int getPluginVersion() const;
|
||||
std::string getCopyright() const;
|
||||
|
||||
size_t getPreferredStepSize() const;
|
||||
size_t getPreferredBlockSize() const;
|
||||
|
||||
ParameterList getParameterDescriptors() const;
|
||||
float getParameter(std::string id) const;
|
||||
void setParameter(std::string id, float value);
|
||||
|
||||
OutputList getOutputDescriptors() const;
|
||||
|
||||
FeatureSet process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp);
|
||||
|
||||
FeatureSet getRemainingFeatures();
|
||||
|
||||
protected:
|
||||
size_t m_stepSize;
|
||||
size_t m_blockSize;
|
||||
|
||||
float m_threshold;
|
||||
float m_sensitivity;
|
||||
float *m_priorMagnitudes;
|
||||
float m_dfMinus1;
|
||||
float m_dfMinus2;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
170
lib-src/libvamp/examples/PowerSpectrum.cpp
Normal file
170
lib-src/libvamp/examples/PowerSpectrum.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2008 QMUL.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#include "PowerSpectrum.h"
|
||||
|
||||
using std::string;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
#include <math.h>
|
||||
|
||||
PowerSpectrum::PowerSpectrum(float inputSampleRate) :
|
||||
Plugin(inputSampleRate),
|
||||
m_blockSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
PowerSpectrum::~PowerSpectrum()
|
||||
{
|
||||
}
|
||||
|
||||
string
|
||||
PowerSpectrum::getIdentifier() const
|
||||
{
|
||||
return "powerspectrum";
|
||||
}
|
||||
|
||||
string
|
||||
PowerSpectrum::getName() const
|
||||
{
|
||||
return "Simple Power Spectrum";
|
||||
}
|
||||
|
||||
string
|
||||
PowerSpectrum::getDescription() const
|
||||
{
|
||||
return "Return the power spectrum of a signal";
|
||||
}
|
||||
|
||||
string
|
||||
PowerSpectrum::getMaker() const
|
||||
{
|
||||
return "Vamp SDK Example Plugins";
|
||||
}
|
||||
|
||||
int
|
||||
PowerSpectrum::getPluginVersion() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
string
|
||||
PowerSpectrum::getCopyright() const
|
||||
{
|
||||
return "Freely redistributable (BSD license)";
|
||||
}
|
||||
|
||||
bool
|
||||
PowerSpectrum::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if (channels < getMinChannelCount() ||
|
||||
channels > getMaxChannelCount()) return false;
|
||||
|
||||
m_blockSize = blockSize;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
PowerSpectrum::reset()
|
||||
{
|
||||
}
|
||||
|
||||
PowerSpectrum::OutputList
|
||||
PowerSpectrum::getOutputDescriptors() const
|
||||
{
|
||||
OutputList list;
|
||||
|
||||
OutputDescriptor d;
|
||||
d.identifier = "powerspectrum";
|
||||
d.name = "Power Spectrum";
|
||||
d.description = "Power values of the frequency spectrum bins calculated from the input signal";
|
||||
d.unit = "";
|
||||
d.hasFixedBinCount = true;
|
||||
if (m_blockSize == 0) {
|
||||
// Just so as not to return "1". This is the bin count that
|
||||
// would result from a block size of 1024, which is a likely
|
||||
// default -- but the host should always set the block size
|
||||
// before querying the bin count for certain.
|
||||
d.binCount = 513;
|
||||
} else {
|
||||
d.binCount = m_blockSize / 2 + 1;
|
||||
}
|
||||
d.hasKnownExtents = false;
|
||||
d.isQuantized = false;
|
||||
d.sampleType = OutputDescriptor::OneSamplePerStep;
|
||||
list.push_back(d);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
PowerSpectrum::FeatureSet
|
||||
PowerSpectrum::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
|
||||
{
|
||||
FeatureSet fs;
|
||||
|
||||
if (m_blockSize == 0) {
|
||||
cerr << "ERROR: PowerSpectrum::process: Not initialised" << endl;
|
||||
return fs;
|
||||
}
|
||||
|
||||
size_t n = m_blockSize / 2 + 1;
|
||||
const float *fbuf = inputBuffers[0];
|
||||
|
||||
Feature feature;
|
||||
feature.hasTimestamp = false;
|
||||
feature.values.reserve(n); // optional
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
|
||||
double real = fbuf[i * 2];
|
||||
double imag = fbuf[i * 2 + 1];
|
||||
|
||||
feature.values.push_back(real * real + imag * imag);
|
||||
}
|
||||
|
||||
fs[0].push_back(feature);
|
||||
|
||||
return fs;
|
||||
}
|
||||
|
||||
PowerSpectrum::FeatureSet
|
||||
PowerSpectrum::getRemainingFeatures()
|
||||
{
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
80
lib-src/libvamp/examples/PowerSpectrum.h
Normal file
80
lib-src/libvamp/examples/PowerSpectrum.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#ifndef _POWER_SPECTRUM_PLUGIN_H_
|
||||
#define _POWER_SPECTRUM_PLUGIN_H_
|
||||
|
||||
#include "vamp-sdk/Plugin.h"
|
||||
|
||||
/**
|
||||
* Example plugin that returns a power spectrum calculated (trivially)
|
||||
* from the frequency domain representation of each block of audio.
|
||||
* This is one of the simplest possible Vamp plugins, included as an
|
||||
* example of how to return the appropriate value structure for this
|
||||
* sort of visualisation.
|
||||
*/
|
||||
|
||||
class PowerSpectrum : public Vamp::Plugin
|
||||
{
|
||||
public:
|
||||
PowerSpectrum(float inputSampleRate);
|
||||
virtual ~PowerSpectrum();
|
||||
|
||||
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
||||
void reset();
|
||||
|
||||
InputDomain getInputDomain() const { return FrequencyDomain; }
|
||||
|
||||
std::string getIdentifier() const;
|
||||
std::string getName() const;
|
||||
std::string getDescription() const;
|
||||
std::string getMaker() const;
|
||||
int getPluginVersion() const;
|
||||
std::string getCopyright() const;
|
||||
|
||||
OutputList getOutputDescriptors() const;
|
||||
|
||||
FeatureSet process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp);
|
||||
|
||||
FeatureSet getRemainingFeatures();
|
||||
|
||||
protected:
|
||||
size_t m_blockSize;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
191
lib-src/libvamp/examples/SpectralCentroid.cpp
Normal file
191
lib-src/libvamp/examples/SpectralCentroid.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#include "SpectralCentroid.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define isnan(x) false
|
||||
#define isinf(x) false
|
||||
#endif
|
||||
|
||||
SpectralCentroid::SpectralCentroid(float inputSampleRate) :
|
||||
Plugin(inputSampleRate),
|
||||
m_stepSize(0),
|
||||
m_blockSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
SpectralCentroid::~SpectralCentroid()
|
||||
{
|
||||
}
|
||||
|
||||
string
|
||||
SpectralCentroid::getIdentifier() const
|
||||
{
|
||||
return "spectralcentroid";
|
||||
}
|
||||
|
||||
string
|
||||
SpectralCentroid::getName() const
|
||||
{
|
||||
return "Spectral Centroid";
|
||||
}
|
||||
|
||||
string
|
||||
SpectralCentroid::getDescription() const
|
||||
{
|
||||
return "Calculate the centroid frequency of the spectrum of the input signal";
|
||||
}
|
||||
|
||||
string
|
||||
SpectralCentroid::getMaker() const
|
||||
{
|
||||
return "Vamp SDK Example Plugins";
|
||||
}
|
||||
|
||||
int
|
||||
SpectralCentroid::getPluginVersion() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
string
|
||||
SpectralCentroid::getCopyright() const
|
||||
{
|
||||
return "Freely redistributable (BSD license)";
|
||||
}
|
||||
|
||||
bool
|
||||
SpectralCentroid::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if (channels < getMinChannelCount() ||
|
||||
channels > getMaxChannelCount()) return false;
|
||||
|
||||
m_stepSize = stepSize;
|
||||
m_blockSize = blockSize;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
SpectralCentroid::reset()
|
||||
{
|
||||
}
|
||||
|
||||
SpectralCentroid::OutputList
|
||||
SpectralCentroid::getOutputDescriptors() const
|
||||
{
|
||||
OutputList list;
|
||||
|
||||
OutputDescriptor d;
|
||||
d.identifier = "logcentroid";
|
||||
d.name = "Log Frequency Centroid";
|
||||
d.description = "Centroid of the log weighted frequency spectrum";
|
||||
d.unit = "Hz";
|
||||
d.hasFixedBinCount = true;
|
||||
d.binCount = 1;
|
||||
d.hasKnownExtents = false;
|
||||
d.isQuantized = false;
|
||||
d.sampleType = OutputDescriptor::OneSamplePerStep;
|
||||
list.push_back(d);
|
||||
|
||||
d.identifier = "linearcentroid";
|
||||
d.name = "Linear Frequency Centroid";
|
||||
d.description = "Centroid of the linear frequency spectrum";
|
||||
list.push_back(d);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
SpectralCentroid::FeatureSet
|
||||
SpectralCentroid::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
|
||||
{
|
||||
if (m_stepSize == 0) {
|
||||
cerr << "ERROR: SpectralCentroid::process: "
|
||||
<< "SpectralCentroid has not been initialised"
|
||||
<< endl;
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
double numLin = 0.0, numLog = 0.0, denom = 0.0;
|
||||
|
||||
for (size_t i = 1; i <= m_blockSize/2; ++i) {
|
||||
double freq = (double(i) * m_inputSampleRate) / m_blockSize;
|
||||
double real = inputBuffers[0][i*2];
|
||||
double imag = inputBuffers[0][i*2 + 1];
|
||||
double scalemag = sqrt(real * real + imag * imag) / (m_blockSize/2);
|
||||
numLin += freq * scalemag;
|
||||
numLog += log10f(freq) * scalemag;
|
||||
denom += scalemag;
|
||||
}
|
||||
|
||||
FeatureSet returnFeatures;
|
||||
|
||||
if (denom != 0.0) {
|
||||
float centroidLin = float(numLin / denom);
|
||||
float centroidLog = powf(10, float(numLog / denom));
|
||||
|
||||
Feature feature;
|
||||
feature.hasTimestamp = false;
|
||||
|
||||
if (!isnan(centroidLog) && !isinf(centroidLog)) {
|
||||
feature.values.push_back(centroidLog);
|
||||
}
|
||||
returnFeatures[0].push_back(feature);
|
||||
|
||||
feature.values.clear();
|
||||
if (!isnan(centroidLin) && !isinf(centroidLin)) {
|
||||
feature.values.push_back(centroidLin);
|
||||
}
|
||||
returnFeatures[1].push_back(feature);
|
||||
}
|
||||
|
||||
return returnFeatures;
|
||||
}
|
||||
|
||||
SpectralCentroid::FeatureSet
|
||||
SpectralCentroid::getRemainingFeatures()
|
||||
{
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
78
lib-src/libvamp/examples/SpectralCentroid.h
Normal file
78
lib-src/libvamp/examples/SpectralCentroid.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#ifndef _SPECTRAL_CENTROID_PLUGIN_H_
|
||||
#define _SPECTRAL_CENTROID_PLUGIN_H_
|
||||
|
||||
#include "vamp-sdk/Plugin.h"
|
||||
|
||||
/**
|
||||
* Example plugin that calculates the centre of gravity of the
|
||||
* frequency domain representation of each block of audio.
|
||||
*/
|
||||
|
||||
class SpectralCentroid : public Vamp::Plugin
|
||||
{
|
||||
public:
|
||||
SpectralCentroid(float inputSampleRate);
|
||||
virtual ~SpectralCentroid();
|
||||
|
||||
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
||||
void reset();
|
||||
|
||||
InputDomain getInputDomain() const { return FrequencyDomain; }
|
||||
|
||||
std::string getIdentifier() const;
|
||||
std::string getName() const;
|
||||
std::string getDescription() const;
|
||||
std::string getMaker() const;
|
||||
int getPluginVersion() const;
|
||||
std::string getCopyright() const;
|
||||
|
||||
OutputList getOutputDescriptors() const;
|
||||
|
||||
FeatureSet process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp);
|
||||
|
||||
FeatureSet getRemainingFeatures();
|
||||
|
||||
protected:
|
||||
size_t m_stepSize;
|
||||
size_t m_blockSize;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
195
lib-src/libvamp/examples/ZeroCrossing.cpp
Normal file
195
lib-src/libvamp/examples/ZeroCrossing.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#include "ZeroCrossing.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
#include <cmath>
|
||||
|
||||
ZeroCrossing::ZeroCrossing(float inputSampleRate) :
|
||||
Plugin(inputSampleRate),
|
||||
m_stepSize(0),
|
||||
m_previousSample(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
ZeroCrossing::~ZeroCrossing()
|
||||
{
|
||||
}
|
||||
|
||||
string
|
||||
ZeroCrossing::getIdentifier() const
|
||||
{
|
||||
return "zerocrossing";
|
||||
}
|
||||
|
||||
string
|
||||
ZeroCrossing::getName() const
|
||||
{
|
||||
return "Zero Crossings";
|
||||
}
|
||||
|
||||
string
|
||||
ZeroCrossing::getDescription() const
|
||||
{
|
||||
return "Detect and count zero crossing points";
|
||||
}
|
||||
|
||||
string
|
||||
ZeroCrossing::getMaker() const
|
||||
{
|
||||
return "Vamp SDK Example Plugins";
|
||||
}
|
||||
|
||||
int
|
||||
ZeroCrossing::getPluginVersion() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
string
|
||||
ZeroCrossing::getCopyright() const
|
||||
{
|
||||
return "Freely redistributable (BSD license)";
|
||||
}
|
||||
|
||||
bool
|
||||
ZeroCrossing::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if (channels < getMinChannelCount() ||
|
||||
channels > getMaxChannelCount()) return false;
|
||||
|
||||
m_stepSize = std::min(stepSize, blockSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ZeroCrossing::reset()
|
||||
{
|
||||
m_previousSample = 0.0f;
|
||||
}
|
||||
|
||||
ZeroCrossing::OutputList
|
||||
ZeroCrossing::getOutputDescriptors() const
|
||||
{
|
||||
OutputList list;
|
||||
|
||||
OutputDescriptor zc;
|
||||
zc.identifier = "counts";
|
||||
zc.name = "Zero Crossing Counts";
|
||||
zc.description = "The number of zero crossing points per processing block";
|
||||
zc.unit = "crossings";
|
||||
zc.hasFixedBinCount = true;
|
||||
zc.binCount = 1;
|
||||
zc.hasKnownExtents = false;
|
||||
zc.isQuantized = true;
|
||||
zc.quantizeStep = 1.0;
|
||||
zc.sampleType = OutputDescriptor::OneSamplePerStep;
|
||||
list.push_back(zc);
|
||||
|
||||
zc.identifier = "zerocrossings";
|
||||
zc.name = "Zero Crossings";
|
||||
zc.description = "The locations of zero crossing points";
|
||||
zc.unit = "";
|
||||
zc.hasFixedBinCount = true;
|
||||
zc.binCount = 0;
|
||||
zc.sampleType = OutputDescriptor::VariableSampleRate;
|
||||
zc.sampleRate = m_inputSampleRate;
|
||||
list.push_back(zc);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
ZeroCrossing::FeatureSet
|
||||
ZeroCrossing::process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp)
|
||||
{
|
||||
if (m_stepSize == 0) {
|
||||
cerr << "ERROR: ZeroCrossing::process: "
|
||||
<< "ZeroCrossing has not been initialised"
|
||||
<< endl;
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
float prev = m_previousSample;
|
||||
size_t count = 0;
|
||||
|
||||
FeatureSet returnFeatures;
|
||||
|
||||
for (size_t i = 0; i < m_stepSize; ++i) {
|
||||
|
||||
float sample = inputBuffers[0][i];
|
||||
bool crossing = false;
|
||||
|
||||
if (sample <= 0.0) {
|
||||
if (prev > 0.0) crossing = true;
|
||||
} else if (sample > 0.0) {
|
||||
if (prev <= 0.0) crossing = true;
|
||||
}
|
||||
|
||||
if (crossing) {
|
||||
++count;
|
||||
Feature feature;
|
||||
feature.hasTimestamp = true;
|
||||
feature.timestamp = timestamp +
|
||||
Vamp::RealTime::frame2RealTime(i, (size_t)m_inputSampleRate);
|
||||
returnFeatures[1].push_back(feature);
|
||||
}
|
||||
|
||||
prev = sample;
|
||||
}
|
||||
|
||||
m_previousSample = prev;
|
||||
|
||||
Feature feature;
|
||||
feature.hasTimestamp = false;
|
||||
feature.values.push_back(count);
|
||||
|
||||
returnFeatures[0].push_back(feature);
|
||||
return returnFeatures;
|
||||
}
|
||||
|
||||
ZeroCrossing::FeatureSet
|
||||
ZeroCrossing::getRemainingFeatures()
|
||||
{
|
||||
return FeatureSet();
|
||||
}
|
||||
|
||||
78
lib-src/libvamp/examples/ZeroCrossing.h
Normal file
78
lib-src/libvamp/examples/ZeroCrossing.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#ifndef _ZERO_CROSSING_PLUGIN_H_
|
||||
#define _ZERO_CROSSING_PLUGIN_H_
|
||||
|
||||
#include "vamp-sdk/Plugin.h"
|
||||
|
||||
/**
|
||||
* Example plugin that calculates the positions and density of
|
||||
* zero-crossing points in an audio waveform.
|
||||
*/
|
||||
|
||||
class ZeroCrossing : public Vamp::Plugin
|
||||
{
|
||||
public:
|
||||
ZeroCrossing(float inputSampleRate);
|
||||
virtual ~ZeroCrossing();
|
||||
|
||||
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
||||
void reset();
|
||||
|
||||
InputDomain getInputDomain() const { return TimeDomain; }
|
||||
|
||||
std::string getIdentifier() const;
|
||||
std::string getName() const;
|
||||
std::string getDescription() const;
|
||||
std::string getMaker() const;
|
||||
int getPluginVersion() const;
|
||||
std::string getCopyright() const;
|
||||
|
||||
OutputList getOutputDescriptors() const;
|
||||
|
||||
FeatureSet process(const float *const *inputBuffers,
|
||||
Vamp::RealTime timestamp);
|
||||
|
||||
FeatureSet getRemainingFeatures();
|
||||
|
||||
protected:
|
||||
size_t m_stepSize;
|
||||
float m_previousSample;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
69
lib-src/libvamp/examples/plugins.cpp
Normal file
69
lib-src/libvamp/examples/plugins.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
||||
|
||||
/*
|
||||
Vamp
|
||||
|
||||
An API for audio analysis and feature extraction plugins.
|
||||
|
||||
Centre for Digital Music, Queen Mary, University of London.
|
||||
Copyright 2006 Chris Cannam.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of the Centre for
|
||||
Digital Music; Queen Mary, University of London; and Chris Cannam
|
||||
shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
*/
|
||||
|
||||
#include "vamp/vamp.h"
|
||||
#include "vamp-sdk/PluginAdapter.h"
|
||||
|
||||
#include "ZeroCrossing.h"
|
||||
#include "SpectralCentroid.h"
|
||||
#include "PercussionOnsetDetector.h"
|
||||
#include "FixedTempoEstimator.h"
|
||||
#include "AmplitudeFollower.h"
|
||||
#include "PowerSpectrum.h"
|
||||
|
||||
static Vamp::PluginAdapter<ZeroCrossing> zeroCrossingAdapter;
|
||||
static Vamp::PluginAdapter<SpectralCentroid> spectralCentroidAdapter;
|
||||
static Vamp::PluginAdapter<PercussionOnsetDetector> percussionOnsetAdapter;
|
||||
static Vamp::PluginAdapter<FixedTempoEstimator> fixedTempoAdapter;
|
||||
static Vamp::PluginAdapter<AmplitudeFollower> amplitudeAdapter;
|
||||
static Vamp::PluginAdapter<PowerSpectrum> powerSpectrum;
|
||||
|
||||
const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version,
|
||||
unsigned int index)
|
||||
{
|
||||
if (version < 1) return 0;
|
||||
|
||||
switch (index) {
|
||||
case 0: return zeroCrossingAdapter.getDescriptor();
|
||||
case 1: return spectralCentroidAdapter.getDescriptor();
|
||||
case 2: return percussionOnsetAdapter.getDescriptor();
|
||||
case 3: return amplitudeAdapter.getDescriptor();
|
||||
case 4: return fixedTempoAdapter.getDescriptor();
|
||||
case 5: return powerSpectrum.getDescriptor();
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
6
lib-src/libvamp/examples/vamp-example-plugins.cat
Normal file
6
lib-src/libvamp/examples/vamp-example-plugins.cat
Normal file
@@ -0,0 +1,6 @@
|
||||
vamp:vamp-example-plugins:zerocrossing::Low Level Features
|
||||
vamp:vamp-example-plugins:spectralcentroid::Low Level Features
|
||||
vamp:vamp-example-plugins:powerspectrum::Visualisation
|
||||
vamp:vamp-example-plugins:percussiononsets::Time > Onsets
|
||||
vamp:vamp-example-plugins:amplitudefollower::Low Level Features
|
||||
vamp:vamp-example-plugins:fixedtempo::Time > Tempo
|
||||
306
lib-src/libvamp/examples/vamp-example-plugins.n3
Normal file
306
lib-src/libvamp/examples/vamp-example-plugins.n3
Normal file
@@ -0,0 +1,306 @@
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
||||
@prefix vamp: <http://purl.org/ontology/vamp/> .
|
||||
@prefix plugbase: <http://vamp-plugins.org/rdf/plugins/vamp-example-plugins#> .
|
||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||
@prefix dc: <http://purl.org/dc/elements/1.1/> .
|
||||
@prefix af: <http://purl.org/ontology/af/> .
|
||||
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
||||
@prefix cc: <http://web.resource.org/cc/> .
|
||||
@prefix : <#> .
|
||||
|
||||
<> a vamp:PluginDescription ;
|
||||
foaf:maker <http://www.vamp-plugins.org/doap.rdf#template-generator> ;
|
||||
foaf:primaryTopic <http://vamp-plugins.org/rdf/plugins/vamp-example-plugins> .
|
||||
|
||||
:vamp-example-plugins a vamp:PluginLibrary ;
|
||||
vamp:identifier "vamp-example-plugins" ;
|
||||
foaf:page <http://www.vamp-plugins.org/plugin-doc/vamp-example-plugins.html> ;
|
||||
vamp:available_plugin plugbase:amplitudefollower ;
|
||||
vamp:available_plugin plugbase:fixedtempo ;
|
||||
vamp:available_plugin plugbase:percussiononsets ;
|
||||
vamp:available_plugin plugbase:powerspectrum ;
|
||||
vamp:available_plugin plugbase:spectralcentroid ;
|
||||
vamp:available_plugin plugbase:zerocrossing ;
|
||||
.
|
||||
|
||||
plugbase:amplitudefollower a vamp:Plugin ;
|
||||
dc:title "Amplitude Follower" ;
|
||||
vamp:name "Amplitude Follower" ;
|
||||
dc:description "Track the amplitude of the audio signal" ;
|
||||
foaf:page <http://www.vamp-plugins.org/plugin-doc/vamp-example-plugins.html#amplitudefollower> ;
|
||||
foaf:maker [ foaf:name "Vamp SDK Example Plugins" ] ;
|
||||
cc:license <http://creativecommons.org/licenses/BSD/> ;
|
||||
dc:rights "Freely redistributable (BSD license)" ;
|
||||
vamp:identifier "amplitudefollower" ;
|
||||
vamp:vamp_API_version vamp:api_version_2 ;
|
||||
owl:versionInfo "1" ;
|
||||
vamp:input_domain vamp:TimeDomain ;
|
||||
|
||||
vamp:parameter plugbase:amplitudefollower_param_attack ;
|
||||
vamp:parameter plugbase:amplitudefollower_param_release ;
|
||||
|
||||
vamp:output plugbase:amplitudefollower_output_amplitude ;
|
||||
.
|
||||
plugbase:amplitudefollower_param_attack a vamp:Parameter ;
|
||||
vamp:identifier "attack" ;
|
||||
dc:title "Attack time" ;
|
||||
dc:format "s" ;
|
||||
vamp:min_value 0 ;
|
||||
vamp:max_value 1 ;
|
||||
vamp:unit "s" ;
|
||||
vamp:default_value 0.01 ;
|
||||
vamp:value_names ();
|
||||
.
|
||||
plugbase:amplitudefollower_param_release a vamp:Parameter ;
|
||||
vamp:identifier "release" ;
|
||||
dc:title "Release time" ;
|
||||
dc:format "s" ;
|
||||
vamp:min_value 0 ;
|
||||
vamp:max_value 1 ;
|
||||
vamp:unit "s" ;
|
||||
vamp:default_value 0.01 ;
|
||||
vamp:value_names ();
|
||||
.
|
||||
plugbase:amplitudefollower_output_amplitude a vamp:DenseOutput ;
|
||||
vamp:identifier "amplitude" ;
|
||||
dc:title "Amplitude" ;
|
||||
dc:description "" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "V" ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:Signal ;
|
||||
.
|
||||
plugbase:fixedtempo a vamp:Plugin ;
|
||||
dc:title "Simple Fixed Tempo Estimator" ;
|
||||
vamp:name "Simple Fixed Tempo Estimator" ;
|
||||
dc:description "Study a short section of audio and estimate its tempo, assuming the tempo is constant" ;
|
||||
foaf:page <http://www.vamp-plugins.org/plugin-doc/vamp-example-plugins.html#fixedtempo> ;
|
||||
foaf:maker [ foaf:name "Vamp SDK Example Plugins" ] ;
|
||||
cc:license <http://creativecommons.org/licenses/BSD/> ;
|
||||
dc:rights "Freely redistributable (BSD license)" ;
|
||||
vamp:identifier "fixedtempo" ;
|
||||
vamp:vamp_API_version vamp:api_version_2 ;
|
||||
owl:versionInfo "1" ;
|
||||
vamp:input_domain vamp:FrequencyDomain ;
|
||||
|
||||
vamp:output plugbase:fixedtempo_output_tempo ;
|
||||
vamp:output plugbase:fixedtempo_output_candidates ;
|
||||
vamp:output plugbase:fixedtempo_output_detectionfunction ;
|
||||
vamp:output plugbase:fixedtempo_output_acf ;
|
||||
vamp:output plugbase:fixedtempo_output_filtered_acf ;
|
||||
.
|
||||
plugbase:fixedtempo_output_tempo a vamp:SparseOutput ;
|
||||
vamp:identifier "tempo" ;
|
||||
dc:title "Tempo" ;
|
||||
dc:description "Estimated tempo" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "bpm" ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:sample_type vamp:VariableSampleRate ;
|
||||
vamp:computes_event_type af:Tempo ;
|
||||
.
|
||||
plugbase:fixedtempo_output_candidates a vamp:SparseOutput ;
|
||||
vamp:identifier "candidates" ;
|
||||
dc:title "Tempo candidates" ;
|
||||
dc:description "Possible tempo estimates, one per bin with the most likely in the first bin" ;
|
||||
vamp:fixed_bin_count "false" ;
|
||||
vamp:unit "bpm" ;
|
||||
vamp:sample_type vamp:VariableSampleRate ;
|
||||
vamp:computes_event_type af:Tempo ;
|
||||
.
|
||||
plugbase:fixedtempo_output_detectionfunction a vamp:DenseOutput ;
|
||||
vamp:identifier "detectionfunction" ;
|
||||
dc:title "Detection Function" ;
|
||||
dc:description "Onset detection function" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "" ;
|
||||
a vamp:KnownExtentsOutput ;
|
||||
vamp:min_value 0 ;
|
||||
vamp:max_value 1 ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:OnsetDetectionFunction ;
|
||||
.
|
||||
plugbase:fixedtempo_output_acf a vamp:DenseOutput ;
|
||||
vamp:identifier "acf" ;
|
||||
dc:title "Autocorrelation Function" ;
|
||||
dc:description "Autocorrelation of onset detection function" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "r" ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:Signal ;
|
||||
.
|
||||
plugbase:fixedtempo_output_filtered_acf a vamp:DenseOutput ;
|
||||
vamp:identifier "filtered_acf" ;
|
||||
dc:title "Filtered Autocorrelation" ;
|
||||
dc:description "Filtered autocorrelation of onset detection function" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "r" ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:Signal ;
|
||||
.
|
||||
plugbase:percussiononsets a vamp:Plugin ;
|
||||
dc:title "Simple Percussion Onset Detector" ;
|
||||
vamp:name "Simple Percussion Onset Detector" ;
|
||||
dc:description "Detect percussive note onsets by identifying broadband energy rises" ;
|
||||
foaf:page <http://www.vamp-plugins.org/plugin-doc/vamp-example-plugins.html#percussiononsets> ;
|
||||
foaf:maker [ foaf:name "Vamp SDK Example Plugins" ] ;
|
||||
cc:license <http://creativecommons.org/licenses/BSD/> ;
|
||||
dc:rights "Freely redistributable (BSD license)" ;
|
||||
vamp:identifier "percussiononsets" ;
|
||||
vamp:vamp_API_version vamp:api_version_2 ;
|
||||
owl:versionInfo "2" ;
|
||||
vamp:input_domain vamp:FrequencyDomain ;
|
||||
|
||||
vamp:parameter plugbase:percussiononsets_param_threshold ;
|
||||
vamp:parameter plugbase:percussiononsets_param_sensitivity ;
|
||||
|
||||
vamp:output plugbase:percussiononsets_output_onsets ;
|
||||
vamp:output plugbase:percussiononsets_output_detectionfunction ;
|
||||
.
|
||||
plugbase:percussiononsets_param_threshold a vamp:Parameter ;
|
||||
vamp:identifier "threshold" ;
|
||||
dc:title "Energy rise threshold" ;
|
||||
dc:format "dB" ;
|
||||
vamp:min_value 0 ;
|
||||
vamp:max_value 20 ;
|
||||
vamp:unit "dB" ;
|
||||
vamp:default_value 3 ;
|
||||
vamp:value_names ();
|
||||
.
|
||||
plugbase:percussiononsets_param_sensitivity a vamp:Parameter ;
|
||||
vamp:identifier "sensitivity" ;
|
||||
dc:title "Sensitivity" ;
|
||||
dc:format "%" ;
|
||||
vamp:min_value 0 ;
|
||||
vamp:max_value 100 ;
|
||||
vamp:unit "%" ;
|
||||
vamp:default_value 40 ;
|
||||
vamp:value_names ();
|
||||
.
|
||||
plugbase:percussiononsets_output_onsets a vamp:SparseOutput ;
|
||||
vamp:identifier "onsets" ;
|
||||
dc:title "Onsets" ;
|
||||
dc:description "Percussive note onset locations" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "" ;
|
||||
vamp:bin_count 0 ;
|
||||
vamp:bin_names ();
|
||||
vamp:sample_type vamp:VariableSampleRate ;
|
||||
vamp:computes_event_type af:Onset ;
|
||||
.
|
||||
plugbase:percussiononsets_output_detectionfunction a vamp:DenseOutput ;
|
||||
vamp:identifier "detectionfunction" ;
|
||||
dc:title "Detection Function" ;
|
||||
dc:description "Broadband energy rise detection function" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "" ;
|
||||
a vamp:QuantizedOutput ;
|
||||
vamp:quantize_step 1 ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:OnsetDetectionFunction ;
|
||||
.
|
||||
plugbase:powerspectrum a vamp:Plugin ;
|
||||
dc:title "Simple Power Spectrum" ;
|
||||
vamp:name "Simple Power Spectrum" ;
|
||||
dc:description "Return the power spectrum of a signal" ;
|
||||
foaf:page <http://www.vamp-plugins.org/plugin-doc/vamp-example-plugins.html#powerspectrum> ;
|
||||
foaf:maker [ foaf:name "Vamp SDK Example Plugins" ] ;
|
||||
cc:license <http://creativecommons.org/licenses/BSD/> ;
|
||||
dc:rights "Freely redistributable (BSD license)" ;
|
||||
vamp:identifier "powerspectrum" ;
|
||||
vamp:vamp_API_version vamp:api_version_2 ;
|
||||
owl:versionInfo "1" ;
|
||||
vamp:input_domain vamp:FrequencyDomain ;
|
||||
|
||||
vamp:output plugbase:powerspectrum_output_powerspectrum ;
|
||||
.
|
||||
plugbase:powerspectrum_output_powerspectrum a vamp:DenseOutput ;
|
||||
vamp:identifier "powerspectrum" ;
|
||||
dc:title "Power Spectrum" ;
|
||||
dc:description "Power values of the frequency spectrum bins calculated from the input signal" ;
|
||||
vamp:computes_signal_type af:Signal ;
|
||||
.
|
||||
plugbase:spectralcentroid a vamp:Plugin ;
|
||||
dc:title "Spectral Centroid" ;
|
||||
vamp:name "Spectral Centroid" ;
|
||||
dc:description "Calculate the centroid frequency of the spectrum of the input signal" ;
|
||||
foaf:page <http://www.vamp-plugins.org/plugin-doc/vamp-example-plugins.html#spectralcentroid> ;
|
||||
foaf:maker [ foaf:name "Vamp SDK Example Plugins" ] ;
|
||||
cc:license <http://creativecommons.org/licenses/BSD/> ;
|
||||
dc:rights "Freely redistributable (BSD license)" ;
|
||||
vamp:identifier "spectralcentroid" ;
|
||||
vamp:vamp_API_version vamp:api_version_2 ;
|
||||
owl:versionInfo "2" ;
|
||||
vamp:input_domain vamp:FrequencyDomain ;
|
||||
|
||||
vamp:output plugbase:spectralcentroid_output_logcentroid ;
|
||||
vamp:output plugbase:spectralcentroid_output_linearcentroid ;
|
||||
.
|
||||
plugbase:spectralcentroid_output_logcentroid a vamp:DenseOutput ;
|
||||
vamp:identifier "logcentroid" ;
|
||||
dc:title "Log Frequency Centroid" ;
|
||||
dc:description "Centroid of the log weighted frequency spectrum" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "Hz" ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:LogFrequencyCentroid ;
|
||||
.
|
||||
plugbase:spectralcentroid_output_linearcentroid a vamp:DenseOutput ;
|
||||
vamp:identifier "linearcentroid" ;
|
||||
dc:title "Linear Frequency Centroid" ;
|
||||
dc:description "Centroid of the linear frequency spectrum" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "Hz" ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:LinearFrequencyCentroid ;
|
||||
.
|
||||
plugbase:zerocrossing a vamp:Plugin ;
|
||||
dc:title "Zero Crossings" ;
|
||||
vamp:name "Zero Crossings" ;
|
||||
dc:description "Detect and count zero crossing points" ;
|
||||
foaf:page <http://www.vamp-plugins.org/plugin-doc/vamp-example-plugins.html#zerocrossing> ;
|
||||
foaf:maker [ foaf:name "Vamp SDK Example Plugins" ] ;
|
||||
cc:license <http://creativecommons.org/licenses/BSD/> ;
|
||||
dc:rights "Freely redistributable (BSD license)" ;
|
||||
vamp:identifier "zerocrossing" ;
|
||||
vamp:vamp_API_version vamp:api_version_2 ;
|
||||
owl:versionInfo "2" ;
|
||||
vamp:input_domain vamp:TimeDomain ;
|
||||
vamp:output plugbase:zerocrossing_output_counts ;
|
||||
vamp:output plugbase:zerocrossing_output_zerocrossings ;
|
||||
.
|
||||
plugbase:zerocrossing_output_counts a vamp:DenseOutput ;
|
||||
vamp:identifier "counts" ;
|
||||
dc:title "Zero Crossing Counts" ;
|
||||
dc:description "The number of zero crossing points per processing block" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "crossings" ;
|
||||
a vamp:QuantizedOutput ;
|
||||
vamp:quantize_step 1 ;
|
||||
vamp:bin_count 1 ;
|
||||
vamp:bin_names ( "");
|
||||
vamp:computes_signal_type af:ZeroCrossingCount ;
|
||||
.
|
||||
plugbase:zerocrossing_output_zerocrossings a vamp:SparseOutput ;
|
||||
vamp:identifier "zerocrossings" ;
|
||||
dc:title "Zero Crossings" ;
|
||||
dc:description "The locations of zero crossing points" ;
|
||||
vamp:fixed_bin_count "true" ;
|
||||
vamp:unit "" ;
|
||||
a vamp:QuantizedOutput ;
|
||||
vamp:quantize_step 1 ;
|
||||
vamp:bin_count 0 ;
|
||||
vamp:bin_names ();
|
||||
vamp:sample_type vamp:VariableSampleRate ;
|
||||
vamp:computes_event_type af:ZeroCrossing ;
|
||||
.
|
||||
|
||||
Reference in New Issue
Block a user