Chris@0
|
1
|
Chris@49
|
2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
3
|
Chris@0
|
4 /*
|
Chris@52
|
5 Sonic Visualiser
|
Chris@52
|
6 An audio file viewer and annotation editor.
|
Chris@52
|
7 Centre for Digital Music, Queen Mary, University of London.
|
Chris@52
|
8 This file copyright 2006 Chris Cannam.
|
Chris@0
|
9
|
Chris@52
|
10 This program is free software; you can redistribute it and/or
|
Chris@52
|
11 modify it under the terms of the GNU General Public License as
|
Chris@52
|
12 published by the Free Software Foundation; either version 2 of the
|
Chris@52
|
13 License, or (at your option) any later version. See the file
|
Chris@52
|
14 COPYING included with this distribution for more information.
|
Chris@0
|
15 */
|
Chris@0
|
16
|
Chris@0
|
17 #include "FeatureExtractionPluginTransform.h"
|
Chris@0
|
18
|
Chris@0
|
19 #include "plugin/FeatureExtractionPluginFactory.h"
|
Chris@66
|
20 #include "plugin/PluginXml.h"
|
Chris@66
|
21 #include "vamp-sdk/Plugin.h"
|
Chris@0
|
22
|
Chris@0
|
23 #include "base/Model.h"
|
Chris@67
|
24 #include "base/Window.h"
|
Chris@0
|
25 #include "model/SparseOneDimensionalModel.h"
|
Chris@0
|
26 #include "model/SparseTimeValueModel.h"
|
Chris@0
|
27 #include "model/DenseThreeDimensionalModel.h"
|
Chris@0
|
28 #include "model/DenseTimeValueModel.h"
|
Chris@115
|
29 #include "model/NoteModel.h"
|
Chris@0
|
30
|
Chris@67
|
31 #include <fftw3.h>
|
Chris@67
|
32
|
Chris@0
|
33 #include <iostream>
|
Chris@0
|
34
|
Chris@0
|
35 FeatureExtractionPluginTransform::FeatureExtractionPluginTransform(Model *inputModel,
|
Chris@0
|
36 QString pluginId,
|
Chris@64
|
37 int channel,
|
Chris@56
|
38 QString configurationXml,
|
Chris@0
|
39 QString outputName) :
|
Chris@0
|
40 Transform(inputModel),
|
Chris@0
|
41 m_plugin(0),
|
Chris@64
|
42 m_channel(channel),
|
Chris@68
|
43 m_stepSize(0),
|
Chris@68
|
44 m_blockSize(0),
|
Chris@0
|
45 m_descriptor(0),
|
Chris@0
|
46 m_outputFeatureNo(0)
|
Chris@0
|
47 {
|
Chris@117
|
48 // std::cerr << "FeatureExtractionPluginTransform::FeatureExtractionPluginTransform: plugin " << pluginId.toStdString() << ", outputName " << outputName.toStdString() << std::endl;
|
Chris@0
|
49
|
Chris@0
|
50 FeatureExtractionPluginFactory *factory =
|
Chris@0
|
51 FeatureExtractionPluginFactory::instanceFor(pluginId);
|
Chris@0
|
52
|
Chris@0
|
53 if (!factory) {
|
Chris@0
|
54 std::cerr << "FeatureExtractionPluginTransform: No factory available for plugin id \""
|
Chris@0
|
55 << pluginId.toStdString() << "\"" << std::endl;
|
Chris@0
|
56 return;
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 m_plugin = factory->instantiatePlugin(pluginId, m_input->getSampleRate());
|
Chris@0
|
60
|
Chris@0
|
61 if (!m_plugin) {
|
Chris@0
|
62 std::cerr << "FeatureExtractionPluginTransform: Failed to instantiate plugin \""
|
Chris@0
|
63 << pluginId.toStdString() << "\"" << std::endl;
|
Chris@0
|
64 return;
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@56
|
67 if (configurationXml != "") {
|
Chris@66
|
68 PluginXml(m_plugin).setParametersFromXml(configurationXml);
|
Chris@56
|
69 }
|
Chris@56
|
70
|
Chris@68
|
71 m_blockSize = m_plugin->getPreferredBlockSize();
|
Chris@68
|
72 m_stepSize = m_plugin->getPreferredStepSize();
|
Chris@68
|
73
|
Chris@68
|
74 if (m_blockSize == 0) m_blockSize = 1024; //!!! todo: ask user
|
Chris@68
|
75 if (m_stepSize == 0) m_stepSize = m_blockSize; //!!! likewise
|
Chris@68
|
76
|
Chris@114
|
77 DenseTimeValueModel *input = getInput();
|
Chris@114
|
78 if (!input) return;
|
Chris@114
|
79
|
Chris@114
|
80 size_t channelCount = input->getChannelCount();
|
Chris@114
|
81 if (m_plugin->getMaxChannelCount() < channelCount) {
|
Chris@114
|
82 channelCount = 1;
|
Chris@114
|
83 }
|
Chris@114
|
84 if (m_plugin->getMinChannelCount() > channelCount) {
|
Chris@114
|
85 std::cerr << "FeatureExtractionPluginTransform:: "
|
Chris@114
|
86 << "Can't provide enough channels to plugin (plugin min "
|
Chris@114
|
87 << m_plugin->getMinChannelCount() << ", max "
|
Chris@114
|
88 << m_plugin->getMaxChannelCount() << ", input model has "
|
Chris@114
|
89 << input->getChannelCount() << ")" << std::endl;
|
Chris@114
|
90 return;
|
Chris@114
|
91 }
|
Chris@114
|
92
|
Chris@114
|
93 if (!m_plugin->initialise(channelCount, m_stepSize, m_blockSize)) {
|
Chris@114
|
94 std::cerr << "FeatureExtractionPluginTransform: Plugin "
|
Chris@114
|
95 << m_plugin->getName() << " failed to initialise!" << std::endl;
|
Chris@114
|
96 return;
|
Chris@114
|
97 }
|
Chris@114
|
98
|
Chris@74
|
99 Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors();
|
Chris@0
|
100
|
Chris@0
|
101 if (outputs.empty()) {
|
Chris@0
|
102 std::cerr << "FeatureExtractionPluginTransform: Plugin \""
|
Chris@0
|
103 << pluginId.toStdString() << "\" has no outputs" << std::endl;
|
Chris@0
|
104 return;
|
Chris@0
|
105 }
|
Chris@0
|
106
|
Chris@0
|
107 for (size_t i = 0; i < outputs.size(); ++i) {
|
Chris@0
|
108 if (outputName == "" || outputs[i].name == outputName.toStdString()) {
|
Chris@0
|
109 m_outputFeatureNo = i;
|
Chris@66
|
110 m_descriptor = new Vamp::Plugin::OutputDescriptor
|
Chris@0
|
111 (outputs[i]);
|
Chris@0
|
112 break;
|
Chris@0
|
113 }
|
Chris@0
|
114 }
|
Chris@0
|
115
|
Chris@0
|
116 if (!m_descriptor) {
|
Chris@0
|
117 std::cerr << "FeatureExtractionPluginTransform: Plugin \""
|
Chris@0
|
118 << pluginId.toStdString() << "\" has no output named \""
|
Chris@0
|
119 << outputName.toStdString() << "\"" << std::endl;
|
Chris@0
|
120 return;
|
Chris@0
|
121 }
|
Chris@0
|
122
|
Chris@117
|
123 // std::cerr << "FeatureExtractionPluginTransform: output sample type "
|
Chris@117
|
124 // << m_descriptor->sampleType << std::endl;
|
Chris@0
|
125
|
Chris@70
|
126 int binCount = 1;
|
Chris@0
|
127 float minValue = 0.0, maxValue = 0.0;
|
Chris@0
|
128
|
Chris@70
|
129 if (m_descriptor->hasFixedBinCount) {
|
Chris@70
|
130 binCount = m_descriptor->binCount;
|
Chris@0
|
131 }
|
Chris@0
|
132
|
Chris@117
|
133 // std::cerr << "FeatureExtractionPluginTransform: output bin count "
|
Chris@117
|
134 // << binCount << std::endl;
|
Chris@114
|
135
|
Chris@70
|
136 if (binCount > 0 && m_descriptor->hasKnownExtents) {
|
Chris@0
|
137 minValue = m_descriptor->minValue;
|
Chris@0
|
138 maxValue = m_descriptor->maxValue;
|
Chris@0
|
139 }
|
Chris@0
|
140
|
Chris@0
|
141 size_t modelRate = m_input->getSampleRate();
|
Chris@0
|
142 size_t modelResolution = 1;
|
Chris@0
|
143
|
Chris@0
|
144 switch (m_descriptor->sampleType) {
|
Chris@0
|
145
|
Chris@66
|
146 case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
|
Chris@0
|
147 if (m_descriptor->sampleRate != 0.0) {
|
Chris@0
|
148 modelResolution = size_t(modelRate / m_descriptor->sampleRate + 0.001);
|
Chris@0
|
149 }
|
Chris@0
|
150 break;
|
Chris@0
|
151
|
Chris@66
|
152 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep:
|
Chris@72
|
153 modelResolution = m_stepSize;
|
Chris@0
|
154 break;
|
Chris@0
|
155
|
Chris@66
|
156 case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
|
Chris@73
|
157 modelRate = size_t(m_descriptor->sampleRate + 0.001);
|
Chris@0
|
158 break;
|
Chris@0
|
159 }
|
Chris@0
|
160
|
Chris@70
|
161 if (binCount == 0) {
|
Chris@0
|
162
|
Chris@20
|
163 m_output = new SparseOneDimensionalModel(modelRate, modelResolution,
|
Chris@20
|
164 false);
|
Chris@0
|
165
|
Chris@115
|
166 } else if (binCount == 1) {
|
Chris@0
|
167
|
Chris@115
|
168 SparseTimeValueModel *model = new SparseTimeValueModel
|
Chris@115
|
169 (modelRate, modelResolution, minValue, maxValue, false);
|
Chris@115
|
170 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str());
|
Chris@115
|
171
|
Chris@115
|
172 m_output = model;
|
Chris@115
|
173
|
Chris@115
|
174 } else if (m_descriptor->sampleType ==
|
Chris@66
|
175 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@115
|
176
|
Chris@115
|
177 // We don't have a sparse 3D model, so interpret this as a
|
Chris@115
|
178 // note model. There's nothing to define which values to use
|
Chris@115
|
179 // as which parameters of the note -- for the moment let's
|
Chris@115
|
180 // treat the first as pitch, second as duration in frames,
|
Chris@115
|
181 // third (if present) as velocity. (Our note model doesn't
|
Chris@115
|
182 // yet store velocity.)
|
Chris@115
|
183 //!!! todo: ask the user!
|
Chris@0
|
184
|
Chris@115
|
185 NoteModel *model = new NoteModel
|
Chris@63
|
186 (modelRate, modelResolution, minValue, maxValue, false);
|
Chris@63
|
187 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str());
|
Chris@63
|
188
|
Chris@63
|
189 m_output = model;
|
Chris@0
|
190
|
Chris@0
|
191 } else {
|
Chris@0
|
192
|
Chris@0
|
193 m_output = new DenseThreeDimensionalModel(modelRate, modelResolution,
|
Chris@70
|
194 binCount, false);
|
Chris@20
|
195
|
Chris@70
|
196 if (!m_descriptor->binNames.empty()) {
|
Chris@20
|
197 std::vector<QString> names;
|
Chris@70
|
198 for (size_t i = 0; i < m_descriptor->binNames.size(); ++i) {
|
Chris@70
|
199 names.push_back(m_descriptor->binNames[i].c_str());
|
Chris@20
|
200 }
|
Chris@20
|
201 (dynamic_cast<DenseThreeDimensionalModel *>(m_output))
|
Chris@20
|
202 ->setBinNames(names);
|
Chris@20
|
203 }
|
Chris@0
|
204 }
|
Chris@0
|
205 }
|
Chris@0
|
206
|
Chris@0
|
207 FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform()
|
Chris@0
|
208 {
|
Chris@0
|
209 delete m_plugin;
|
Chris@0
|
210 delete m_descriptor;
|
Chris@0
|
211 }
|
Chris@0
|
212
|
Chris@0
|
213 DenseTimeValueModel *
|
Chris@0
|
214 FeatureExtractionPluginTransform::getInput()
|
Chris@0
|
215 {
|
Chris@0
|
216 DenseTimeValueModel *dtvm =
|
Chris@0
|
217 dynamic_cast<DenseTimeValueModel *>(getInputModel());
|
Chris@0
|
218 if (!dtvm) {
|
Chris@0
|
219 std::cerr << "FeatureExtractionPluginTransform::getInput: WARNING: Input model is not conformable to DenseTimeValueModel" << std::endl;
|
Chris@0
|
220 }
|
Chris@0
|
221 return dtvm;
|
Chris@0
|
222 }
|
Chris@0
|
223
|
Chris@0
|
224 void
|
Chris@0
|
225 FeatureExtractionPluginTransform::run()
|
Chris@0
|
226 {
|
Chris@0
|
227 DenseTimeValueModel *input = getInput();
|
Chris@0
|
228 if (!input) return;
|
Chris@0
|
229
|
Chris@0
|
230 if (!m_output) return;
|
Chris@0
|
231
|
Chris@114
|
232 size_t sampleRate = m_input->getSampleRate();
|
Chris@114
|
233
|
Chris@0
|
234 size_t channelCount = input->getChannelCount();
|
Chris@0
|
235 if (m_plugin->getMaxChannelCount() < channelCount) {
|
Chris@0
|
236 channelCount = 1;
|
Chris@0
|
237 }
|
Chris@0
|
238
|
Chris@0
|
239 float **buffers = new float*[channelCount];
|
Chris@0
|
240 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@68
|
241 buffers[ch] = new float[m_blockSize];
|
Chris@0
|
242 }
|
Chris@0
|
243
|
Chris@122
|
244 float *fftInput = 0;
|
Chris@122
|
245 fftwf_complex *fftOutput = 0;
|
Chris@122
|
246 fftwf_plan fftPlan = 0;
|
Chris@122
|
247 Window<float> windower(HanningWindow, m_blockSize);
|
Chris@67
|
248
|
Chris@67
|
249 if (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
|
Chris@67
|
250
|
Chris@122
|
251 fftInput = (float *)fftwf_malloc(m_blockSize * sizeof(double));
|
Chris@122
|
252 fftOutput = (fftwf_complex *)fftwf_malloc(m_blockSize * sizeof(fftwf_complex));
|
Chris@122
|
253 fftPlan = fftwf_plan_dft_r2c_1d(m_blockSize, fftInput, fftOutput,
|
Chris@122
|
254 FFTW_ESTIMATE);
|
Chris@67
|
255 if (!fftPlan) {
|
Chris@67
|
256 std::cerr << "ERROR: FeatureExtractionPluginTransform::run(): fftw_plan failed! Results will be garbage" << std::endl;
|
Chris@67
|
257 }
|
Chris@67
|
258 }
|
Chris@67
|
259
|
Chris@70
|
260 long startFrame = m_input->getStartFrame();
|
Chris@70
|
261 long endFrame = m_input->getEndFrame();
|
Chris@70
|
262 long blockFrame = startFrame;
|
Chris@0
|
263
|
Chris@70
|
264 long prevCompletion = 0;
|
Chris@0
|
265
|
Chris@70
|
266 while (1) {
|
Chris@70
|
267
|
Chris@70
|
268 if (fftPlan) {
|
Chris@73
|
269 if (blockFrame - int(m_blockSize)/2 > endFrame) break;
|
Chris@70
|
270 } else {
|
Chris@70
|
271 if (blockFrame >= endFrame) break;
|
Chris@70
|
272 }
|
Chris@0
|
273
|
Chris@0
|
274 // std::cerr << "FeatureExtractionPluginTransform::run: blockFrame "
|
Chris@0
|
275 // << blockFrame << std::endl;
|
Chris@0
|
276
|
Chris@70
|
277 long completion =
|
Chris@68
|
278 (((blockFrame - startFrame) / m_stepSize) * 99) /
|
Chris@68
|
279 ( (endFrame - startFrame) / m_stepSize);
|
Chris@0
|
280
|
Chris@0
|
281 // channelCount is either m_input->channelCount or 1
|
Chris@0
|
282
|
Chris@73
|
283 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@70
|
284 if (fftPlan) {
|
Chris@70
|
285 getFrames(ch, channelCount,
|
Chris@70
|
286 blockFrame - m_blockSize/2, m_blockSize, buffers[ch]);
|
Chris@70
|
287 } else {
|
Chris@70
|
288 getFrames(ch, channelCount,
|
Chris@70
|
289 blockFrame, m_blockSize, buffers[ch]);
|
Chris@70
|
290 }
|
Chris@70
|
291 }
|
Chris@70
|
292
|
Chris@67
|
293 if (fftPlan) {
|
Chris@73
|
294 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@73
|
295 for (size_t i = 0; i < m_blockSize; ++i) {
|
Chris@67
|
296 fftInput[i] = buffers[ch][i];
|
Chris@67
|
297 }
|
Chris@67
|
298 windower.cut(fftInput);
|
Chris@73
|
299 for (size_t i = 0; i < m_blockSize/2; ++i) {
|
Chris@122
|
300 float temp = fftInput[i];
|
Chris@68
|
301 fftInput[i] = fftInput[i + m_blockSize/2];
|
Chris@68
|
302 fftInput[i + m_blockSize/2] = temp;
|
Chris@67
|
303 }
|
Chris@122
|
304 fftwf_execute(fftPlan);
|
Chris@73
|
305 for (size_t i = 0; i < m_blockSize/2; ++i) {
|
Chris@67
|
306 buffers[ch][i*2] = fftOutput[i][0];
|
Chris@67
|
307 buffers[ch][i*2 + 1] = fftOutput[i][1];
|
Chris@67
|
308 }
|
Chris@67
|
309 }
|
Chris@67
|
310 }
|
Chris@67
|
311
|
Chris@66
|
312 Vamp::Plugin::FeatureSet features = m_plugin->process
|
Chris@66
|
313 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate));
|
Chris@0
|
314
|
Chris@0
|
315 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) {
|
Chris@66
|
316 Vamp::Plugin::Feature feature =
|
Chris@0
|
317 features[m_outputFeatureNo][fi];
|
Chris@0
|
318 addFeature(blockFrame, feature);
|
Chris@0
|
319 }
|
Chris@0
|
320
|
Chris@0
|
321 if (blockFrame == startFrame || completion > prevCompletion) {
|
Chris@0
|
322 setCompletion(completion);
|
Chris@0
|
323 prevCompletion = completion;
|
Chris@0
|
324 }
|
Chris@0
|
325
|
Chris@68
|
326 blockFrame += m_stepSize;
|
Chris@0
|
327 }
|
Chris@0
|
328
|
Chris@67
|
329 if (fftPlan) {
|
Chris@122
|
330 fftwf_destroy_plan(fftPlan);
|
Chris@122
|
331 fftwf_free(fftInput);
|
Chris@122
|
332 fftwf_free(fftOutput);
|
Chris@67
|
333 }
|
Chris@67
|
334
|
Chris@66
|
335 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures();
|
Chris@0
|
336
|
Chris@0
|
337 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) {
|
Chris@66
|
338 Vamp::Plugin::Feature feature =
|
Chris@0
|
339 features[m_outputFeatureNo][fi];
|
Chris@0
|
340 addFeature(blockFrame, feature);
|
Chris@0
|
341 }
|
Chris@0
|
342
|
Chris@0
|
343 setCompletion(100);
|
Chris@0
|
344 }
|
Chris@0
|
345
|
Chris@70
|
346 void
|
Chris@70
|
347 FeatureExtractionPluginTransform::getFrames(int channel, int channelCount,
|
Chris@70
|
348 long startFrame, long size,
|
Chris@70
|
349 float *buffer)
|
Chris@70
|
350 {
|
Chris@70
|
351 long offset = 0;
|
Chris@70
|
352
|
Chris@70
|
353 if (startFrame < 0) {
|
Chris@70
|
354 for (int i = 0; i < size && startFrame + i < 0; ++i) {
|
Chris@70
|
355 buffer[i] = 0.0f;
|
Chris@70
|
356 }
|
Chris@70
|
357 offset = -startFrame;
|
Chris@70
|
358 size -= offset;
|
Chris@70
|
359 if (size <= 0) return;
|
Chris@70
|
360 startFrame = 0;
|
Chris@70
|
361 }
|
Chris@70
|
362
|
Chris@73
|
363 long got = getInput()->getValues
|
Chris@70
|
364 ((channelCount == 1 ? m_channel : channel),
|
Chris@70
|
365 startFrame, startFrame + size, buffer + offset);
|
Chris@70
|
366
|
Chris@70
|
367 while (got < size) {
|
Chris@70
|
368 buffer[offset + got] = 0.0;
|
Chris@70
|
369 ++got;
|
Chris@70
|
370 }
|
Chris@74
|
371
|
Chris@74
|
372 if (m_channel == -1 && channelCount == 1 &&
|
Chris@74
|
373 getInput()->getChannelCount() > 1) {
|
Chris@74
|
374 // use mean instead of sum, as plugin input
|
Chris@74
|
375 int cc = getInput()->getChannelCount();
|
Chris@74
|
376 for (long i = 0; i < size; ++i) {
|
Chris@74
|
377 buffer[i] /= cc;
|
Chris@74
|
378 }
|
Chris@74
|
379 }
|
Chris@70
|
380 }
|
Chris@0
|
381
|
Chris@0
|
382 void
|
Chris@0
|
383 FeatureExtractionPluginTransform::addFeature(size_t blockFrame,
|
Chris@66
|
384 const Vamp::Plugin::Feature &feature)
|
Chris@0
|
385 {
|
Chris@0
|
386 size_t inputRate = m_input->getSampleRate();
|
Chris@0
|
387
|
Chris@0
|
388 // std::cerr << "FeatureExtractionPluginTransform::addFeature("
|
Chris@0
|
389 // << blockFrame << ")" << std::endl;
|
Chris@0
|
390
|
Chris@70
|
391 int binCount = 1;
|
Chris@70
|
392 if (m_descriptor->hasFixedBinCount) {
|
Chris@70
|
393 binCount = m_descriptor->binCount;
|
Chris@0
|
394 }
|
Chris@0
|
395
|
Chris@0
|
396 size_t frame = blockFrame;
|
Chris@0
|
397
|
Chris@0
|
398 if (m_descriptor->sampleType ==
|
Chris@66
|
399 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@0
|
400
|
Chris@0
|
401 if (!feature.hasTimestamp) {
|
Chris@0
|
402 std::cerr
|
Chris@0
|
403 << "WARNING: FeatureExtractionPluginTransform::addFeature: "
|
Chris@0
|
404 << "Feature has variable sample rate but no timestamp!"
|
Chris@0
|
405 << std::endl;
|
Chris@0
|
406 return;
|
Chris@0
|
407 } else {
|
Chris@66
|
408 frame = Vamp::RealTime::realTime2Frame(feature.timestamp, inputRate);
|
Chris@0
|
409 }
|
Chris@0
|
410
|
Chris@0
|
411 } else if (m_descriptor->sampleType ==
|
Chris@66
|
412 Vamp::Plugin::OutputDescriptor::FixedSampleRate) {
|
Chris@0
|
413
|
Chris@0
|
414 if (feature.hasTimestamp) {
|
Chris@0
|
415 //!!! warning: sampleRate may be non-integral
|
Chris@66
|
416 frame = Vamp::RealTime::realTime2Frame(feature.timestamp,
|
Chris@66
|
417 m_descriptor->sampleRate);
|
Chris@0
|
418 } else {
|
Chris@0
|
419 frame = m_output->getEndFrame() + 1;
|
Chris@0
|
420 }
|
Chris@0
|
421 }
|
Chris@0
|
422
|
Chris@70
|
423 if (binCount == 0) {
|
Chris@0
|
424
|
Chris@0
|
425 SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>();
|
Chris@0
|
426 if (!model) return;
|
Chris@0
|
427 model->addPoint(SparseOneDimensionalModel::Point(frame, feature.label.c_str()));
|
Chris@0
|
428
|
Chris@115
|
429 } else if (binCount == 1) {
|
Chris@0
|
430
|
Chris@0
|
431 float value = 0.0;
|
Chris@0
|
432 if (feature.values.size() > 0) value = feature.values[0];
|
Chris@0
|
433
|
Chris@0
|
434 SparseTimeValueModel *model = getOutput<SparseTimeValueModel>();
|
Chris@0
|
435 if (!model) return;
|
Chris@0
|
436 model->addPoint(SparseTimeValueModel::Point(frame, value, feature.label.c_str()));
|
Chris@115
|
437
|
Chris@115
|
438 } else if (m_descriptor->sampleType ==
|
Chris@115
|
439 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@115
|
440
|
Chris@115
|
441 float pitch = 0.0;
|
Chris@115
|
442 if (feature.values.size() > 0) pitch = feature.values[0];
|
Chris@115
|
443
|
Chris@115
|
444 float duration = 1;
|
Chris@115
|
445 if (feature.values.size() > 1) duration = feature.values[1];
|
Chris@115
|
446
|
Chris@115
|
447 float velocity = 100;
|
Chris@115
|
448 if (feature.values.size() > 2) velocity = feature.values[2];
|
Chris@115
|
449
|
Chris@115
|
450 NoteModel *model = getOutput<NoteModel>();
|
Chris@115
|
451 if (!model) return;
|
Chris@115
|
452
|
Chris@115
|
453 model->addPoint(NoteModel::Point(frame, pitch, duration, feature.label.c_str()));
|
Chris@0
|
454
|
Chris@0
|
455 } else {
|
Chris@0
|
456
|
Chris@0
|
457 DenseThreeDimensionalModel::BinValueSet values = feature.values;
|
Chris@0
|
458
|
Chris@0
|
459 DenseThreeDimensionalModel *model = getOutput<DenseThreeDimensionalModel>();
|
Chris@0
|
460 if (!model) return;
|
Chris@0
|
461
|
Chris@0
|
462 model->setBinValues(frame, values);
|
Chris@0
|
463 }
|
Chris@0
|
464 }
|
Chris@0
|
465
|
Chris@0
|
466 void
|
Chris@0
|
467 FeatureExtractionPluginTransform::setCompletion(int completion)
|
Chris@0
|
468 {
|
Chris@70
|
469 int binCount = 1;
|
Chris@70
|
470 if (m_descriptor->hasFixedBinCount) {
|
Chris@70
|
471 binCount = m_descriptor->binCount;
|
Chris@0
|
472 }
|
Chris@0
|
473
|
Chris@70
|
474 if (binCount == 0) {
|
Chris@0
|
475
|
Chris@0
|
476 SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>();
|
Chris@0
|
477 if (!model) return;
|
Chris@0
|
478 model->setCompletion(completion);
|
Chris@0
|
479
|
Chris@115
|
480 } else if (binCount == 1) {
|
Chris@115
|
481
|
Chris@115
|
482 SparseTimeValueModel *model = getOutput<SparseTimeValueModel>();
|
Chris@115
|
483 if (!model) return;
|
Chris@115
|
484 model->setCompletion(completion);
|
Chris@115
|
485
|
Chris@115
|
486 } else if (m_descriptor->sampleType ==
|
Chris@66
|
487 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@0
|
488
|
Chris@115
|
489 NoteModel *model = getOutput<NoteModel>();
|
Chris@0
|
490 if (!model) return;
|
Chris@0
|
491 model->setCompletion(completion);
|
Chris@0
|
492
|
Chris@0
|
493 } else {
|
Chris@0
|
494
|
Chris@19
|
495 DenseThreeDimensionalModel *model = getOutput<DenseThreeDimensionalModel>();
|
Chris@19
|
496 if (!model) return;
|
Chris@19
|
497 model->setCompletion(completion);
|
Chris@0
|
498 }
|
Chris@0
|
499 }
|
Chris@0
|
500
|