annotate transform/FeatureExtractionPluginTransform.cpp @ 129:4e38a29c13fc

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