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(aubio_onset_complex),
41 if (m_onsetdet) aubio_onsetdetection_free(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(m_threshold);
102 m_onsetdet = new_aubio_onsetdetection(m_onsettype, blockSize);
104 m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize,
105 lrintf(m_inputSampleRate));
107 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
118 Onset::getPreferredStepSize() const
124 Onset::getPreferredBlockSize() const
126 return 2 * getPreferredStepSize();
130 Onset::getParameterDescriptors() const
134 ParameterDescriptor desc;
135 desc.identifier = "onsettype";
136 desc.name = "Onset Detection Function Type";
139 desc.defaultValue = (int)aubio_onset_complex;
140 desc.isQuantized = true;
141 desc.quantizeStep = 1;
142 desc.valueNames.push_back("Energy Based");
143 desc.valueNames.push_back("Spectral Difference");
144 desc.valueNames.push_back("High-Frequency Content");
145 desc.valueNames.push_back("Complex Domain");
146 desc.valueNames.push_back("Phase Deviation");
147 desc.valueNames.push_back("Kullback-Liebler");
148 desc.valueNames.push_back("Modified Kullback-Liebler");
149 list.push_back(desc);
151 desc = ParameterDescriptor();
152 desc.identifier = "peakpickthreshold";
153 desc.name = "Peak Picker Threshold";
156 desc.defaultValue = 0.3;
157 desc.isQuantized = false;
158 list.push_back(desc);
160 desc = ParameterDescriptor();
161 desc.identifier = "silencethreshold";
162 desc.name = "Silence Threshold";
163 desc.minValue = -120;
165 desc.defaultValue = -90;
167 desc.isQuantized = false;
168 list.push_back(desc);
174 Onset::getParameter(std::string param) const
176 if (param == "onsettype") {
178 } else if (param == "peakpickthreshold") {
180 } else if (param == "silencethreshold") {
188 Onset::setParameter(std::string param, float value)
190 if (param == "onsettype") {
191 switch (lrintf(value)) {
192 case 0: m_onsettype = aubio_onset_energy; break;
193 case 1: m_onsettype = aubio_onset_specdiff; break;
194 case 2: m_onsettype = aubio_onset_hfc; break;
195 case 3: m_onsettype = aubio_onset_complex; break;
196 case 4: m_onsettype = aubio_onset_phase; break;
197 case 5: m_onsettype = aubio_onset_kl; break;
198 case 6: m_onsettype = aubio_onset_mkl; break;
200 } else if (param == "peakpickthreshold") {
202 } else if (param == "silencethreshold") {
208 Onset::getOutputDescriptors() const
213 d.identifier = "onsets";
216 d.hasFixedBinCount = true;
218 d.sampleType = OutputDescriptor::VariableSampleRate;
222 d = OutputDescriptor();
223 d.identifier = "detectionfunction";
224 d.name = "Onset Detection Function";
226 d.hasFixedBinCount = true;
228 d.hasKnownExtents = false;
229 d.isQuantized = false;
230 d.sampleType = OutputDescriptor::OneSamplePerStep;
237 Onset::process(const float *const *inputBuffers,
238 Vamp::RealTime timestamp)
240 for (size_t i = 0; i < m_stepSize; ++i) {
241 for (size_t j = 0; j < m_channelCount; ++j) {
242 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
246 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
247 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
249 bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
252 if (aubio_silence_detection(m_ibuf, m_silence)) {
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 for (size_t j = 0; j < m_channelCount; ++j) {
271 feature.values.push_back(m_onset->data[j][0]);
273 returnFeatures[1].push_back(feature);
275 return returnFeatures;
279 Onset::getRemainingFeatures()