To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / BeatRootVampPlugin.cpp @ 22:6afcb5edd7ab
History | View | Annotate | Download (5.12 KB)
| 1 |
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|---|---|
| 2 |
|
| 3 |
/*
|
| 4 |
Vamp feature extraction plugin for the BeatRoot beat tracker.
|
| 5 |
|
| 6 |
Centre for Digital Music, Queen Mary, University of London.
|
| 7 |
This file copyright 2011 Simon Dixon, Chris Cannam and QMUL.
|
| 8 |
|
| 9 |
This program is free software; you can redistribute it and/or
|
| 10 |
modify it under the terms of the GNU General Public License as
|
| 11 |
published by the Free Software Foundation; either version 2 of the
|
| 12 |
License, or (at your option) any later version. See the file
|
| 13 |
COPYING included with this distribution for more information.
|
| 14 |
*/
|
| 15 |
|
| 16 |
#include "BeatRootVampPlugin.h" |
| 17 |
#include "BeatRootProcessor.h" |
| 18 |
|
| 19 |
#include "Event.h" |
| 20 |
|
| 21 |
#include <vamp-sdk/RealTime.h> |
| 22 |
#include <vamp-sdk/PluginAdapter.h> |
| 23 |
|
| 24 |
BeatRootVampPlugin::BeatRootVampPlugin(float inputSampleRate) :
|
| 25 |
Plugin(inputSampleRate) |
| 26 |
{
|
| 27 |
m_processor = new BeatRootProcessor(inputSampleRate);
|
| 28 |
} |
| 29 |
|
| 30 |
BeatRootVampPlugin::~BeatRootVampPlugin() |
| 31 |
{
|
| 32 |
delete m_processor;
|
| 33 |
} |
| 34 |
|
| 35 |
string
|
| 36 |
BeatRootVampPlugin::getIdentifier() const
|
| 37 |
{
|
| 38 |
return "beatroot"; |
| 39 |
} |
| 40 |
|
| 41 |
string
|
| 42 |
BeatRootVampPlugin::getName() const
|
| 43 |
{
|
| 44 |
return "BeatRoot Beat Tracker"; |
| 45 |
} |
| 46 |
|
| 47 |
string
|
| 48 |
BeatRootVampPlugin::getDescription() const
|
| 49 |
{
|
| 50 |
return "Identify beat locations in music"; |
| 51 |
} |
| 52 |
|
| 53 |
string
|
| 54 |
BeatRootVampPlugin::getMaker() const
|
| 55 |
{
|
| 56 |
return "Simon Dixon (plugin by Chris Cannam)"; |
| 57 |
} |
| 58 |
|
| 59 |
int
|
| 60 |
BeatRootVampPlugin::getPluginVersion() const
|
| 61 |
{
|
| 62 |
// Increment this each time you release a version that behaves
|
| 63 |
// differently from the previous one
|
| 64 |
return 1; |
| 65 |
} |
| 66 |
|
| 67 |
string
|
| 68 |
BeatRootVampPlugin::getCopyright() const
|
| 69 |
{
|
| 70 |
return "GPL"; |
| 71 |
} |
| 72 |
|
| 73 |
BeatRootVampPlugin::InputDomain |
| 74 |
BeatRootVampPlugin::getInputDomain() const
|
| 75 |
{
|
| 76 |
return FrequencyDomain;
|
| 77 |
} |
| 78 |
|
| 79 |
size_t |
| 80 |
BeatRootVampPlugin::getPreferredBlockSize() const
|
| 81 |
{
|
| 82 |
return m_processor->getFFTSize();
|
| 83 |
} |
| 84 |
|
| 85 |
size_t |
| 86 |
BeatRootVampPlugin::getPreferredStepSize() const
|
| 87 |
{
|
| 88 |
return m_processor->getHopSize();
|
| 89 |
} |
| 90 |
|
| 91 |
size_t |
| 92 |
BeatRootVampPlugin::getMinChannelCount() const
|
| 93 |
{
|
| 94 |
return 1; |
| 95 |
} |
| 96 |
|
| 97 |
size_t |
| 98 |
BeatRootVampPlugin::getMaxChannelCount() const
|
| 99 |
{
|
| 100 |
return 1; |
| 101 |
} |
| 102 |
|
| 103 |
BeatRootVampPlugin::ParameterList |
| 104 |
BeatRootVampPlugin::getParameterDescriptors() const
|
| 105 |
{
|
| 106 |
ParameterList list; |
| 107 |
return list;
|
| 108 |
} |
| 109 |
|
| 110 |
float
|
| 111 |
BeatRootVampPlugin::getParameter(string identifier) const |
| 112 |
{
|
| 113 |
return 0; |
| 114 |
} |
| 115 |
|
| 116 |
void
|
| 117 |
BeatRootVampPlugin::setParameter(string identifier, float value) |
| 118 |
{
|
| 119 |
} |
| 120 |
|
| 121 |
BeatRootVampPlugin::ProgramList |
| 122 |
BeatRootVampPlugin::getPrograms() const
|
| 123 |
{
|
| 124 |
ProgramList list; |
| 125 |
return list;
|
| 126 |
} |
| 127 |
|
| 128 |
string
|
| 129 |
BeatRootVampPlugin::getCurrentProgram() const
|
| 130 |
{
|
| 131 |
return ""; // no programs |
| 132 |
} |
| 133 |
|
| 134 |
void
|
| 135 |
BeatRootVampPlugin::selectProgram(string name)
|
| 136 |
{
|
| 137 |
} |
| 138 |
|
| 139 |
BeatRootVampPlugin::OutputList |
| 140 |
BeatRootVampPlugin::getOutputDescriptors() const
|
| 141 |
{
|
| 142 |
OutputList list; |
| 143 |
|
| 144 |
// See OutputDescriptor documentation for the possibilities here.
|
| 145 |
// Every plugin must have at least one output.
|
| 146 |
|
| 147 |
OutputDescriptor d; |
| 148 |
d.identifier = "beats";
|
| 149 |
d.name = "Beats";
|
| 150 |
d.description = "Estimated beat locations";
|
| 151 |
d.unit = "";
|
| 152 |
d.hasFixedBinCount = true;
|
| 153 |
d.binCount = 0;
|
| 154 |
d.hasKnownExtents = false;
|
| 155 |
d.isQuantized = false;
|
| 156 |
d.sampleType = OutputDescriptor::VariableSampleRate; |
| 157 |
d.sampleRate = m_inputSampleRate; |
| 158 |
d.hasDuration = false;
|
| 159 |
list.push_back(d); |
| 160 |
|
| 161 |
return list;
|
| 162 |
} |
| 163 |
|
| 164 |
bool
|
| 165 |
BeatRootVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) |
| 166 |
{
|
| 167 |
if (channels < getMinChannelCount() ||
|
| 168 |
channels > getMaxChannelCount()) {
|
| 169 |
std::cerr << "BeatRootVampPlugin::initialise: Unsupported number ("
|
| 170 |
<< channels << ") of channels" << std::endl;
|
| 171 |
return false; |
| 172 |
} |
| 173 |
|
| 174 |
if (stepSize != getPreferredStepSize()) {
|
| 175 |
std::cerr << "BeatRootVampPlugin::initialise: Unsupported step size "
|
| 176 |
<< "for sample rate (" << stepSize << ", required step is " |
| 177 |
<< getPreferredStepSize() << " for rate " << m_inputSampleRate
|
| 178 |
<< ")" << std::endl;
|
| 179 |
return false; |
| 180 |
} |
| 181 |
|
| 182 |
if (blockSize != getPreferredBlockSize()) {
|
| 183 |
std::cerr << "BeatRootVampPlugin::initialise: Unsupported block size "
|
| 184 |
<< "for sample rate (" << blockSize << ", required size is " |
| 185 |
<< getPreferredBlockSize() << " for rate " << m_inputSampleRate
|
| 186 |
<< ")" << std::endl;
|
| 187 |
return false; |
| 188 |
} |
| 189 |
|
| 190 |
m_processor->reset(); |
| 191 |
|
| 192 |
return true; |
| 193 |
} |
| 194 |
|
| 195 |
void
|
| 196 |
BeatRootVampPlugin::reset() |
| 197 |
{
|
| 198 |
m_processor->reset(); |
| 199 |
} |
| 200 |
|
| 201 |
BeatRootVampPlugin::FeatureSet |
| 202 |
BeatRootVampPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp) |
| 203 |
{
|
| 204 |
m_processor->processFrame(inputBuffers); |
| 205 |
return FeatureSet();
|
| 206 |
} |
| 207 |
|
| 208 |
BeatRootVampPlugin::FeatureSet |
| 209 |
BeatRootVampPlugin::getRemainingFeatures() |
| 210 |
{
|
| 211 |
EventList el = m_processor->beatTrack(); |
| 212 |
|
| 213 |
Feature f; |
| 214 |
f.hasTimestamp = true;
|
| 215 |
f.hasDuration = false;
|
| 216 |
f.label = "";
|
| 217 |
f.values.clear(); |
| 218 |
|
| 219 |
FeatureSet fs; |
| 220 |
|
| 221 |
for (EventList::const_iterator i = el.begin(); i != el.end(); ++i) {
|
| 222 |
f.timestamp = Vamp::RealTime::fromSeconds(i->time); |
| 223 |
fs[0].push_back(f);
|
| 224 |
} |
| 225 |
|
| 226 |
return fs;
|
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
static Vamp::PluginAdapter<BeatRootVampPlugin> brAdapter;
|
| 231 |
|
| 232 |
const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version, |
| 233 |
unsigned int index) |
| 234 |
{
|
| 235 |
if (version < 1) return 0; |
| 236 |
|
| 237 |
switch (index) {
|
| 238 |
case 0: return brAdapter.getDescriptor(); |
| 239 |
default: return 0; |
| 240 |
} |
| 241 |
} |
| 242 |
|