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