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 Onset::Onset(float inputSampleRate) :
35 Plugin(inputSampleRate),
39 m_onsettype(OnsetDefault),
48 if (m_onsetdet) del_aubio_onset(m_onsetdet);
49 if (m_ibuf) del_fvec(m_ibuf);
50 if (m_onset) del_fvec(m_onset);
54 Onset::getIdentifier() const
60 Onset::getName() const
62 return "Aubio Onset Detector";
66 Onset::getDescription() const
68 return "Estimate note onset times";
72 Onset::getMaker() const
74 return "Paul Brossier (plugin by Chris Cannam)";
78 Onset::getPluginVersion() const
84 Onset::getCopyright() const
90 Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
93 std::cerr << "Onset::initialise: channels must be 1" << std::endl;
97 m_stepSize = stepSize;
98 m_blockSize = blockSize;
100 m_ibuf = new_fvec(stepSize);
101 m_onset = new_fvec(1);
111 if (m_onsetdet) del_aubio_onset(m_onsetdet);
113 m_onsetdet = new_aubio_onset
114 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
117 lrintf(m_inputSampleRate));
119 aubio_onset_set_threshold(m_onsetdet, m_threshold);
120 aubio_onset_set_silence(m_onsetdet, m_silence);
121 aubio_onset_set_minioi(m_onsetdet, m_minioi);
123 m_delay = Vamp::RealTime::frame2RealTime(4 * m_stepSize,
124 lrintf(m_inputSampleRate));
126 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
130 Onset::getPreferredStepSize() const
136 Onset::getPreferredBlockSize() const
138 return 2 * getPreferredStepSize();
142 Onset::getParameterDescriptors() const
146 ParameterDescriptor desc;
147 desc.identifier = "onsettype";
148 desc.name = "Onset Detection Function Type";
149 desc.description = "Type of onset detection function to use";
152 desc.defaultValue = (int)OnsetDefault;
153 desc.isQuantized = true;
154 desc.quantizeStep = 1;
155 desc.valueNames.push_back("Energy Based");
156 desc.valueNames.push_back("Spectral Difference");
157 desc.valueNames.push_back("High-Frequency Content");
158 desc.valueNames.push_back("Complex Domain");
159 desc.valueNames.push_back("Phase Deviation");
160 desc.valueNames.push_back("Kullback-Liebler");
161 desc.valueNames.push_back("Modified Kullback-Liebler");
162 desc.valueNames.push_back("Spectral Flux");
163 desc.valueNames.push_back("Default");
164 list.push_back(desc);
166 desc = ParameterDescriptor();
167 desc.identifier = "peakpickthreshold";
168 desc.name = "Peak Picker Threshold";
169 desc.description = "Threshold used for peak picking, the higher the more detections";
172 desc.defaultValue = 0.3;
173 desc.isQuantized = false;
174 list.push_back(desc);
176 desc = ParameterDescriptor();
177 desc.identifier = "silencethreshold";
178 desc.name = "Silence Threshold";
179 desc.description = "Silence threshold, the higher the least detection";
180 desc.minValue = -120;
182 desc.defaultValue = -70;
184 desc.isQuantized = false;
185 list.push_back(desc);
187 desc = ParameterDescriptor();
188 desc.identifier = "minioi";
189 desc.name = "Minimum Inter-Onset Interval";
190 desc.description = "Time interval below which two consecutive onsets should be merged";
193 desc.defaultValue = 4;
195 desc.isQuantized = true;
196 desc.quantizeStep = 1;
197 list.push_back(desc);
203 Onset::getParameter(std::string param) const
205 if (param == "onsettype") {
207 } else if (param == "peakpickthreshold") {
209 } else if (param == "silencethreshold") {
211 } else if (param == "minioi") {
219 Onset::setParameter(std::string param, float value)
221 if (param == "onsettype") {
222 switch (lrintf(value)) {
223 case 0: m_onsettype = OnsetEnergy; break;
224 case 1: m_onsettype = OnsetSpecDiff; break;
225 case 2: m_onsettype = OnsetHFC; break;
226 case 3: m_onsettype = OnsetComplex; break;
227 case 4: m_onsettype = OnsetPhase; break;
228 case 5: m_onsettype = OnsetKL; break;
229 case 6: m_onsettype = OnsetMKL; break;
230 case 7: m_onsettype = OnsetSpecFlux; break;
232 } else if (param == "peakpickthreshold") {
234 } else if (param == "silencethreshold") {
236 } else if (param == "minioi") {
242 Onset::getOutputDescriptors() const
247 d.identifier = "onsets";
249 d.description = "List of times at which a note onset was detected";
251 d.hasFixedBinCount = true;
253 d.sampleType = OutputDescriptor::VariableSampleRate;
257 d.identifier = "odf";
258 d.name = "Onset detection function";
259 d.description = "Output of the onset detection function";
261 d.isQuantized = true;
262 d.quantizeStep = 1.0;
263 d.sampleType = OutputDescriptor::OneSamplePerStep;
266 d.identifier = "todf";
267 d.name = "Thresholded Onset detection function";
268 d.description = "Output of the thresholded onset detection function";
270 d.isQuantized = true;
271 d.quantizeStep = 1.0;
272 d.sampleType = OutputDescriptor::OneSamplePerStep;
279 Onset::process(const float *const *inputBuffers,
280 Vamp::RealTime timestamp)
282 for (size_t i = 0; i < m_stepSize; ++i) {
283 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
286 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
288 bool isonset = m_onset->data[0];
290 FeatureSet returnFeatures;
293 if (timestamp - m_lastOnset >= m_delay) {
295 onsettime.hasTimestamp = true;
296 if (timestamp < m_delay) timestamp = m_delay;
297 onsettime.timestamp = timestamp - m_delay;
298 returnFeatures[0].push_back(onsettime);
299 m_lastOnset = timestamp;
304 odf.hasTimestamp = false;
305 odf.values.push_back(aubio_onset_get_descriptor(m_onsetdet));
306 returnFeatures[1].push_back(odf);
309 todf.hasTimestamp = false;
310 todf.values.push_back(aubio_onset_get_thresholded_descriptor(m_onsetdet));
311 returnFeatures[2].push_back(todf);
313 return returnFeatures;
317 Onset::getRemainingFeatures()