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);
104 Onset::getPreferredStepSize() const
110 Onset::getPreferredBlockSize() const
112 return 2*getPreferredStepSize();
116 Onset::getParameterDescriptors() const
120 ParameterDescriptor desc;
121 desc.name = "onsettype";
122 desc.description = "Onset Detection Function Type";
125 desc.defaultValue = (int)aubio_onset_complex;
126 desc.isQuantized = true;
127 desc.quantizeStep = 1;
128 desc.valueNames.push_back("Energy Based");
129 desc.valueNames.push_back("Spectral Difference");
130 desc.valueNames.push_back("High-Frequency Content");
131 desc.valueNames.push_back("Complex Domain");
132 desc.valueNames.push_back("Phase Deviation");
133 desc.valueNames.push_back("Kullback-Liebler");
134 desc.valueNames.push_back("Modified Kullback-Liebler");
135 list.push_back(desc);
137 desc = ParameterDescriptor();
138 desc.name = "peakpickthreshold";
139 desc.description = "Peak Picker Threshold";
142 desc.defaultValue = 0.3;
143 desc.isQuantized = false;
144 list.push_back(desc);
146 desc = ParameterDescriptor();
147 desc.name = "silencethreshold";
148 desc.description = "Silence Threshold";
149 desc.minValue = -120;
151 desc.defaultValue = -90;
153 desc.isQuantized = false;
154 list.push_back(desc);
160 Onset::getParameter(std::string param) const
162 if (param == "onsettype") {
164 } else if (param == "peakpickthreshold") {
166 } else if (param == "silencethreshold") {
174 Onset::setParameter(std::string param, float value)
176 if (param == "onsettype") {
177 switch (lrintf(value)) {
178 case 0: m_onsettype = aubio_onset_energy; break;
179 case 1: m_onsettype = aubio_onset_specdiff; break;
180 case 2: m_onsettype = aubio_onset_hfc; break;
181 case 3: m_onsettype = aubio_onset_complex; break;
182 case 4: m_onsettype = aubio_onset_phase; break;
183 case 5: m_onsettype = aubio_onset_kl; break;
184 case 6: m_onsettype = aubio_onset_mkl; break;
186 } else if (param == "peakpickthreshold") {
188 } else if (param == "silencethreshold") {
194 Onset::getOutputDescriptors() const
201 d.description = "Onsets";
202 d.hasFixedBinCount = true;
204 d.sampleType = OutputDescriptor::OneSamplePerStep;
207 d = OutputDescriptor();
208 d.name = "detectionfunction";
210 d.description = "Onset Detection Function";
211 d.hasFixedBinCount = true;
212 d.binCount = m_channelCount;
213 d.hasKnownExtents = false;
214 d.isQuantized = false;
215 d.sampleType = OutputDescriptor::OneSamplePerStep;
222 Onset::process(float **inputBuffers, Vamp::RealTime /* timestamp */)
224 for (size_t i = 0; i < m_stepSize; ++i) {
225 for (size_t j = 0; j < m_channelCount; ++j) {
226 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
230 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
231 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
233 bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
236 if (aubio_silence_detection(m_ibuf, m_silence)) {
241 FeatureSet returnFeatures;
245 onsettime.hasTimestamp = false;
246 returnFeatures[0].push_back(onsettime);
249 for (size_t j = 0; j < m_channelCount; ++j) {
250 feature.values.push_back(m_onset->data[j][0]);
252 returnFeatures[1].push_back(feature);
254 return returnFeatures;
258 Onset::getRemainingFeatures()