cannam@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@0
|
2
|
cannam@0
|
3 /*
|
cannam@0
|
4 Vamp feature extraction plugins using Paul Brossier's Aubio library.
|
cannam@0
|
5
|
cannam@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
cannam@0
|
7 This file copyright 2006 Chris Cannam.
|
cannam@0
|
8
|
piem@112
|
9 This file is part of vamp-aubio-plugins.
|
piem@112
|
10
|
piem@112
|
11 vamp-aubio is free software: you can redistribute it and/or modify
|
piem@112
|
12 it under the terms of the GNU General Public License as published by
|
piem@112
|
13 the Free Software Foundation, either version 3 of the License, or
|
piem@112
|
14 (at your option) any later version.
|
piem@112
|
15
|
piem@112
|
16 vamp-aubio is distributed in the hope that it will be useful,
|
piem@112
|
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
piem@112
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
piem@112
|
19 GNU General Public License for more details.
|
piem@112
|
20
|
piem@112
|
21 You should have received a copy of the GNU General Public License
|
piem@112
|
22 along with aubio. If not, see <http://www.gnu.org/licenses/>.
|
cannam@0
|
23
|
cannam@0
|
24 */
|
cannam@0
|
25
|
piem@2
|
26 #include <math.h>
|
cannam@0
|
27 #include "Onset.h"
|
cannam@0
|
28
|
cannam@0
|
29 using std::string;
|
cannam@0
|
30 using std::vector;
|
cannam@0
|
31 using std::cerr;
|
cannam@0
|
32 using std::endl;
|
cannam@0
|
33
|
cannam@0
|
34 Onset::Onset(float inputSampleRate) :
|
cannam@0
|
35 Plugin(inputSampleRate),
|
cannam@0
|
36 m_ibuf(0),
|
cannam@0
|
37 m_onset(0),
|
cannam@0
|
38 m_onsetdet(0),
|
piem@145
|
39 m_onsettype(OnsetDefault),
|
cannam@0
|
40 m_threshold(0.3),
|
cannam@34
|
41 m_silence(-70),
|
cannam@34
|
42 m_minioi(4)
|
cannam@0
|
43 {
|
cannam@0
|
44 }
|
cannam@0
|
45
|
cannam@0
|
46 Onset::~Onset()
|
cannam@0
|
47 {
|
cannam@33
|
48 if (m_onsetdet) del_aubio_onset(m_onsetdet);
|
cannam@0
|
49 if (m_ibuf) del_fvec(m_ibuf);
|
cannam@0
|
50 if (m_onset) del_fvec(m_onset);
|
cannam@0
|
51 }
|
cannam@0
|
52
|
cannam@0
|
53 string
|
cannam@13
|
54 Onset::getIdentifier() const
|
cannam@0
|
55 {
|
cannam@0
|
56 return "aubioonset";
|
cannam@0
|
57 }
|
cannam@0
|
58
|
cannam@0
|
59 string
|
cannam@13
|
60 Onset::getName() const
|
cannam@13
|
61 {
|
cannam@13
|
62 return "Aubio Onset Detector";
|
cannam@13
|
63 }
|
cannam@13
|
64
|
cannam@13
|
65 string
|
cannam@0
|
66 Onset::getDescription() const
|
cannam@0
|
67 {
|
cannam@13
|
68 return "Estimate note onset times";
|
cannam@0
|
69 }
|
cannam@0
|
70
|
cannam@0
|
71 string
|
cannam@0
|
72 Onset::getMaker() const
|
cannam@0
|
73 {
|
cannam@0
|
74 return "Paul Brossier (plugin by Chris Cannam)";
|
cannam@0
|
75 }
|
cannam@0
|
76
|
cannam@0
|
77 int
|
cannam@0
|
78 Onset::getPluginVersion() const
|
cannam@0
|
79 {
|
cannam@31
|
80 return 2;
|
cannam@0
|
81 }
|
cannam@0
|
82
|
cannam@0
|
83 string
|
cannam@0
|
84 Onset::getCopyright() const
|
cannam@0
|
85 {
|
cannam@0
|
86 return "GPL";
|
cannam@0
|
87 }
|
cannam@0
|
88
|
cannam@0
|
89 bool
|
cannam@0
|
90 Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
cannam@0
|
91 {
|
cannam@32
|
92 if (channels != 1) {
|
cannam@32
|
93 std::cerr << "Onset::initialise: channels must be 1" << std::endl;
|
cannam@32
|
94 return false;
|
cannam@32
|
95 }
|
cannam@32
|
96
|
cannam@0
|
97 m_stepSize = stepSize;
|
cannam@0
|
98 m_blockSize = blockSize;
|
cannam@0
|
99
|
cannam@32
|
100 m_ibuf = new_fvec(stepSize);
|
cannam@32
|
101 m_onset = new_fvec(1);
|
cannam@0
|
102
|
cannam@37
|
103 reset();
|
cannam@0
|
104
|
cannam@0
|
105 return true;
|
cannam@0
|
106 }
|
cannam@0
|
107
|
cannam@0
|
108 void
|
cannam@0
|
109 Onset::reset()
|
cannam@0
|
110 {
|
cannam@37
|
111 if (m_onsetdet) del_aubio_onset(m_onsetdet);
|
cannam@37
|
112
|
cannam@37
|
113 m_onsetdet = new_aubio_onset
|
cannam@37
|
114 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)),
|
cannam@37
|
115 m_blockSize,
|
cannam@37
|
116 m_stepSize,
|
cannam@37
|
117 lrintf(m_inputSampleRate));
|
cannam@37
|
118
|
cannam@37
|
119 aubio_onset_set_threshold(m_onsetdet, m_threshold);
|
cannam@37
|
120 aubio_onset_set_silence(m_onsetdet, m_silence);
|
cannam@37
|
121 aubio_onset_set_minioi(m_onsetdet, m_minioi);
|
cannam@37
|
122
|
cannam@37
|
123 m_delay = Vamp::RealTime::frame2RealTime(4 * m_stepSize,
|
cannam@37
|
124 lrintf(m_inputSampleRate));
|
cannam@37
|
125
|
cannam@37
|
126 m_lastOnset = Vamp::RealTime::zeroTime - m_delay - m_delay;
|
cannam@0
|
127 }
|
cannam@0
|
128
|
cannam@0
|
129 size_t
|
cannam@0
|
130 Onset::getPreferredStepSize() const
|
cannam@0
|
131 {
|
piem@2
|
132 return 512;
|
cannam@0
|
133 }
|
cannam@0
|
134
|
cannam@0
|
135 size_t
|
cannam@0
|
136 Onset::getPreferredBlockSize() const
|
cannam@0
|
137 {
|
cannam@3
|
138 return 2 * getPreferredStepSize();
|
cannam@0
|
139 }
|
cannam@0
|
140
|
cannam@0
|
141 Onset::ParameterList
|
cannam@0
|
142 Onset::getParameterDescriptors() const
|
cannam@0
|
143 {
|
cannam@0
|
144 ParameterList list;
|
cannam@0
|
145
|
cannam@0
|
146 ParameterDescriptor desc;
|
cannam@13
|
147 desc.identifier = "onsettype";
|
cannam@13
|
148 desc.name = "Onset Detection Function Type";
|
piem@64
|
149 desc.description = "Type of onset detection function to use";
|
cannam@0
|
150 desc.minValue = 0;
|
cannam@34
|
151 desc.maxValue = 7;
|
piem@145
|
152 desc.defaultValue = (int)OnsetDefault;
|
cannam@0
|
153 desc.isQuantized = true;
|
cannam@0
|
154 desc.quantizeStep = 1;
|
cannam@0
|
155 desc.valueNames.push_back("Energy Based");
|
cannam@0
|
156 desc.valueNames.push_back("Spectral Difference");
|
cannam@0
|
157 desc.valueNames.push_back("High-Frequency Content");
|
cannam@0
|
158 desc.valueNames.push_back("Complex Domain");
|
cannam@0
|
159 desc.valueNames.push_back("Phase Deviation");
|
cannam@0
|
160 desc.valueNames.push_back("Kullback-Liebler");
|
cannam@0
|
161 desc.valueNames.push_back("Modified Kullback-Liebler");
|
cannam@34
|
162 desc.valueNames.push_back("Spectral Flux");
|
piem@145
|
163 desc.valueNames.push_back("Default");
|
cannam@0
|
164 list.push_back(desc);
|
cannam@0
|
165
|
cannam@0
|
166 desc = ParameterDescriptor();
|
cannam@13
|
167 desc.identifier = "peakpickthreshold";
|
cannam@13
|
168 desc.name = "Peak Picker Threshold";
|
piem@64
|
169 desc.description = "Threshold used for peak picking, the higher the more detections";
|
cannam@0
|
170 desc.minValue = 0;
|
cannam@0
|
171 desc.maxValue = 1;
|
cannam@0
|
172 desc.defaultValue = 0.3;
|
cannam@0
|
173 desc.isQuantized = false;
|
cannam@0
|
174 list.push_back(desc);
|
cannam@0
|
175
|
cannam@0
|
176 desc = ParameterDescriptor();
|
cannam@13
|
177 desc.identifier = "silencethreshold";
|
cannam@13
|
178 desc.name = "Silence Threshold";
|
piem@64
|
179 desc.description = "Silence threshold, the higher the least detection";
|
cannam@0
|
180 desc.minValue = -120;
|
cannam@0
|
181 desc.maxValue = 0;
|
cannam@34
|
182 desc.defaultValue = -70;
|
cannam@0
|
183 desc.unit = "dB";
|
cannam@0
|
184 desc.isQuantized = false;
|
cannam@0
|
185 list.push_back(desc);
|
cannam@0
|
186
|
cannam@34
|
187 desc = ParameterDescriptor();
|
cannam@34
|
188 desc.identifier = "minioi";
|
cannam@34
|
189 desc.name = "Minimum Inter-Onset Interval";
|
piem@64
|
190 desc.description = "Time interval below which two consecutive onsets should be merged";
|
cannam@34
|
191 desc.minValue = 0;
|
cannam@34
|
192 desc.maxValue = 40;
|
cannam@34
|
193 desc.defaultValue = 4;
|
cannam@34
|
194 desc.unit = "ms";
|
cannam@34
|
195 desc.isQuantized = true;
|
cannam@34
|
196 desc.quantizeStep = 1;
|
cannam@34
|
197 list.push_back(desc);
|
cannam@34
|
198
|
cannam@0
|
199 return list;
|
cannam@0
|
200 }
|
cannam@0
|
201
|
cannam@0
|
202 float
|
cannam@0
|
203 Onset::getParameter(std::string param) const
|
cannam@0
|
204 {
|
cannam@0
|
205 if (param == "onsettype") {
|
cannam@0
|
206 return m_onsettype;
|
cannam@0
|
207 } else if (param == "peakpickthreshold") {
|
cannam@0
|
208 return m_threshold;
|
cannam@0
|
209 } else if (param == "silencethreshold") {
|
cannam@0
|
210 return m_silence;
|
cannam@34
|
211 } else if (param == "minioi") {
|
cannam@34
|
212 return m_minioi;
|
cannam@0
|
213 } else {
|
cannam@0
|
214 return 0.0;
|
cannam@0
|
215 }
|
cannam@0
|
216 }
|
cannam@0
|
217
|
cannam@0
|
218 void
|
cannam@0
|
219 Onset::setParameter(std::string param, float value)
|
cannam@0
|
220 {
|
cannam@0
|
221 if (param == "onsettype") {
|
cannam@0
|
222 switch (lrintf(value)) {
|
cannam@33
|
223 case 0: m_onsettype = OnsetEnergy; break;
|
cannam@33
|
224 case 1: m_onsettype = OnsetSpecDiff; break;
|
cannam@33
|
225 case 2: m_onsettype = OnsetHFC; break;
|
cannam@33
|
226 case 3: m_onsettype = OnsetComplex; break;
|
cannam@33
|
227 case 4: m_onsettype = OnsetPhase; break;
|
cannam@33
|
228 case 5: m_onsettype = OnsetKL; break;
|
cannam@33
|
229 case 6: m_onsettype = OnsetMKL; break;
|
cannam@34
|
230 case 7: m_onsettype = OnsetSpecFlux; break;
|
cannam@0
|
231 }
|
cannam@0
|
232 } else if (param == "peakpickthreshold") {
|
cannam@0
|
233 m_threshold = value;
|
cannam@0
|
234 } else if (param == "silencethreshold") {
|
cannam@0
|
235 m_silence = value;
|
cannam@34
|
236 } else if (param == "minioi") {
|
cannam@34
|
237 m_minioi = value;
|
cannam@0
|
238 }
|
cannam@0
|
239 }
|
cannam@0
|
240
|
cannam@0
|
241 Onset::OutputList
|
cannam@0
|
242 Onset::getOutputDescriptors() const
|
cannam@0
|
243 {
|
cannam@0
|
244 OutputList list;
|
cannam@0
|
245
|
cannam@0
|
246 OutputDescriptor d;
|
cannam@13
|
247 d.identifier = "onsets";
|
cannam@13
|
248 d.name = "Onsets";
|
piem@64
|
249 d.description = "List of times at which a note onset was detected";
|
cannam@0
|
250 d.unit = "";
|
cannam@0
|
251 d.hasFixedBinCount = true;
|
cannam@0
|
252 d.binCount = 0;
|
cannam@3
|
253 d.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@3
|
254 d.sampleRate = 0;
|
cannam@0
|
255 list.push_back(d);
|
cannam@0
|
256
|
piem@71
|
257 d.identifier = "odf";
|
piem@71
|
258 d.name = "Onset detection function";
|
piem@71
|
259 d.description = "Output of the onset detection function";
|
piem@71
|
260 d.binCount = 1;
|
piem@71
|
261 d.isQuantized = true;
|
piem@71
|
262 d.quantizeStep = 1.0;
|
piem@71
|
263 d.sampleType = OutputDescriptor::OneSamplePerStep;
|
piem@71
|
264 list.push_back(d);
|
piem@71
|
265
|
piem@71
|
266 d.identifier = "todf";
|
piem@71
|
267 d.name = "Thresholded Onset detection function";
|
piem@71
|
268 d.description = "Output of the thresholded onset detection function";
|
piem@71
|
269 d.binCount = 1;
|
piem@71
|
270 d.isQuantized = true;
|
piem@71
|
271 d.quantizeStep = 1.0;
|
piem@71
|
272 d.sampleType = OutputDescriptor::OneSamplePerStep;
|
piem@71
|
273 list.push_back(d);
|
piem@71
|
274
|
cannam@0
|
275 return list;
|
cannam@0
|
276 }
|
cannam@0
|
277
|
cannam@0
|
278 Onset::FeatureSet
|
cannam@12
|
279 Onset::process(const float *const *inputBuffers,
|
cannam@12
|
280 Vamp::RealTime timestamp)
|
cannam@0
|
281 {
|
cannam@0
|
282 for (size_t i = 0; i < m_stepSize; ++i) {
|
piem@52
|
283 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
|
cannam@0
|
284 }
|
cannam@0
|
285
|
cannam@33
|
286 aubio_onset_do(m_onsetdet, m_ibuf, m_onset);
|
cannam@0
|
287
|
cannam@34
|
288 bool isonset = m_onset->data[0];
|
cannam@0
|
289
|
cannam@0
|
290 FeatureSet returnFeatures;
|
cannam@0
|
291
|
cannam@0
|
292 if (isonset) {
|
cannam@3
|
293 if (timestamp - m_lastOnset >= m_delay) {
|
cannam@3
|
294 Feature onsettime;
|
cannam@3
|
295 onsettime.hasTimestamp = true;
|
piem@5
|
296 if (timestamp < m_delay) timestamp = m_delay;
|
cannam@3
|
297 onsettime.timestamp = timestamp - m_delay;
|
cannam@3
|
298 returnFeatures[0].push_back(onsettime);
|
cannam@3
|
299 m_lastOnset = timestamp;
|
cannam@3
|
300 }
|
cannam@0
|
301 }
|
cannam@38
|
302
|
piem@71
|
303 Feature odf;
|
piem@71
|
304 odf.hasTimestamp = false;
|
piem@71
|
305 odf.values.push_back(aubio_onset_get_descriptor(m_onsetdet));
|
piem@71
|
306 returnFeatures[1].push_back(odf);
|
piem@71
|
307
|
piem@71
|
308 Feature todf;
|
piem@71
|
309 todf.hasTimestamp = false;
|
piem@71
|
310 todf.values.push_back(aubio_onset_get_thresholded_descriptor(m_onsetdet));
|
piem@71
|
311 returnFeatures[2].push_back(todf);
|
piem@71
|
312
|
cannam@0
|
313 return returnFeatures;
|
cannam@0
|
314 }
|
cannam@0
|
315
|
cannam@0
|
316 Onset::FeatureSet
|
cannam@0
|
317 Onset::getRemainingFeatures()
|
cannam@0
|
318 {
|
cannam@0
|
319 return FeatureSet();
|
cannam@0
|
320 }
|
cannam@0
|
321
|