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 Onset::Onset(float inputSampleRate) :
26 Plugin(inputSampleRate),
30 m_onsettype(OnsetComplex),
39 if (m_onsetdet) del_aubio_onset(m_onsetdet);
40 if (m_ibuf) del_fvec(m_ibuf);
41 if (m_onset) del_fvec(m_onset);
45 Onset::getIdentifier() const
51 Onset::getName() const
53 return "Aubio Onset Detector";
57 Onset::getDescription() const
59 return "Estimate note onset times";
63 Onset::getMaker() const
65 return "Paul Brossier (plugin by Chris Cannam)";
69 Onset::getPluginVersion() const
75 Onset::getCopyright() const
81 Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
84 std::cerr << "Onset::initialise: channels must be 1" << std::endl;
88 m_stepSize = stepSize;
89 m_blockSize = blockSize;
91 m_ibuf = new_fvec(stepSize);
92 m_onset = new_fvec(1);
94 m_onsetdet = new_aubio_onset
95 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
98 lrintf(m_inputSampleRate));
100 aubio_onset_set_threshold(m_onsetdet, m_threshold);
101 aubio_onset_set_silence(m_onsetdet, m_silence);
102 aubio_onset_set_minioi(m_onsetdet, m_minioi);
104 m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize,
105 lrintf(m_inputSampleRate));
107 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
118 Onset::getPreferredStepSize() const
124 Onset::getPreferredBlockSize() const
126 return 2 * getPreferredStepSize();
130 Onset::getParameterDescriptors() const
134 ParameterDescriptor desc;
135 desc.identifier = "onsettype";
136 desc.name = "Onset Detection Function Type";
139 desc.defaultValue = (int)OnsetComplex;
140 desc.isQuantized = true;
141 desc.quantizeStep = 1;
142 desc.valueNames.push_back("Energy Based");
143 desc.valueNames.push_back("Spectral Difference");
144 desc.valueNames.push_back("High-Frequency Content");
145 desc.valueNames.push_back("Complex Domain");
146 desc.valueNames.push_back("Phase Deviation");
147 desc.valueNames.push_back("Kullback-Liebler");
148 desc.valueNames.push_back("Modified Kullback-Liebler");
149 desc.valueNames.push_back("Spectral Flux");
150 list.push_back(desc);
152 desc = ParameterDescriptor();
153 desc.identifier = "peakpickthreshold";
154 desc.name = "Peak Picker Threshold";
157 desc.defaultValue = 0.3;
158 desc.isQuantized = false;
159 list.push_back(desc);
161 desc = ParameterDescriptor();
162 desc.identifier = "silencethreshold";
163 desc.name = "Silence Threshold";
164 desc.minValue = -120;
166 desc.defaultValue = -70;
168 desc.isQuantized = false;
169 list.push_back(desc);
171 desc = ParameterDescriptor();
172 desc.identifier = "minioi";
173 desc.name = "Minimum Inter-Onset Interval";
176 desc.defaultValue = 4;
178 desc.isQuantized = true;
179 desc.quantizeStep = 1;
180 list.push_back(desc);
186 Onset::getParameter(std::string param) const
188 if (param == "onsettype") {
190 } else if (param == "peakpickthreshold") {
192 } else if (param == "silencethreshold") {
194 } else if (param == "minioi") {
202 Onset::setParameter(std::string param, float value)
204 if (param == "onsettype") {
205 switch (lrintf(value)) {
206 case 0: m_onsettype = OnsetEnergy; break;
207 case 1: m_onsettype = OnsetSpecDiff; break;
208 case 2: m_onsettype = OnsetHFC; break;
209 case 3: m_onsettype = OnsetComplex; break;
210 case 4: m_onsettype = OnsetPhase; break;
211 case 5: m_onsettype = OnsetKL; break;
212 case 6: m_onsettype = OnsetMKL; break;
213 case 7: m_onsettype = OnsetSpecFlux; break;
215 } else if (param == "peakpickthreshold") {
217 } else if (param == "silencethreshold") {
219 } else if (param == "minioi") {
225 Onset::getOutputDescriptors() const
230 d.identifier = "onsets";
233 d.hasFixedBinCount = true;
235 d.sampleType = OutputDescriptor::VariableSampleRate;
239 d = OutputDescriptor();
240 d.identifier = "detectionfunction";
241 d.name = "Onset Detection Function";
243 d.hasFixedBinCount = true;
245 d.hasKnownExtents = false;
246 d.isQuantized = false;
247 d.sampleType = OutputDescriptor::OneSamplePerStep;
254 Onset::process(const float *const *inputBuffers,
255 Vamp::RealTime timestamp)
257 for (size_t i = 0; i < m_stepSize; ++i) {
258 fvec_write_sample(m_ibuf, inputBuffers[0][i], i);
261 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
263 bool isonset = m_onset->data[0];
265 FeatureSet returnFeatures;
268 if (timestamp - m_lastOnset >= m_delay) {
270 onsettime.hasTimestamp = true;
271 if (timestamp < m_delay) timestamp = m_delay;
272 onsettime.timestamp = timestamp - m_delay;
273 returnFeatures[0].push_back(onsettime);
274 m_lastOnset = timestamp;
279 for (size_t j = 0; j < m_channelCount; ++j) {
280 feature.values.push_back(m_onset->data[j][0]);
282 returnFeatures[1].push_back(feature);
284 return returnFeatures;
288 Onset::getRemainingFeatures()