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.
26 const char *getAubioNameForOnsetType(OnsetType t)
28 // In the same order as the enum elements in the header
29 static const char *const names[] = {
30 "energy", "specdiff", "hfc", "complex", "phase", "kl", "mkl", "specflux"
36 Onset::Onset(float inputSampleRate) :
37 Plugin(inputSampleRate),
42 m_onsettype(OnsetComplex),
50 m_onsettype(aubio_onset_complex),
61 if (m_onsetdet) del_aubio_onset(m_onsetdet);
63 if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet);
64 if (m_fftgrain) del_cvec(m_fftgrain);
65 if (m_pv) del_aubio_pvoc(m_pv);
66 if (m_peakpick) del_aubio_peakpicker(m_peakpick);
68 if (m_ibuf) del_fvec(m_ibuf);
69 if (m_onset) del_fvec(m_onset);
73 Onset::getIdentifier() const
79 Onset::getName() const
81 return "Aubio Onset Detector";
85 Onset::getDescription() const
87 return "Estimate note onset times";
91 Onset::getMaker() const
93 return "Paul Brossier (plugin by Chris Cannam)";
97 Onset::getPluginVersion() const
107 Onset::getCopyright() const
113 Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
115 m_stepSize = stepSize;
116 m_blockSize = blockSize;
120 std::cerr << "Onset::initialise: channels must be 1" << std::endl;
123 m_ibuf = new_fvec(stepSize);
124 m_onset = new_fvec(1);
127 m_channelCount = channels;
129 m_ibuf = new_fvec(stepSize, channels);
130 m_onset = new_fvec(1, channels);
131 m_fftgrain = new_cvec(blockSize, channels);
132 m_pv = new_aubio_pvoc(blockSize, stepSize, channels);
133 m_peakpick = new_aubio_peakpicker(m_threshold);
135 m_onsetdet = new_aubio_onsetdetection(m_onsettype, blockSize, channels);
137 m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize,
138 lrintf(m_inputSampleRate));
140 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
150 if (m_onsetdet) del_aubio_onset(m_onsetdet);
152 m_onsetdet = new_aubio_onset
153 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
156 lrintf(m_inputSampleRate));
158 aubio_onset_set_threshold(m_onsetdet, m_threshold);
159 aubio_onset_set_silence(m_onsetdet, m_silence);
160 aubio_onset_set_minioi(m_onsetdet, m_minioi);
162 m_delay = Vamp::RealTime::frame2RealTime(4 * m_stepSize,
163 lrintf(m_inputSampleRate));
165 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
170 Onset::getPreferredStepSize() const
176 Onset::getPreferredBlockSize() const
178 return 2 * getPreferredStepSize();
182 Onset::getParameterDescriptors() const
186 ParameterDescriptor desc;
187 desc.identifier = "onsettype";
188 desc.name = "Onset Detection Function Type";
192 desc.defaultValue = (int)OnsetComplex;
195 desc.defaultValue = (int)aubio_onset_complex;
197 desc.isQuantized = true;
198 desc.quantizeStep = 1;
199 desc.valueNames.push_back("Energy Based");
200 desc.valueNames.push_back("Spectral Difference");
201 desc.valueNames.push_back("High-Frequency Content");
202 desc.valueNames.push_back("Complex Domain");
203 desc.valueNames.push_back("Phase Deviation");
204 desc.valueNames.push_back("Kullback-Liebler");
205 desc.valueNames.push_back("Modified Kullback-Liebler");
207 desc.valueNames.push_back("Spectral Flux");
209 list.push_back(desc);
211 desc = ParameterDescriptor();
212 desc.identifier = "peakpickthreshold";
213 desc.name = "Peak Picker Threshold";
216 desc.defaultValue = 0.3;
217 desc.isQuantized = false;
218 list.push_back(desc);
220 desc = ParameterDescriptor();
221 desc.identifier = "silencethreshold";
222 desc.name = "Silence Threshold";
223 desc.minValue = -120;
226 desc.defaultValue = -70;
228 desc.defaultValue = -90;
231 desc.isQuantized = false;
232 list.push_back(desc);
235 desc = ParameterDescriptor();
236 desc.identifier = "minioi";
237 desc.name = "Minimum Inter-Onset Interval";
240 desc.defaultValue = 4;
242 desc.isQuantized = true;
243 desc.quantizeStep = 1;
244 list.push_back(desc);
250 Onset::getParameter(std::string param) const
252 if (param == "onsettype") {
254 } else if (param == "peakpickthreshold") {
256 } else if (param == "silencethreshold") {
259 } else if (param == "minioi") {
268 Onset::setParameter(std::string param, float value)
270 if (param == "onsettype") {
271 switch (lrintf(value)) {
273 case 0: m_onsettype = OnsetEnergy; break;
274 case 1: m_onsettype = OnsetSpecDiff; break;
275 case 2: m_onsettype = OnsetHFC; break;
276 case 3: m_onsettype = OnsetComplex; break;
277 case 4: m_onsettype = OnsetPhase; break;
278 case 5: m_onsettype = OnsetKL; break;
279 case 6: m_onsettype = OnsetMKL; break;
280 case 7: m_onsettype = OnsetSpecFlux; break;
282 case 0: m_onsettype = aubio_onset_energy; break;
283 case 1: m_onsettype = aubio_onset_specdiff; break;
284 case 2: m_onsettype = aubio_onset_hfc; break;
285 case 3: m_onsettype = aubio_onset_complex; break;
286 case 4: m_onsettype = aubio_onset_phase; break;
287 case 5: m_onsettype = aubio_onset_kl; break;
288 case 6: m_onsettype = aubio_onset_mkl; break;
291 } else if (param == "peakpickthreshold") {
293 } else if (param == "silencethreshold") {
296 } else if (param == "minioi") {
303 Onset::getOutputDescriptors() const
308 d.identifier = "onsets";
311 d.hasFixedBinCount = true;
313 d.sampleType = OutputDescriptor::VariableSampleRate;
318 d = OutputDescriptor();
319 d.identifier = "detectionfunction";
320 d.name = "Onset Detection Function";
322 d.hasFixedBinCount = true;
323 d.binCount = m_channelCount;
324 d.hasKnownExtents = false;
325 d.isQuantized = false;
326 d.sampleType = OutputDescriptor::OneSamplePerStep;
333 Onset::process(const float *const *inputBuffers,
334 Vamp::RealTime timestamp)
337 for (size_t i = 0; i < m_stepSize; ++i) {
338 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
341 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
343 bool isonset = m_onset->data[0];
345 for (size_t i = 0; i < m_stepSize; ++i) {
346 for (size_t j = 0; j < m_channelCount; ++j) {
347 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
351 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
352 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
354 bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
357 if (aubio_silence_detection(m_ibuf, m_silence)) {
363 FeatureSet returnFeatures;
366 if (timestamp - m_lastOnset >= m_delay) {
368 onsettime.hasTimestamp = true;
369 if (timestamp < m_delay) timestamp = m_delay;
370 onsettime.timestamp = timestamp - m_delay;
371 returnFeatures[0].push_back(onsettime);
372 m_lastOnset = timestamp;
377 for (size_t j = 0; j < m_channelCount; ++j) {
378 feature.values.push_back(m_onset->data[j][0]);
380 returnFeatures[1].push_back(feature);
383 return returnFeatures;
387 Onset::getRemainingFeatures()