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@0
|
29
|
Chris@67
|
30 #include <fftw3.h>
|
Chris@67
|
31
|
Chris@0
|
32 #include <iostream>
|
Chris@0
|
33
|
Chris@0
|
34 FeatureExtractionPluginTransform::FeatureExtractionPluginTransform(Model *inputModel,
|
Chris@0
|
35 QString pluginId,
|
Chris@64
|
36 int channel,
|
Chris@56
|
37 QString configurationXml,
|
Chris@0
|
38 QString outputName) :
|
Chris@0
|
39 Transform(inputModel),
|
Chris@0
|
40 m_plugin(0),
|
Chris@64
|
41 m_channel(channel),
|
Chris@68
|
42 m_stepSize(0),
|
Chris@68
|
43 m_blockSize(0),
|
Chris@0
|
44 m_descriptor(0),
|
Chris@0
|
45 m_outputFeatureNo(0)
|
Chris@0
|
46 {
|
Chris@0
|
47 std::cerr << "FeatureExtractionPluginTransform::FeatureExtractionPluginTransform: plugin " << pluginId.toStdString() << ", outputName " << outputName.toStdString() << std::endl;
|
Chris@0
|
48
|
Chris@0
|
49 FeatureExtractionPluginFactory *factory =
|
Chris@0
|
50 FeatureExtractionPluginFactory::instanceFor(pluginId);
|
Chris@0
|
51
|
Chris@0
|
52 if (!factory) {
|
Chris@0
|
53 std::cerr << "FeatureExtractionPluginTransform: No factory available for plugin id \""
|
Chris@0
|
54 << pluginId.toStdString() << "\"" << std::endl;
|
Chris@0
|
55 return;
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 m_plugin = factory->instantiatePlugin(pluginId, m_input->getSampleRate());
|
Chris@0
|
59
|
Chris@0
|
60 if (!m_plugin) {
|
Chris@0
|
61 std::cerr << "FeatureExtractionPluginTransform: Failed to instantiate plugin \""
|
Chris@0
|
62 << pluginId.toStdString() << "\"" << std::endl;
|
Chris@0
|
63 return;
|
Chris@0
|
64 }
|
Chris@0
|
65
|
Chris@56
|
66 if (configurationXml != "") {
|
Chris@66
|
67 PluginXml(m_plugin).setParametersFromXml(configurationXml);
|
Chris@56
|
68 }
|
Chris@56
|
69
|
Chris@68
|
70 m_blockSize = m_plugin->getPreferredBlockSize();
|
Chris@68
|
71 m_stepSize = m_plugin->getPreferredStepSize();
|
Chris@68
|
72
|
Chris@68
|
73 if (m_blockSize == 0) m_blockSize = 1024; //!!! todo: ask user
|
Chris@68
|
74 if (m_stepSize == 0) m_stepSize = m_blockSize; //!!! likewise
|
Chris@68
|
75
|
Chris@66
|
76 Vamp::Plugin::OutputList outputs =
|
Chris@0
|
77 m_plugin->getOutputDescriptors();
|
Chris@0
|
78
|
Chris@0
|
79 if (outputs.empty()) {
|
Chris@0
|
80 std::cerr << "FeatureExtractionPluginTransform: Plugin \""
|
Chris@0
|
81 << pluginId.toStdString() << "\" has no outputs" << std::endl;
|
Chris@0
|
82 return;
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 for (size_t i = 0; i < outputs.size(); ++i) {
|
Chris@0
|
86 if (outputName == "" || outputs[i].name == outputName.toStdString()) {
|
Chris@0
|
87 m_outputFeatureNo = i;
|
Chris@66
|
88 m_descriptor = new Vamp::Plugin::OutputDescriptor
|
Chris@0
|
89 (outputs[i]);
|
Chris@0
|
90 break;
|
Chris@0
|
91 }
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 if (!m_descriptor) {
|
Chris@0
|
95 std::cerr << "FeatureExtractionPluginTransform: Plugin \""
|
Chris@0
|
96 << pluginId.toStdString() << "\" has no output named \""
|
Chris@0
|
97 << outputName.toStdString() << "\"" << std::endl;
|
Chris@0
|
98 return;
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 std::cerr << "FeatureExtractionPluginTransform: output sample type "
|
Chris@0
|
102 << m_descriptor->sampleType << std::endl;
|
Chris@0
|
103
|
Chris@70
|
104 int binCount = 1;
|
Chris@0
|
105 float minValue = 0.0, maxValue = 0.0;
|
Chris@0
|
106
|
Chris@70
|
107 if (m_descriptor->hasFixedBinCount) {
|
Chris@70
|
108 binCount = m_descriptor->binCount;
|
Chris@0
|
109 }
|
Chris@0
|
110
|
Chris@70
|
111 if (binCount > 0 && m_descriptor->hasKnownExtents) {
|
Chris@0
|
112 minValue = m_descriptor->minValue;
|
Chris@0
|
113 maxValue = m_descriptor->maxValue;
|
Chris@0
|
114 }
|
Chris@0
|
115
|
Chris@0
|
116 size_t modelRate = m_input->getSampleRate();
|
Chris@0
|
117 size_t modelResolution = 1;
|
Chris@0
|
118
|
Chris@0
|
119 switch (m_descriptor->sampleType) {
|
Chris@0
|
120
|
Chris@66
|
121 case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
|
Chris@0
|
122 if (m_descriptor->sampleRate != 0.0) {
|
Chris@0
|
123 modelResolution = size_t(modelRate / m_descriptor->sampleRate + 0.001);
|
Chris@0
|
124 }
|
Chris@0
|
125 break;
|
Chris@0
|
126
|
Chris@66
|
127 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep:
|
Chris@0
|
128 modelResolution = m_plugin->getPreferredStepSize();
|
Chris@0
|
129 break;
|
Chris@0
|
130
|
Chris@66
|
131 case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
|
Chris@0
|
132 modelRate = m_descriptor->sampleRate;
|
Chris@0
|
133 break;
|
Chris@0
|
134 }
|
Chris@0
|
135
|
Chris@70
|
136 if (binCount == 0) {
|
Chris@0
|
137
|
Chris@20
|
138 m_output = new SparseOneDimensionalModel(modelRate, modelResolution,
|
Chris@20
|
139 false);
|
Chris@0
|
140
|
Chris@70
|
141 } else if (binCount == 1 ||
|
Chris@0
|
142
|
Chris@0
|
143 // We don't have a sparse 3D model
|
Chris@0
|
144 m_descriptor->sampleType ==
|
Chris@66
|
145 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@0
|
146
|
Chris@63
|
147 SparseTimeValueModel *model = new SparseTimeValueModel
|
Chris@63
|
148 (modelRate, modelResolution, minValue, maxValue, false);
|
Chris@63
|
149 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str());
|
Chris@63
|
150
|
Chris@63
|
151 m_output = model;
|
Chris@0
|
152
|
Chris@0
|
153 } else {
|
Chris@0
|
154
|
Chris@0
|
155 m_output = new DenseThreeDimensionalModel(modelRate, modelResolution,
|
Chris@70
|
156 binCount, false);
|
Chris@20
|
157
|
Chris@70
|
158 if (!m_descriptor->binNames.empty()) {
|
Chris@20
|
159 std::vector<QString> names;
|
Chris@70
|
160 for (size_t i = 0; i < m_descriptor->binNames.size(); ++i) {
|
Chris@70
|
161 names.push_back(m_descriptor->binNames[i].c_str());
|
Chris@20
|
162 }
|
Chris@20
|
163 (dynamic_cast<DenseThreeDimensionalModel *>(m_output))
|
Chris@20
|
164 ->setBinNames(names);
|
Chris@20
|
165 }
|
Chris@0
|
166 }
|
Chris@0
|
167 }
|
Chris@0
|
168
|
Chris@0
|
169 FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform()
|
Chris@0
|
170 {
|
Chris@0
|
171 delete m_plugin;
|
Chris@0
|
172 delete m_descriptor;
|
Chris@0
|
173 }
|
Chris@0
|
174
|
Chris@0
|
175 DenseTimeValueModel *
|
Chris@0
|
176 FeatureExtractionPluginTransform::getInput()
|
Chris@0
|
177 {
|
Chris@0
|
178 DenseTimeValueModel *dtvm =
|
Chris@0
|
179 dynamic_cast<DenseTimeValueModel *>(getInputModel());
|
Chris@0
|
180 if (!dtvm) {
|
Chris@0
|
181 std::cerr << "FeatureExtractionPluginTransform::getInput: WARNING: Input model is not conformable to DenseTimeValueModel" << std::endl;
|
Chris@0
|
182 }
|
Chris@0
|
183 return dtvm;
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@0
|
186 void
|
Chris@0
|
187 FeatureExtractionPluginTransform::run()
|
Chris@0
|
188 {
|
Chris@0
|
189 DenseTimeValueModel *input = getInput();
|
Chris@0
|
190 if (!input) return;
|
Chris@0
|
191
|
Chris@0
|
192 if (!m_output) return;
|
Chris@0
|
193
|
Chris@0
|
194 size_t channelCount = input->getChannelCount();
|
Chris@0
|
195 if (m_plugin->getMaxChannelCount() < channelCount) {
|
Chris@0
|
196 channelCount = 1;
|
Chris@0
|
197 }
|
Chris@0
|
198 if (m_plugin->getMinChannelCount() > channelCount) {
|
Chris@0
|
199 std::cerr << "FeatureExtractionPluginTransform::run: "
|
Chris@0
|
200 << "Can't provide enough channels to plugin (plugin min "
|
Chris@0
|
201 << m_plugin->getMinChannelCount() << ", max "
|
Chris@0
|
202 << m_plugin->getMaxChannelCount() << ", input model has "
|
Chris@0
|
203 << input->getChannelCount() << ")" << std::endl;
|
Chris@0
|
204 return;
|
Chris@0
|
205 }
|
Chris@0
|
206
|
Chris@0
|
207 size_t sampleRate = m_input->getSampleRate();
|
Chris@0
|
208
|
Chris@69
|
209 if (!m_plugin->initialise(channelCount, m_stepSize, m_blockSize)) {
|
Chris@69
|
210 std::cerr << "FeatureExtractionPluginTransform::run: Plugin "
|
Chris@69
|
211 << m_plugin->getName() << " failed to initialise!" << std::endl;
|
Chris@69
|
212 return;
|
Chris@69
|
213 }
|
Chris@0
|
214
|
Chris@0
|
215 float **buffers = new float*[channelCount];
|
Chris@0
|
216 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@68
|
217 buffers[ch] = new float[m_blockSize];
|
Chris@0
|
218 }
|
Chris@0
|
219
|
Chris@67
|
220 double *fftInput = 0;
|
Chris@67
|
221 fftw_complex *fftOutput = 0;
|
Chris@67
|
222 fftw_plan fftPlan = 0;
|
Chris@68
|
223 Window<double> windower(HanningWindow, m_blockSize);
|
Chris@67
|
224
|
Chris@67
|
225 if (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
|
Chris@67
|
226
|
Chris@68
|
227 fftInput = (double *)fftw_malloc(m_blockSize * sizeof(double));
|
Chris@68
|
228 fftOutput = (fftw_complex *)fftw_malloc(m_blockSize * sizeof(fftw_complex));
|
Chris@68
|
229 fftPlan = fftw_plan_dft_r2c_1d(m_blockSize, fftInput, fftOutput,
|
Chris@67
|
230 FFTW_ESTIMATE);
|
Chris@67
|
231 if (!fftPlan) {
|
Chris@67
|
232 std::cerr << "ERROR: FeatureExtractionPluginTransform::run(): fftw_plan failed! Results will be garbage" << std::endl;
|
Chris@67
|
233 }
|
Chris@67
|
234 }
|
Chris@67
|
235
|
Chris@70
|
236 long startFrame = m_input->getStartFrame();
|
Chris@70
|
237 long endFrame = m_input->getEndFrame();
|
Chris@70
|
238 long blockFrame = startFrame;
|
Chris@0
|
239
|
Chris@70
|
240 long prevCompletion = 0;
|
Chris@0
|
241
|
Chris@70
|
242 while (1) {
|
Chris@70
|
243
|
Chris@70
|
244 if (fftPlan) {
|
Chris@70
|
245 if (blockFrame - m_blockSize/2 > endFrame) break;
|
Chris@70
|
246 } else {
|
Chris@70
|
247 if (blockFrame >= endFrame) break;
|
Chris@70
|
248 }
|
Chris@0
|
249
|
Chris@0
|
250 // std::cerr << "FeatureExtractionPluginTransform::run: blockFrame "
|
Chris@0
|
251 // << blockFrame << std::endl;
|
Chris@0
|
252
|
Chris@70
|
253 long completion =
|
Chris@68
|
254 (((blockFrame - startFrame) / m_stepSize) * 99) /
|
Chris@68
|
255 ( (endFrame - startFrame) / m_stepSize);
|
Chris@0
|
256
|
Chris@0
|
257 // channelCount is either m_input->channelCount or 1
|
Chris@0
|
258
|
Chris@70
|
259 for (int ch = 0; ch < channelCount; ++ch) {
|
Chris@70
|
260 if (fftPlan) {
|
Chris@70
|
261 getFrames(ch, channelCount,
|
Chris@70
|
262 blockFrame - m_blockSize/2, m_blockSize, buffers[ch]);
|
Chris@70
|
263 } else {
|
Chris@70
|
264 getFrames(ch, channelCount,
|
Chris@70
|
265 blockFrame, m_blockSize, buffers[ch]);
|
Chris@70
|
266 }
|
Chris@70
|
267 }
|
Chris@70
|
268
|
Chris@67
|
269 if (fftPlan) {
|
Chris@70
|
270 for (int ch = 0; ch < channelCount; ++ch) {
|
Chris@70
|
271 for (int i = 0; i < m_blockSize; ++i) {
|
Chris@67
|
272 fftInput[i] = buffers[ch][i];
|
Chris@67
|
273 }
|
Chris@67
|
274 windower.cut(fftInput);
|
Chris@70
|
275 for (int i = 0; i < m_blockSize/2; ++i) {
|
Chris@67
|
276 double temp = fftInput[i];
|
Chris@68
|
277 fftInput[i] = fftInput[i + m_blockSize/2];
|
Chris@68
|
278 fftInput[i + m_blockSize/2] = temp;
|
Chris@67
|
279 }
|
Chris@67
|
280 fftw_execute(fftPlan);
|
Chris@70
|
281 for (int i = 0; i < m_blockSize/2; ++i) {
|
Chris@67
|
282 buffers[ch][i*2] = fftOutput[i][0];
|
Chris@67
|
283 buffers[ch][i*2 + 1] = fftOutput[i][1];
|
Chris@67
|
284 }
|
Chris@67
|
285 }
|
Chris@67
|
286 }
|
Chris@67
|
287
|
Chris@66
|
288 Vamp::Plugin::FeatureSet features = m_plugin->process
|
Chris@66
|
289 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate));
|
Chris@0
|
290
|
Chris@0
|
291 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) {
|
Chris@66
|
292 Vamp::Plugin::Feature feature =
|
Chris@0
|
293 features[m_outputFeatureNo][fi];
|
Chris@0
|
294 addFeature(blockFrame, feature);
|
Chris@0
|
295 }
|
Chris@0
|
296
|
Chris@0
|
297 if (blockFrame == startFrame || completion > prevCompletion) {
|
Chris@0
|
298 setCompletion(completion);
|
Chris@0
|
299 prevCompletion = completion;
|
Chris@0
|
300 }
|
Chris@0
|
301
|
Chris@68
|
302 blockFrame += m_stepSize;
|
Chris@0
|
303 }
|
Chris@0
|
304
|
Chris@67
|
305 if (fftPlan) {
|
Chris@67
|
306 fftw_destroy_plan(fftPlan);
|
Chris@67
|
307 fftw_free(fftInput);
|
Chris@67
|
308 fftw_free(fftOutput);
|
Chris@67
|
309 }
|
Chris@67
|
310
|
Chris@66
|
311 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures();
|
Chris@0
|
312
|
Chris@0
|
313 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) {
|
Chris@66
|
314 Vamp::Plugin::Feature feature =
|
Chris@0
|
315 features[m_outputFeatureNo][fi];
|
Chris@0
|
316 addFeature(blockFrame, feature);
|
Chris@0
|
317 }
|
Chris@0
|
318
|
Chris@0
|
319 setCompletion(100);
|
Chris@0
|
320 }
|
Chris@0
|
321
|
Chris@70
|
322 void
|
Chris@70
|
323 FeatureExtractionPluginTransform::getFrames(int channel, int channelCount,
|
Chris@70
|
324 long startFrame, long size,
|
Chris@70
|
325 float *buffer)
|
Chris@70
|
326 {
|
Chris@70
|
327 long offset = 0;
|
Chris@70
|
328
|
Chris@70
|
329 if (startFrame < 0) {
|
Chris@70
|
330 for (int i = 0; i < size && startFrame + i < 0; ++i) {
|
Chris@70
|
331 buffer[i] = 0.0f;
|
Chris@70
|
332 }
|
Chris@70
|
333 offset = -startFrame;
|
Chris@70
|
334 size -= offset;
|
Chris@70
|
335 if (size <= 0) return;
|
Chris@70
|
336 startFrame = 0;
|
Chris@70
|
337 }
|
Chris@70
|
338
|
Chris@70
|
339 size_t got = getInput()->getValues
|
Chris@70
|
340 ((channelCount == 1 ? m_channel : channel),
|
Chris@70
|
341 startFrame, startFrame + size, buffer + offset);
|
Chris@70
|
342
|
Chris@70
|
343 while (got < size) {
|
Chris@70
|
344 buffer[offset + got] = 0.0;
|
Chris@70
|
345 ++got;
|
Chris@70
|
346 }
|
Chris@70
|
347 }
|
Chris@0
|
348
|
Chris@0
|
349 void
|
Chris@0
|
350 FeatureExtractionPluginTransform::addFeature(size_t blockFrame,
|
Chris@66
|
351 const Vamp::Plugin::Feature &feature)
|
Chris@0
|
352 {
|
Chris@0
|
353 size_t inputRate = m_input->getSampleRate();
|
Chris@0
|
354
|
Chris@0
|
355 // std::cerr << "FeatureExtractionPluginTransform::addFeature("
|
Chris@0
|
356 // << blockFrame << ")" << std::endl;
|
Chris@0
|
357
|
Chris@70
|
358 int binCount = 1;
|
Chris@70
|
359 if (m_descriptor->hasFixedBinCount) {
|
Chris@70
|
360 binCount = m_descriptor->binCount;
|
Chris@0
|
361 }
|
Chris@0
|
362
|
Chris@0
|
363 size_t frame = blockFrame;
|
Chris@0
|
364
|
Chris@0
|
365 if (m_descriptor->sampleType ==
|
Chris@66
|
366 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@0
|
367
|
Chris@0
|
368 if (!feature.hasTimestamp) {
|
Chris@0
|
369 std::cerr
|
Chris@0
|
370 << "WARNING: FeatureExtractionPluginTransform::addFeature: "
|
Chris@0
|
371 << "Feature has variable sample rate but no timestamp!"
|
Chris@0
|
372 << std::endl;
|
Chris@0
|
373 return;
|
Chris@0
|
374 } else {
|
Chris@66
|
375 frame = Vamp::RealTime::realTime2Frame(feature.timestamp, inputRate);
|
Chris@0
|
376 }
|
Chris@0
|
377
|
Chris@0
|
378 } else if (m_descriptor->sampleType ==
|
Chris@66
|
379 Vamp::Plugin::OutputDescriptor::FixedSampleRate) {
|
Chris@0
|
380
|
Chris@0
|
381 if (feature.hasTimestamp) {
|
Chris@0
|
382 //!!! warning: sampleRate may be non-integral
|
Chris@66
|
383 frame = Vamp::RealTime::realTime2Frame(feature.timestamp,
|
Chris@66
|
384 m_descriptor->sampleRate);
|
Chris@0
|
385 } else {
|
Chris@0
|
386 frame = m_output->getEndFrame() + 1;
|
Chris@0
|
387 }
|
Chris@0
|
388 }
|
Chris@0
|
389
|
Chris@70
|
390 if (binCount == 0) {
|
Chris@0
|
391
|
Chris@0
|
392 SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>();
|
Chris@0
|
393 if (!model) return;
|
Chris@0
|
394 model->addPoint(SparseOneDimensionalModel::Point(frame, feature.label.c_str()));
|
Chris@0
|
395
|
Chris@70
|
396 } else if (binCount == 1 ||
|
Chris@0
|
397 m_descriptor->sampleType ==
|
Chris@66
|
398 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@0
|
399
|
Chris@0
|
400 float value = 0.0;
|
Chris@0
|
401 if (feature.values.size() > 0) value = feature.values[0];
|
Chris@0
|
402
|
Chris@0
|
403 SparseTimeValueModel *model = getOutput<SparseTimeValueModel>();
|
Chris@0
|
404 if (!model) return;
|
Chris@0
|
405 model->addPoint(SparseTimeValueModel::Point(frame, value, feature.label.c_str()));
|
Chris@0
|
406
|
Chris@0
|
407 } else {
|
Chris@0
|
408
|
Chris@0
|
409 DenseThreeDimensionalModel::BinValueSet values = feature.values;
|
Chris@0
|
410
|
Chris@0
|
411 DenseThreeDimensionalModel *model = getOutput<DenseThreeDimensionalModel>();
|
Chris@0
|
412 if (!model) return;
|
Chris@0
|
413
|
Chris@0
|
414 model->setBinValues(frame, values);
|
Chris@0
|
415 }
|
Chris@0
|
416 }
|
Chris@0
|
417
|
Chris@0
|
418 void
|
Chris@0
|
419 FeatureExtractionPluginTransform::setCompletion(int completion)
|
Chris@0
|
420 {
|
Chris@70
|
421 int binCount = 1;
|
Chris@70
|
422 if (m_descriptor->hasFixedBinCount) {
|
Chris@70
|
423 binCount = m_descriptor->binCount;
|
Chris@0
|
424 }
|
Chris@0
|
425
|
Chris@70
|
426 if (binCount == 0) {
|
Chris@0
|
427
|
Chris@0
|
428 SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>();
|
Chris@0
|
429 if (!model) return;
|
Chris@0
|
430 model->setCompletion(completion);
|
Chris@0
|
431
|
Chris@70
|
432 } else if (binCount == 1 ||
|
Chris@0
|
433 m_descriptor->sampleType ==
|
Chris@66
|
434 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@0
|
435
|
Chris@0
|
436 SparseTimeValueModel *model = getOutput<SparseTimeValueModel>();
|
Chris@0
|
437 if (!model) return;
|
Chris@0
|
438 model->setCompletion(completion);
|
Chris@0
|
439
|
Chris@0
|
440 } else {
|
Chris@0
|
441
|
Chris@19
|
442 DenseThreeDimensionalModel *model = getOutput<DenseThreeDimensionalModel>();
|
Chris@19
|
443 if (!model) return;
|
Chris@19
|
444 model->setCompletion(completion);
|
Chris@0
|
445 }
|
Chris@0
|
446 }
|
Chris@0
|
447
|