1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
4 Vamp feature extraction plugins using Paul Brossier's Aubio library.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
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.
25 Tempo::Tempo(float inputSampleRate) :
26 Plugin(inputSampleRate),
30 m_onsettype(OnsetComplex),
39 if (m_ibuf) del_fvec(m_ibuf);
40 if (m_beat) del_fvec(m_beat);
41 if (m_tempo) del_aubio_tempo(m_tempo);
45 Tempo::getIdentifier() const
51 Tempo::getName() const
53 return "Aubio Beat Tracker";
57 Tempo::getDescription() const
59 return "Estimate the musical tempo and track beat positions";
63 Tempo::getMaker() const
65 return "Paul Brossier (method by Matthew Davies, plugin by Chris Cannam)";
69 Tempo::getPluginVersion() const
75 Tempo::getCopyright() const
81 Tempo::initialise(size_t channels, size_t stepSize, size_t blockSize)
84 std::cerr << "Tempo::initialise: channels must be 1" << std::endl;
88 m_stepSize = stepSize;
89 m_blockSize = blockSize;
91 m_ibuf = new_fvec(stepSize);
94 m_delay = Vamp::RealTime::frame2RealTime(3 * stepSize,
95 lrintf(m_inputSampleRate));
105 if (m_tempo) del_aubio_tempo(m_tempo);
107 m_lastBeat = Vamp::RealTime::zeroTime - m_delay - m_delay;
109 m_tempo = new_aubio_tempo
110 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
113 lrintf(m_inputSampleRate));
115 aubio_tempo_set_silence(m_tempo, m_silence);
116 aubio_tempo_set_threshold(m_tempo, m_threshold);
120 Tempo::getPreferredStepSize() const
126 Tempo::getPreferredBlockSize() const
128 return 2 * getPreferredStepSize();
132 Tempo::getParameterDescriptors() const
136 ParameterDescriptor desc;
137 desc.identifier = "onsettype";
138 desc.name = "Onset Detection Function Type";
141 desc.defaultValue = (int)OnsetComplex;
142 desc.isQuantized = true;
143 desc.quantizeStep = 1;
144 desc.valueNames.push_back("Energy Based");
145 desc.valueNames.push_back("Spectral Difference");
146 desc.valueNames.push_back("High-Frequency Content");
147 desc.valueNames.push_back("Complex Domain");
148 desc.valueNames.push_back("Phase Deviation");
149 desc.valueNames.push_back("Kullback-Liebler");
150 desc.valueNames.push_back("Modified Kullback-Liebler");
151 desc.valueNames.push_back("Spectral Flux");
152 list.push_back(desc);
154 desc = ParameterDescriptor();
155 desc.identifier = "peakpickthreshold";
156 desc.name = "Peak Picker Threshold";
159 desc.defaultValue = 0.3;
160 desc.isQuantized = false;
161 list.push_back(desc);
163 desc = ParameterDescriptor();
164 desc.identifier = "silencethreshold";
165 desc.name = "Silence Threshold";
166 desc.minValue = -120;
168 desc.defaultValue = -70;
170 desc.isQuantized = false;
171 list.push_back(desc);
177 Tempo::getParameter(std::string param) const
179 if (param == "onsettype") {
181 } else if (param == "peakpickthreshold") {
183 } else if (param == "silencethreshold") {
191 Tempo::setParameter(std::string param, float value)
193 if (param == "onsettype") {
194 switch (lrintf(value)) {
195 case 0: m_onsettype = OnsetEnergy; break;
196 case 1: m_onsettype = OnsetSpecDiff; break;
197 case 2: m_onsettype = OnsetHFC; break;
198 case 3: m_onsettype = OnsetComplex; break;
199 case 4: m_onsettype = OnsetPhase; break;
200 case 5: m_onsettype = OnsetKL; break;
201 case 6: m_onsettype = OnsetMKL; break;
202 case 7: m_onsettype = OnsetSpecFlux; break;
204 } else if (param == "peakpickthreshold") {
206 } else if (param == "silencethreshold") {
212 Tempo::getOutputDescriptors() const
217 d.identifier = "beats";
220 d.hasFixedBinCount = true;
222 d.sampleType = OutputDescriptor::VariableSampleRate;
226 d.identifier = "tempo";
229 d.hasFixedBinCount = true;
231 d.hasKnownExtents = false;
232 d.isQuantized = false;
233 d.sampleType = OutputDescriptor::OneSamplePerStep;
240 Tempo::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
242 for (size_t i = 0; i < m_stepSize; ++i) {
243 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
246 aubio_tempo_do(m_tempo, m_ibuf, m_beat);
248 bool istactus = m_beat->data[0];
250 m_bpm = aubio_tempo_get_bpm(m_tempo);
252 FeatureSet returnFeatures;
254 if (istactus == true) {
255 if (timestamp - m_lastBeat >= m_delay) {
257 onsettime.hasTimestamp = true;
258 if (timestamp < m_delay) timestamp = m_delay;
259 onsettime.timestamp = timestamp - m_delay;
260 returnFeatures[0].push_back(onsettime);
261 m_lastBeat = timestamp;
265 if (m_bpm >= 30 && m_bpm <= 206) {
267 tempo.hasTimestamp = false;
268 tempo.values.push_back(m_bpm);
269 returnFeatures[1].push_back(tempo);
272 return returnFeatures;
276 Tempo::getRemainingFeatures()