annotate plugin/transform/PluginTransform.cpp @ 325:82a2d3161e14

* Document FileSource
author Chris Cannam
date Thu, 01 Nov 2007 12:34:17 +0000
parents 32e50b620a6c
children
rev   line source
Chris@320 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@320 2
Chris@320 3 /*
Chris@320 4 Sonic Visualiser
Chris@320 5 An audio file viewer and annotation editor.
Chris@320 6 Centre for Digital Music, Queen Mary, University of London.
Chris@320 7 This file copyright 2006 QMUL.
Chris@320 8
Chris@320 9 This program is free software; you can redistribute it and/or
Chris@320 10 modify it under the terms of the GNU General Public License as
Chris@320 11 published by the Free Software Foundation; either version 2 of the
Chris@320 12 License, or (at your option) any later version. See the file
Chris@320 13 COPYING included with this distribution for more information.
Chris@320 14 */
Chris@320 15
Chris@320 16 #include "PluginTransform.h"
Chris@320 17
Chris@320 18 #include "vamp-sdk/PluginHostAdapter.h"
Chris@320 19 #include "vamp-sdk/hostext/PluginWrapper.h"
Chris@320 20
Chris@320 21 PluginTransform::PluginTransform(Model *inputModel,
Chris@320 22 const ExecutionContext &context) :
Chris@320 23 Transform(inputModel),
Chris@320 24 m_context(context)
Chris@320 25 {
Chris@320 26 }
Chris@320 27
Chris@320 28 PluginTransform::ExecutionContext::ExecutionContext(int _c, size_t _bs) :
Chris@320 29 channel(_c),
Chris@320 30 domain(Vamp::Plugin::TimeDomain),
Chris@320 31 stepSize(_bs ? _bs : 1024),
Chris@320 32 blockSize(_bs ? _bs : 1024),
Chris@320 33 windowType(HanningWindow),
Chris@320 34 startFrame(0),
Chris@320 35 duration(0),
Chris@320 36 sampleRate(0)
Chris@320 37 {
Chris@320 38 }
Chris@320 39
Chris@320 40 PluginTransform::ExecutionContext::ExecutionContext(int _c, size_t _ss,
Chris@320 41 size_t _bs, WindowType _wt) :
Chris@320 42 channel(_c),
Chris@320 43 domain(Vamp::Plugin::FrequencyDomain),
Chris@320 44 stepSize(_ss ? _ss : (_bs ? _bs / 2 : 512)),
Chris@320 45 blockSize(_bs ? _bs : 1024),
Chris@320 46 windowType(_wt),
Chris@320 47 startFrame(0),
Chris@320 48 duration(0),
Chris@320 49 sampleRate(0)
Chris@320 50 {
Chris@320 51 }
Chris@320 52
Chris@320 53 PluginTransform::ExecutionContext::ExecutionContext(int _c,
Chris@320 54 const Vamp::PluginBase *_plugin) :
Chris@320 55 channel(_c),
Chris@320 56 domain(Vamp::Plugin::TimeDomain),
Chris@320 57 stepSize(0),
Chris@320 58 blockSize(0),
Chris@320 59 windowType(HanningWindow),
Chris@320 60 startFrame(0),
Chris@320 61 duration(0),
Chris@320 62 sampleRate(0)
Chris@320 63 {
Chris@320 64 makeConsistentWithPlugin(_plugin);
Chris@320 65 }
Chris@320 66
Chris@320 67 bool
Chris@320 68 PluginTransform::ExecutionContext::operator==(const ExecutionContext &c)
Chris@320 69 {
Chris@320 70 return (c.channel == channel &&
Chris@320 71 c.domain == domain &&
Chris@320 72 c.stepSize == stepSize &&
Chris@320 73 c.blockSize == blockSize &&
Chris@320 74 c.windowType == windowType &&
Chris@320 75 c.startFrame == startFrame &&
Chris@320 76 c.duration == duration &&
Chris@320 77 c.sampleRate == sampleRate);
Chris@320 78 }
Chris@320 79
Chris@320 80 void
Chris@320 81 PluginTransform::ExecutionContext::makeConsistentWithPlugin(const Vamp::PluginBase *_plugin)
Chris@320 82 {
Chris@320 83 const Vamp::Plugin *vp = dynamic_cast<const Vamp::Plugin *>(_plugin);
Chris@320 84 if (!vp) {
Chris@320 85 // std::cerr << "makeConsistentWithPlugin: not a Vamp::Plugin" << std::endl;
Chris@320 86 vp = dynamic_cast<const Vamp::PluginHostAdapter *>(_plugin); //!!! why?
Chris@320 87 }
Chris@320 88 if (!vp) {
Chris@320 89 // std::cerr << "makeConsistentWithPlugin: not a Vamp::PluginHostAdapter" << std::endl;
Chris@320 90 vp = dynamic_cast<const Vamp::HostExt::PluginWrapper *>(_plugin); //!!! no, I mean really why?
Chris@320 91 }
Chris@320 92 if (!vp) {
Chris@320 93 // std::cerr << "makeConsistentWithPlugin: not a Vamp::HostExt::PluginWrapper" << std::endl;
Chris@320 94 }
Chris@320 95
Chris@320 96 if (!vp) {
Chris@320 97 domain = Vamp::Plugin::TimeDomain;
Chris@320 98 if (!stepSize) {
Chris@320 99 if (!blockSize) blockSize = 1024;
Chris@320 100 stepSize = blockSize;
Chris@320 101 } else {
Chris@320 102 if (!blockSize) blockSize = stepSize;
Chris@320 103 }
Chris@320 104 } else {
Chris@320 105 domain = vp->getInputDomain();
Chris@320 106 if (!stepSize) stepSize = vp->getPreferredStepSize();
Chris@320 107 if (!blockSize) blockSize = vp->getPreferredBlockSize();
Chris@320 108 if (!blockSize) blockSize = 1024;
Chris@320 109 if (!stepSize) {
Chris@320 110 if (domain == Vamp::Plugin::FrequencyDomain) {
Chris@320 111 // std::cerr << "frequency domain, step = " << blockSize/2 << std::endl;
Chris@320 112 stepSize = blockSize/2;
Chris@320 113 } else {
Chris@320 114 // std::cerr << "time domain, step = " << blockSize/2 << std::endl;
Chris@320 115 stepSize = blockSize;
Chris@320 116 }
Chris@320 117 }
Chris@320 118 }
Chris@320 119 }
Chris@320 120
Chris@320 121