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),
49 if (m_onsetdet) del_aubio_onset(m_onsetdet);
50 if (m_ibuf) del_fvec(m_ibuf);
51 if (m_onset) del_fvec(m_onset);
55 Onset::getIdentifier() const
61 Onset::getName() const
63 return "Aubio Onset Detector";
67 Onset::getDescription() const
69 return "Estimate note onset times";
73 Onset::getMaker() const
75 return "Paul Brossier (plugin by Chris Cannam)";
79 Onset::getPluginVersion() const
85 Onset::getCopyright() const
91 Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
94 std::cerr << "Onset::initialise: channels must be 1" << std::endl;
98 m_stepSize = stepSize;
99 m_blockSize = blockSize;
101 m_ibuf = new_fvec(stepSize);
102 m_onset = new_fvec(1);
112 if (m_onsetdet) del_aubio_onset(m_onsetdet);
114 m_onsetdet = new_aubio_onset
115 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
118 lrintf(m_inputSampleRate));
120 aubio_onset_set_threshold(m_onsetdet, m_threshold);
121 aubio_onset_set_silence(m_onsetdet, m_silence);
122 aubio_onset_set_minioi(m_onsetdet, m_minioi);
127 Onset::getPreferredStepSize() const
133 Onset::getPreferredBlockSize() const
135 return 2 * getPreferredStepSize();
139 Onset::getParameterDescriptors() const
143 ParameterDescriptor desc;
144 desc.identifier = "onsettype";
145 desc.name = "Onset Detection Function Type";
146 desc.description = "Type of onset detection function to use";
149 desc.defaultValue = (int)OnsetDefault;
150 desc.isQuantized = true;
151 desc.quantizeStep = 1;
152 desc.valueNames.push_back("Energy Based");
153 desc.valueNames.push_back("Spectral Difference");
154 desc.valueNames.push_back("High-Frequency Content");
155 desc.valueNames.push_back("Complex Domain");
156 desc.valueNames.push_back("Phase Deviation");
157 desc.valueNames.push_back("Kullback-Liebler");
158 desc.valueNames.push_back("Modified Kullback-Liebler");
159 desc.valueNames.push_back("Spectral Flux");
160 desc.valueNames.push_back("Default");
161 list.push_back(desc);
163 desc = ParameterDescriptor();
164 desc.identifier = "peakpickthreshold";
165 desc.name = "Peak Picker Threshold";
166 desc.description = "Threshold used for peak picking, the higher the more detections";
169 desc.defaultValue = 0.3;
170 desc.isQuantized = false;
171 list.push_back(desc);
173 desc = ParameterDescriptor();
174 desc.identifier = "silencethreshold";
175 desc.name = "Silence Threshold";
176 desc.description = "Silence threshold, the higher the least detection";
177 desc.minValue = -120;
179 desc.defaultValue = -90;
181 desc.isQuantized = false;
182 list.push_back(desc);
184 desc = ParameterDescriptor();
185 desc.identifier = "minioi";
186 desc.name = "Minimum Inter-Onset Interval";
187 desc.description = "Time interval below which two consecutive onsets should be merged";
190 desc.defaultValue = 4;
192 desc.isQuantized = true;
193 desc.quantizeStep = 1;
194 list.push_back(desc);
200 Onset::getParameter(std::string param) const
202 if (param == "onsettype") {
204 } else if (param == "peakpickthreshold") {
206 return aubio_onset_get_threshold(m_onsetdet);
210 } else if (param == "silencethreshold") {
212 return aubio_onset_get_silence(m_onsetdet);
216 } else if (param == "minioi") {
218 return aubio_onset_get_minioi(m_onsetdet);
228 Onset::setParameter(std::string param, float value)
230 if (param == "onsettype") {
231 switch (lrintf(value)) {
232 case 0: m_onsettype = OnsetEnergy; break;
233 case 1: m_onsettype = OnsetSpecDiff; break;
234 case 2: m_onsettype = OnsetHFC; break;
235 case 3: m_onsettype = OnsetComplex; break;
236 case 4: m_onsettype = OnsetPhase; break;
237 case 5: m_onsettype = OnsetKL; break;
238 case 6: m_onsettype = OnsetMKL; break;
239 case 7: m_onsettype = OnsetSpecFlux; break;
240 case 8: m_onsettype = OnsetDefault; break;
242 if (!m_onsetdet) initialise(1, 256, 512);
243 } else if (param == "peakpickthreshold") {
246 aubio_onset_set_threshold(m_onsetdet, m_threshold);
247 } else if (param == "silencethreshold") {
250 aubio_onset_set_silence(m_onsetdet, m_silence);
251 } else if (param == "minioi") {
254 aubio_onset_set_minioi(m_onsetdet, m_minioi);
259 Onset::getOutputDescriptors() const
264 d.identifier = "onsets";
266 d.description = "List of times at which a note onset was detected";
268 d.hasFixedBinCount = true;
270 d.sampleType = OutputDescriptor::VariableSampleRate;
274 d.identifier = "odf";
275 d.name = "Onset detection function";
276 d.description = "Output of the onset detection function";
278 d.isQuantized = true;
279 d.quantizeStep = 1.0;
280 d.sampleType = OutputDescriptor::OneSamplePerStep;
283 d.identifier = "todf";
284 d.name = "Thresholded Onset detection function";
285 d.description = "Output of the thresholded onset detection function";
287 d.isQuantized = true;
288 d.quantizeStep = 1.0;
289 d.sampleType = OutputDescriptor::OneSamplePerStep;
296 Onset::process(const float *const *inputBuffers,
297 Vamp::RealTime timestamp)
299 for (size_t i = 0; i < m_stepSize; ++i) {
300 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
303 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
305 smpl_t isonset = m_onset->data[0];
307 FeatureSet returnFeatures;
311 onsettime.hasTimestamp = true;
312 onsettime.timestamp = Vamp::RealTime::fromSeconds(aubio_onset_get_last_s(m_onsetdet));
313 returnFeatures[0].push_back(onsettime);
317 odf.hasTimestamp = false;
318 odf.values.push_back(aubio_onset_get_descriptor(m_onsetdet));
319 returnFeatures[1].push_back(odf);
322 todf.hasTimestamp = false;
323 todf.values.push_back(aubio_onset_get_thresholded_descriptor(m_onsetdet));
324 returnFeatures[2].push_back(todf);
326 return returnFeatures;
330 Onset::getRemainingFeatures()