To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / BeatRootVampPlugin.cpp @ 13:0d4048bfadbb

History | View | Annotate | Download (5.09 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.hasDuration = false;
158
    list.push_back(d);
159

    
160
    return list;
161
}
162

    
163
bool
164
BeatRootVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
165
{
166
    if (channels < getMinChannelCount() ||
167
        channels > getMaxChannelCount()) {
168
        std::cerr << "BeatRootVampPlugin::initialise: Unsupported number ("
169
                  << channels << ") of channels" << std::endl;
170
        return false;
171
    }
172

    
173
    if (stepSize != getPreferredStepSize()) {
174
        std::cerr << "BeatRootVampPlugin::initialise: Unsupported step size "
175
                  << "for sample rate (" << stepSize << ", required step is "
176
                  << getPreferredStepSize() << " for rate " << m_inputSampleRate
177
                  << ")" << std::endl;
178
        return false;
179
    }
180

    
181
    if (blockSize != getPreferredBlockSize()) {
182
        std::cerr << "BeatRootVampPlugin::initialise: Unsupported block size "
183
                  << "for sample rate (" << blockSize << ", required size is "
184
                  << getPreferredBlockSize() << " for rate " << m_inputSampleRate
185
                  << ")" << std::endl;
186
        return false;
187
    }
188

    
189
    m_processor->reset();
190

    
191
    return true;
192
}
193

    
194
void
195
BeatRootVampPlugin::reset()
196
{
197
    m_processor->reset();
198
}
199

    
200
BeatRootVampPlugin::FeatureSet
201
BeatRootVampPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
202
{
203
    m_processor->processFrame(inputBuffers);
204
    return FeatureSet();
205
}
206

    
207
BeatRootVampPlugin::FeatureSet
208
BeatRootVampPlugin::getRemainingFeatures()
209
{
210
    EventList el = m_processor->beatTrack();
211
    
212
    Feature f;
213
    f.hasTimestamp = true;
214
    f.hasDuration = false;
215
    f.label = "";
216
    f.values.clear();
217

    
218
    FeatureSet fs;
219

    
220
    for (EventList::const_iterator i = el.begin(); i != el.end(); ++i) {
221
        f.timestamp = Vamp::RealTime::fromSeconds(i->time);
222
        fs[0].push_back(f);
223
    }
224

    
225
    return fs;
226
}
227

    
228

    
229
static Vamp::PluginAdapter<BeatRootVampPlugin> brAdapter;
230

    
231
const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version,
232
                                                    unsigned int index)
233
{
234
    if (version < 1) return 0;
235

    
236
    switch (index) {
237
    case  0: return brAdapter.getDescriptor();
238
    default: return 0;
239
    }
240
}
241