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(OnsetComplex),
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)OnsetComplex;
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 list.push_back(desc);
165 desc = ParameterDescriptor();
166 desc.identifier = "peakpickthreshold";
167 desc.name = "Peak Picker Threshold";
168 desc.description = "Threshold used for peak picking, the higher the more detections";
171 desc.defaultValue = 0.3;
172 desc.isQuantized = false;
173 list.push_back(desc);
175 desc = ParameterDescriptor();
176 desc.identifier = "silencethreshold";
177 desc.name = "Silence Threshold";
178 desc.description = "Silence threshold, the higher the least detection";
179 desc.minValue = -120;
181 desc.defaultValue = -70;
183 desc.isQuantized = false;
184 list.push_back(desc);
186 desc = ParameterDescriptor();
187 desc.identifier = "minioi";
188 desc.name = "Minimum Inter-Onset Interval";
189 desc.description = "Time interval below which two consecutive onsets should be merged";
192 desc.defaultValue = 4;
194 desc.isQuantized = true;
195 desc.quantizeStep = 1;
196 list.push_back(desc);
202 Onset::getParameter(std::string param) const
204 if (param == "onsettype") {
206 } else if (param == "peakpickthreshold") {
208 } else if (param == "silencethreshold") {
210 } else if (param == "minioi") {
218 Onset::setParameter(std::string param, float value)
220 if (param == "onsettype") {
221 switch (lrintf(value)) {
222 case 0: m_onsettype = OnsetEnergy; break;
223 case 1: m_onsettype = OnsetSpecDiff; break;
224 case 2: m_onsettype = OnsetHFC; break;
225 case 3: m_onsettype = OnsetComplex; break;
226 case 4: m_onsettype = OnsetPhase; break;
227 case 5: m_onsettype = OnsetKL; break;
228 case 6: m_onsettype = OnsetMKL; break;
229 case 7: m_onsettype = OnsetSpecFlux; break;
231 } else if (param == "peakpickthreshold") {
233 } else if (param == "silencethreshold") {
235 } else if (param == "minioi") {
241 Onset::getOutputDescriptors() const
246 d.identifier = "onsets";
248 d.description = "List of times at which a note onset was detected";
250 d.hasFixedBinCount = true;
252 d.sampleType = OutputDescriptor::VariableSampleRate;
256 d.identifier = "odf";
257 d.name = "Onset detection function";
258 d.description = "Output of the onset detection function";
260 d.isQuantized = true;
261 d.quantizeStep = 1.0;
262 d.sampleType = OutputDescriptor::OneSamplePerStep;
265 d.identifier = "todf";
266 d.name = "Thresholded Onset detection function";
267 d.description = "Output of the thresholded onset detection function";
269 d.isQuantized = true;
270 d.quantizeStep = 1.0;
271 d.sampleType = OutputDescriptor::OneSamplePerStep;
278 Onset::process(const float *const *inputBuffers,
279 Vamp::RealTime timestamp)
281 for (size_t i = 0; i < m_stepSize; ++i) {
282 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
285 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
287 bool isonset = m_onset->data[0];
289 FeatureSet returnFeatures;
292 if (timestamp - m_lastOnset >= m_delay) {
294 onsettime.hasTimestamp = true;
295 if (timestamp < m_delay) timestamp = m_delay;
296 onsettime.timestamp = timestamp - m_delay;
297 returnFeatures[0].push_back(onsettime);
298 m_lastOnset = timestamp;
303 odf.hasTimestamp = false;
304 odf.values.push_back(aubio_onset_get_descriptor(m_onsetdet));
305 returnFeatures[1].push_back(odf);
308 todf.hasTimestamp = false;
309 todf.values.push_back(aubio_onset_get_thresholded_descriptor(m_onsetdet));
310 returnFeatures[2].push_back(todf);
312 return returnFeatures;
316 Onset::getRemainingFeatures()