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),
33 m_onsettype(OnsetComplex),
41 if (m_onsetdet) del_aubio_onset(m_onsetdet);
42 if (m_ibuf) del_fvec(m_ibuf);
43 if (m_onset) del_fvec(m_onset);
44 if (m_fftgrain) del_cvec(m_fftgrain);
45 if (m_pv) del_aubio_pvoc(m_pv);
46 if (m_peakpick) del_aubio_peakpicker(m_peakpick);
50 Onset::getIdentifier() const
56 Onset::getName() const
58 return "Aubio Onset Detector";
62 Onset::getDescription() const
64 return "Estimate note onset times";
68 Onset::getMaker() const
70 return "Paul Brossier (plugin by Chris Cannam)";
74 Onset::getPluginVersion() const
80 Onset::getCopyright() const
86 Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
89 std::cerr << "Onset::initialise: channels must be 1" << std::endl;
93 m_stepSize = stepSize;
94 m_blockSize = blockSize;
96 m_ibuf = new_fvec(stepSize);
97 m_onset = new_fvec(1);
98 m_fftgrain = new_cvec(blockSize);
99 m_pv = new_aubio_pvoc(blockSize, stepSize);
100 m_peakpick = new_aubio_peakpicker();
101 aubio_peakpicker_set_threshold(m_peakpick, m_threshold);
103 m_onsetdet = new_aubio_onset
104 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
107 lrintf(m_inputSampleRate));
109 m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize,
110 lrintf(m_inputSampleRate));
112 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
123 Onset::getPreferredStepSize() const
129 Onset::getPreferredBlockSize() const
131 return 2 * getPreferredStepSize();
135 Onset::getParameterDescriptors() const
139 ParameterDescriptor desc;
140 desc.identifier = "onsettype";
141 desc.name = "Onset Detection Function Type";
144 desc.defaultValue = (int)OnsetComplex;
145 desc.isQuantized = true;
146 desc.quantizeStep = 1;
147 desc.valueNames.push_back("Energy Based");
148 desc.valueNames.push_back("Spectral Difference");
149 desc.valueNames.push_back("High-Frequency Content");
150 desc.valueNames.push_back("Complex Domain");
151 desc.valueNames.push_back("Phase Deviation");
152 desc.valueNames.push_back("Kullback-Liebler");
153 desc.valueNames.push_back("Modified Kullback-Liebler");
154 list.push_back(desc);
156 desc = ParameterDescriptor();
157 desc.identifier = "peakpickthreshold";
158 desc.name = "Peak Picker Threshold";
161 desc.defaultValue = 0.3;
162 desc.isQuantized = false;
163 list.push_back(desc);
165 desc = ParameterDescriptor();
166 desc.identifier = "silencethreshold";
167 desc.name = "Silence Threshold";
168 desc.minValue = -120;
170 desc.defaultValue = -90;
172 desc.isQuantized = false;
173 list.push_back(desc);
179 Onset::getParameter(std::string param) const
181 if (param == "onsettype") {
183 } else if (param == "peakpickthreshold") {
185 } else if (param == "silencethreshold") {
193 Onset::setParameter(std::string param, float value)
195 if (param == "onsettype") {
196 switch (lrintf(value)) {
197 case 0: m_onsettype = OnsetEnergy; break;
198 case 1: m_onsettype = OnsetSpecDiff; break;
199 case 2: m_onsettype = OnsetHFC; break;
200 case 3: m_onsettype = OnsetComplex; break;
201 case 4: m_onsettype = OnsetPhase; break;
202 case 5: m_onsettype = OnsetKL; break;
203 case 6: m_onsettype = OnsetMKL; break;
205 } else if (param == "peakpickthreshold") {
207 } else if (param == "silencethreshold") {
213 Onset::getOutputDescriptors() const
218 d.identifier = "onsets";
221 d.hasFixedBinCount = true;
223 d.sampleType = OutputDescriptor::VariableSampleRate;
227 d = OutputDescriptor();
228 d.identifier = "detectionfunction";
229 d.name = "Onset Detection Function";
231 d.hasFixedBinCount = true;
233 d.hasKnownExtents = false;
234 d.isQuantized = false;
235 d.sampleType = OutputDescriptor::OneSamplePerStep;
242 Onset::process(const float *const *inputBuffers,
243 Vamp::RealTime timestamp)
245 for (size_t i = 0; i < m_stepSize; ++i) {
246 fvec_write_sample(m_ibuf, inputBuffers[0][i], i);
249 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
251 bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
254 if (aubio_silence_detection(m_ibuf, m_silence)) {
259 FeatureSet returnFeatures;
262 if (timestamp - m_lastOnset >= m_delay) {
264 onsettime.hasTimestamp = true;
265 if (timestamp < m_delay) timestamp = m_delay;
266 onsettime.timestamp = timestamp - m_delay;
267 returnFeatures[0].push_back(onsettime);
268 m_lastOnset = timestamp;
272 for (size_t j = 0; j < m_channelCount; ++j) {
273 feature.values.push_back(m_onset->data[j][0]);
275 returnFeatures[1].push_back(feature);
277 return returnFeatures;
281 Onset::getRemainingFeatures()