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);
102 if (m_onsetdet) del_aubio_onset(m_onsetdet);
104 m_onsetdet = new_aubio_onset
105 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
108 lrintf(m_inputSampleRate));
110 aubio_onset_set_threshold(m_onsetdet, m_threshold);
111 aubio_onset_set_silence(m_onsetdet, m_silence);
112 aubio_onset_set_minioi(m_onsetdet, m_minioi);
114 m_delay = Vamp::RealTime::frame2RealTime(4 * m_stepSize,
115 lrintf(m_inputSampleRate));
117 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
121 Onset::getPreferredStepSize() const
127 Onset::getPreferredBlockSize() const
129 return 2 * getPreferredStepSize();
133 Onset::getParameterDescriptors() const
137 ParameterDescriptor desc;
138 desc.identifier = "onsettype";
139 desc.name = "Onset Detection Function Type";
142 desc.defaultValue = (int)OnsetComplex;
143 desc.isQuantized = true;
144 desc.quantizeStep = 1;
145 desc.valueNames.push_back("Energy Based");
146 desc.valueNames.push_back("Spectral Difference");
147 desc.valueNames.push_back("High-Frequency Content");
148 desc.valueNames.push_back("Complex Domain");
149 desc.valueNames.push_back("Phase Deviation");
150 desc.valueNames.push_back("Kullback-Liebler");
151 desc.valueNames.push_back("Modified Kullback-Liebler");
152 desc.valueNames.push_back("Spectral Flux");
153 list.push_back(desc);
155 desc = ParameterDescriptor();
156 desc.identifier = "peakpickthreshold";
157 desc.name = "Peak Picker Threshold";
160 desc.defaultValue = 0.3;
161 desc.isQuantized = false;
162 list.push_back(desc);
164 desc = ParameterDescriptor();
165 desc.identifier = "silencethreshold";
166 desc.name = "Silence Threshold";
167 desc.minValue = -120;
169 desc.defaultValue = -70;
171 desc.isQuantized = false;
172 list.push_back(desc);
174 desc = ParameterDescriptor();
175 desc.identifier = "minioi";
176 desc.name = "Minimum Inter-Onset Interval";
179 desc.defaultValue = 4;
181 desc.isQuantized = true;
182 desc.quantizeStep = 1;
183 list.push_back(desc);
189 Onset::getParameter(std::string param) const
191 if (param == "onsettype") {
193 } else if (param == "peakpickthreshold") {
195 } else if (param == "silencethreshold") {
197 } else if (param == "minioi") {
205 Onset::setParameter(std::string param, float value)
207 if (param == "onsettype") {
208 switch (lrintf(value)) {
209 case 0: m_onsettype = OnsetEnergy; break;
210 case 1: m_onsettype = OnsetSpecDiff; break;
211 case 2: m_onsettype = OnsetHFC; break;
212 case 3: m_onsettype = OnsetComplex; break;
213 case 4: m_onsettype = OnsetPhase; break;
214 case 5: m_onsettype = OnsetKL; break;
215 case 6: m_onsettype = OnsetMKL; break;
216 case 7: m_onsettype = OnsetSpecFlux; break;
218 } else if (param == "peakpickthreshold") {
220 } else if (param == "silencethreshold") {
222 } else if (param == "minioi") {
228 Onset::getOutputDescriptors() const
233 d.identifier = "onsets";
236 d.hasFixedBinCount = true;
238 d.sampleType = OutputDescriptor::VariableSampleRate;
246 Onset::process(const float *const *inputBuffers,
247 Vamp::RealTime timestamp)
249 for (size_t i = 0; i < m_stepSize; ++i) {
250 fvec_write_sample(m_ibuf, inputBuffers[0][i], i);
253 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
255 bool isonset = m_onset->data[0];
257 FeatureSet returnFeatures;
260 if (timestamp - m_lastOnset >= m_delay) {
262 onsettime.hasTimestamp = true;
263 if (timestamp < m_delay) timestamp = m_delay;
264 onsettime.timestamp = timestamp - m_delay;
265 returnFeatures[0].push_back(onsettime);
266 m_lastOnset = timestamp;
270 return returnFeatures;
274 Onset::getRemainingFeatures()