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.
24 Onset::Onset(float inputSampleRate) :
25 Plugin(inputSampleRate),
32 m_onsettype(aubio_onset_mkl),
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::getName() const
56 Onset::getDescription() const
58 return "Aubio Onset Detector";
62 Onset::getMaker() const
64 return "Paul Brossier (plugin by Chris Cannam)";
68 Onset::getPluginVersion() const
74 Onset::getCopyright() const
80 Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
82 m_channelCount = channels;
83 m_stepSize = stepSize;
84 m_blockSize = blockSize;
86 size_t processingBlockSize;
87 if (m_onsettype == aubio_onset_energy ||
88 m_onsettype == aubio_onset_hfc) {
89 processingBlockSize = stepSize * 2;
91 processingBlockSize = stepSize * 4;
94 m_ibuf = new_fvec(stepSize, channels);
95 m_onset = new_fvec(1, channels);
96 m_fftgrain = new_cvec(processingBlockSize, channels);
97 m_pv = new_aubio_pvoc(processingBlockSize, stepSize, channels);
98 m_peakpick = new_aubio_peakpicker(m_threshold);
100 m_onsetdet = new_aubio_onsetdetection(m_onsettype, processingBlockSize, channels);
111 Onset::getPreferredStepSize() const
113 if (m_onsettype == aubio_onset_energy ||
114 m_onsettype == aubio_onset_hfc) {
122 Onset::getPreferredBlockSize() const
124 return getPreferredStepSize();
128 Onset::getParameterDescriptors() const
132 ParameterDescriptor desc;
133 desc.name = "onsettype";
134 desc.description = "Onset Detection Function Type";
137 desc.defaultValue = (int)aubio_onset_mkl;
138 desc.isQuantized = true;
139 desc.quantizeStep = 1;
140 desc.valueNames.push_back("Energy Based");
141 desc.valueNames.push_back("Spectral Difference");
142 desc.valueNames.push_back("High-Frequency Content");
143 desc.valueNames.push_back("Complex Domain");
144 desc.valueNames.push_back("Phase Deviation");
145 desc.valueNames.push_back("Kullback-Liebler");
146 desc.valueNames.push_back("Modified Kullback-Liebler");
147 list.push_back(desc);
149 desc = ParameterDescriptor();
150 desc.name = "peakpickthreshold";
151 desc.description = "Peak Picker Threshold";
154 desc.defaultValue = 0.3;
155 desc.isQuantized = false;
156 list.push_back(desc);
158 desc = ParameterDescriptor();
159 desc.name = "silencethreshold";
160 desc.description = "Silence Threshold";
161 desc.minValue = -120;
163 desc.defaultValue = -90;
165 desc.isQuantized = false;
166 list.push_back(desc);
172 Onset::getParameter(std::string param) const
174 if (param == "onsettype") {
176 } else if (param == "peakpickthreshold") {
178 } else if (param == "silencethreshold") {
186 Onset::setParameter(std::string param, float value)
188 if (param == "onsettype") {
189 switch (lrintf(value)) {
190 case 0: m_onsettype = aubio_onset_energy; break;
191 case 1: m_onsettype = aubio_onset_specdiff; break;
192 case 2: m_onsettype = aubio_onset_hfc; break;
193 case 3: m_onsettype = aubio_onset_complex; break;
194 case 4: m_onsettype = aubio_onset_phase; break;
195 case 5: m_onsettype = aubio_onset_kl; break;
196 case 6: m_onsettype = aubio_onset_mkl; break;
198 } else if (param == "peakpickthreshold") {
200 } else if (param == "silencethreshold") {
206 Onset::getOutputDescriptors() const
213 d.description = "Onsets";
214 d.hasFixedBinCount = true;
216 d.sampleType = OutputDescriptor::OneSamplePerStep;
219 d = OutputDescriptor();
220 d.name = "detectionfunction";
222 d.description = "Onset Detection Function";
223 d.hasFixedBinCount = true;
224 d.binCount = m_channelCount;
225 d.hasKnownExtents = false;
226 d.isQuantized = false;
227 d.sampleType = OutputDescriptor::OneSamplePerStep;
234 Onset::process(float **inputBuffers, Vamp::RealTime /* timestamp */)
236 for (size_t i = 0; i < m_stepSize; ++i) {
237 for (size_t j = 0; j < m_channelCount; ++j) {
238 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
242 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
243 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
245 bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
248 if (aubio_silence_detection(m_ibuf, m_silence)) {
253 FeatureSet returnFeatures;
256 returnFeatures[0].push_back(Feature());
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()