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),
42 if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet);
43 if (m_ibuf) del_fvec(m_ibuf);
44 if (m_onset) del_fvec(m_onset);
45 if (m_fftgrain) del_cvec(m_fftgrain);
46 if (m_pv) del_aubio_pvoc(m_pv);
47 if (m_peakpick) del_aubio_peakpicker(m_peakpick);
51 Onset::getName() const
57 Onset::getDescription() const
59 return "Aubio Onset Detector";
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)
83 m_channelCount = channels;
84 m_stepSize = stepSize;
85 m_blockSize = blockSize;
87 m_ibuf = new_fvec(stepSize, channels);
88 m_onset = new_fvec(1, channels);
89 m_fftgrain = new_cvec(blockSize, channels);
90 m_pv = new_aubio_pvoc(blockSize, stepSize, channels);
91 m_peakpick = new_aubio_peakpicker(m_threshold);
93 m_onsetdet = new_aubio_onsetdetection(m_onsettype, blockSize, channels);
95 m_delay = Vamp::RealTime::frame2RealTime(4 * stepSize,
96 lrintf(m_inputSampleRate));
98 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
109 Onset::getPreferredStepSize() const
115 Onset::getPreferredBlockSize() const
117 return 2 * getPreferredStepSize();
121 Onset::getParameterDescriptors() const
125 ParameterDescriptor desc;
126 desc.name = "onsettype";
127 desc.description = "Onset Detection Function Type";
130 desc.defaultValue = (int)aubio_onset_complex;
131 desc.isQuantized = true;
132 desc.quantizeStep = 1;
133 desc.valueNames.push_back("Energy Based");
134 desc.valueNames.push_back("Spectral Difference");
135 desc.valueNames.push_back("High-Frequency Content");
136 desc.valueNames.push_back("Complex Domain");
137 desc.valueNames.push_back("Phase Deviation");
138 desc.valueNames.push_back("Kullback-Liebler");
139 desc.valueNames.push_back("Modified Kullback-Liebler");
140 list.push_back(desc);
142 desc = ParameterDescriptor();
143 desc.name = "peakpickthreshold";
144 desc.description = "Peak Picker Threshold";
147 desc.defaultValue = 0.3;
148 desc.isQuantized = false;
149 list.push_back(desc);
151 desc = ParameterDescriptor();
152 desc.name = "silencethreshold";
153 desc.description = "Silence Threshold";
154 desc.minValue = -120;
156 desc.defaultValue = -90;
158 desc.isQuantized = false;
159 list.push_back(desc);
165 Onset::getParameter(std::string param) const
167 if (param == "onsettype") {
169 } else if (param == "peakpickthreshold") {
171 } else if (param == "silencethreshold") {
179 Onset::setParameter(std::string param, float value)
181 if (param == "onsettype") {
182 switch (lrintf(value)) {
183 case 0: m_onsettype = aubio_onset_energy; break;
184 case 1: m_onsettype = aubio_onset_specdiff; break;
185 case 2: m_onsettype = aubio_onset_hfc; break;
186 case 3: m_onsettype = aubio_onset_complex; break;
187 case 4: m_onsettype = aubio_onset_phase; break;
188 case 5: m_onsettype = aubio_onset_kl; break;
189 case 6: m_onsettype = aubio_onset_mkl; break;
191 } else if (param == "peakpickthreshold") {
193 } else if (param == "silencethreshold") {
199 Onset::getOutputDescriptors() const
206 d.description = "Onsets";
207 d.hasFixedBinCount = true;
209 d.sampleType = OutputDescriptor::VariableSampleRate;
213 d = OutputDescriptor();
214 d.name = "detectionfunction";
216 d.description = "Onset Detection Function";
217 d.hasFixedBinCount = true;
218 d.binCount = m_channelCount;
219 d.hasKnownExtents = false;
220 d.isQuantized = false;
221 d.sampleType = OutputDescriptor::OneSamplePerStep;
228 Onset::process(float **inputBuffers, Vamp::RealTime timestamp)
230 for (size_t i = 0; i < m_stepSize; ++i) {
231 for (size_t j = 0; j < m_channelCount; ++j) {
232 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
236 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
237 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
239 bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
242 if (aubio_silence_detection(m_ibuf, m_silence)) {
247 FeatureSet returnFeatures;
250 if (timestamp - m_lastOnset >= m_delay) {
252 onsettime.hasTimestamp = true;
253 onsettime.timestamp = timestamp - m_delay;
254 returnFeatures[0].push_back(onsettime);
255 m_lastOnset = timestamp;
259 for (size_t j = 0; j < m_channelCount; ++j) {
260 feature.values.push_back(m_onset->data[j][0]);
262 returnFeatures[1].push_back(feature);
264 return returnFeatures;
268 Onset::getRemainingFeatures()