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 file is part of vamp-aubio-plugins.
11 vamp-aubio is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 vamp-aubio is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with aubio. If not, see <http://www.gnu.org/licenses/>.
34 Tempo::Tempo(float inputSampleRate) :
35 Plugin(inputSampleRate),
39 m_onsettype(OnsetComplex),
48 if (m_ibuf) del_fvec(m_ibuf);
49 if (m_beat) del_fvec(m_beat);
50 if (m_tempo) del_aubio_tempo(m_tempo);
54 Tempo::getIdentifier() const
60 Tempo::getName() const
62 return "Aubio Beat Tracker";
66 Tempo::getDescription() const
68 return "Estimate the musical tempo and track beat positions";
72 Tempo::getMaker() const
74 return "Paul Brossier (method by Matthew Davies, plugin by Chris Cannam)";
78 Tempo::getPluginVersion() const
84 Tempo::getCopyright() const
90 Tempo::initialise(size_t channels, size_t stepSize, size_t blockSize)
93 std::cerr << "Tempo::initialise: channels must be 1" << std::endl;
97 m_stepSize = stepSize;
98 m_blockSize = blockSize;
100 m_ibuf = new_fvec(stepSize);
101 m_beat = new_fvec(2);
103 m_delay = Vamp::RealTime::frame2RealTime(3 * stepSize,
104 lrintf(m_inputSampleRate));
114 if (m_tempo) del_aubio_tempo(m_tempo);
116 m_lastBeat = Vamp::RealTime::zeroTime - m_delay - m_delay;
118 m_tempo = new_aubio_tempo
119 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
122 lrintf(m_inputSampleRate));
124 aubio_tempo_set_silence(m_tempo, m_silence);
125 aubio_tempo_set_threshold(m_tempo, m_threshold);
129 Tempo::getPreferredStepSize() const
135 Tempo::getPreferredBlockSize() const
137 return 2 * getPreferredStepSize();
141 Tempo::getParameterDescriptors() const
145 ParameterDescriptor desc;
146 desc.identifier = "onsettype";
147 desc.name = "Onset Detection Function Type";
148 desc.description = "Type of onset detection function to use";
151 desc.defaultValue = (int)OnsetComplex;
152 desc.isQuantized = true;
153 desc.quantizeStep = 1;
154 desc.valueNames.push_back("Energy Based");
155 desc.valueNames.push_back("Spectral Difference");
156 desc.valueNames.push_back("High-Frequency Content");
157 desc.valueNames.push_back("Complex Domain");
158 desc.valueNames.push_back("Phase Deviation");
159 desc.valueNames.push_back("Kullback-Liebler");
160 desc.valueNames.push_back("Modified Kullback-Liebler");
161 desc.valueNames.push_back("Spectral Flux");
162 list.push_back(desc);
164 desc = ParameterDescriptor();
165 desc.identifier = "peakpickthreshold";
166 desc.name = "Peak Picker Threshold";
167 desc.description = "Peak picking threshold, the higher the least detection";
170 desc.defaultValue = 0.3;
171 desc.isQuantized = false;
172 list.push_back(desc);
174 desc = ParameterDescriptor();
175 desc.identifier = "silencethreshold";
176 desc.name = "Silence Threshold";
177 desc.description = "Silence threshold, the higher the least detection";
178 desc.minValue = -120;
180 desc.defaultValue = -70;
182 desc.isQuantized = false;
183 list.push_back(desc);
189 Tempo::getParameter(std::string param) const
191 if (param == "onsettype") {
193 } else if (param == "peakpickthreshold") {
195 } else if (param == "silencethreshold") {
203 Tempo::setParameter(std::string param, float value)
205 if (param == "onsettype") {
206 switch (lrintf(value)) {
207 case 0: m_onsettype = OnsetEnergy; break;
208 case 1: m_onsettype = OnsetSpecDiff; break;
209 case 2: m_onsettype = OnsetHFC; break;
210 case 3: m_onsettype = OnsetComplex; break;
211 case 4: m_onsettype = OnsetPhase; break;
212 case 5: m_onsettype = OnsetKL; break;
213 case 6: m_onsettype = OnsetMKL; break;
214 case 7: m_onsettype = OnsetSpecFlux; break;
216 } else if (param == "peakpickthreshold") {
218 } else if (param == "silencethreshold") {
224 Tempo::getOutputDescriptors() const
229 d.identifier = "beats";
231 d.description = "List of times at which a beat was detected";
233 d.hasFixedBinCount = true;
235 d.sampleType = OutputDescriptor::VariableSampleRate;
239 d.identifier = "tempo";
241 d.description = "Overall estimated tempo";
243 d.hasFixedBinCount = true;
245 d.hasKnownExtents = false;
246 d.isQuantized = false;
247 d.sampleType = OutputDescriptor::OneSamplePerStep;
254 Tempo::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
256 for (size_t i = 0; i < m_stepSize; ++i) {
257 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
260 aubio_tempo_do(m_tempo, m_ibuf, m_beat);
262 bool istactus = m_beat->data[0];
264 m_bpm = aubio_tempo_get_bpm(m_tempo);
266 FeatureSet returnFeatures;
268 if (istactus == true) {
269 if (timestamp - m_lastBeat >= m_delay) {
271 onsettime.hasTimestamp = true;
272 if (timestamp < m_delay) timestamp = m_delay;
273 onsettime.timestamp = timestamp - m_delay;
274 returnFeatures[0].push_back(onsettime);
275 m_lastBeat = timestamp;
279 if (m_bpm >= 30 && m_bpm <= 206) {
281 tempo.hasTimestamp = false;
282 tempo.values.push_back(m_bpm);
283 returnFeatures[1].push_back(tempo);
286 return returnFeatures;
290 Tempo::getRemainingFeatures()