annotate plugin/transform/PluginTransformer.cpp @ 338:f14e2f7b24f7

* More space and time efficient AlignmentModel
author Chris Cannam
date Thu, 22 Nov 2007 11:09:26 +0000
parents 1afaf98dbf11
children 277006c62fea
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@328 16 #include "PluginTransformer.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@328 21 PluginTransformer::PluginTransformer(Model *inputModel,
Chris@320 22 const ExecutionContext &context) :
Chris@331 23 ModelTransformer(inputModel),
Chris@320 24 m_context(context)
Chris@320 25 {
Chris@320 26 }
Chris@320 27
Chris@328 28 PluginTransformer::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@333 36 sampleRate(0),
Chris@333 37 updates(true)
Chris@320 38 {
Chris@320 39 }
Chris@320 40
Chris@328 41 PluginTransformer::ExecutionContext::ExecutionContext(int _c, size_t _ss,
Chris@320 42 size_t _bs, WindowType _wt) :
Chris@320 43 channel(_c),
Chris@320 44 domain(Vamp::Plugin::FrequencyDomain),
Chris@320 45 stepSize(_ss ? _ss : (_bs ? _bs / 2 : 512)),
Chris@320 46 blockSize(_bs ? _bs : 1024),
Chris@320 47 windowType(_wt),
Chris@320 48 startFrame(0),
Chris@320 49 duration(0),
Chris@333 50 sampleRate(0),
Chris@333 51 updates(true)
Chris@320 52 {
Chris@320 53 }
Chris@320 54
Chris@328 55 PluginTransformer::ExecutionContext::ExecutionContext(int _c,
Chris@320 56 const Vamp::PluginBase *_plugin) :
Chris@320 57 channel(_c),
Chris@320 58 domain(Vamp::Plugin::TimeDomain),
Chris@320 59 stepSize(0),
Chris@320 60 blockSize(0),
Chris@320 61 windowType(HanningWindow),
Chris@320 62 startFrame(0),
Chris@320 63 duration(0),
Chris@320 64 sampleRate(0)
Chris@320 65 {
Chris@320 66 makeConsistentWithPlugin(_plugin);
Chris@320 67 }
Chris@320 68
Chris@320 69 bool
Chris@328 70 PluginTransformer::ExecutionContext::operator==(const ExecutionContext &c)
Chris@320 71 {
Chris@320 72 return (c.channel == channel &&
Chris@320 73 c.domain == domain &&
Chris@320 74 c.stepSize == stepSize &&
Chris@320 75 c.blockSize == blockSize &&
Chris@320 76 c.windowType == windowType &&
Chris@320 77 c.startFrame == startFrame &&
Chris@320 78 c.duration == duration &&
Chris@320 79 c.sampleRate == sampleRate);
Chris@320 80 }
Chris@320 81
Chris@320 82 void
Chris@328 83 PluginTransformer::ExecutionContext::makeConsistentWithPlugin(const Vamp::PluginBase *_plugin)
Chris@320 84 {
Chris@320 85 const Vamp::Plugin *vp = dynamic_cast<const Vamp::Plugin *>(_plugin);
Chris@320 86 if (!vp) {
Chris@320 87 // std::cerr << "makeConsistentWithPlugin: not a Vamp::Plugin" << std::endl;
Chris@320 88 vp = dynamic_cast<const Vamp::PluginHostAdapter *>(_plugin); //!!! why?
Chris@320 89 }
Chris@320 90 if (!vp) {
Chris@320 91 // std::cerr << "makeConsistentWithPlugin: not a Vamp::PluginHostAdapter" << std::endl;
Chris@320 92 vp = dynamic_cast<const Vamp::HostExt::PluginWrapper *>(_plugin); //!!! no, I mean really why?
Chris@320 93 }
Chris@320 94 if (!vp) {
Chris@320 95 // std::cerr << "makeConsistentWithPlugin: not a Vamp::HostExt::PluginWrapper" << std::endl;
Chris@320 96 }
Chris@320 97
Chris@320 98 if (!vp) {
Chris@320 99 domain = Vamp::Plugin::TimeDomain;
Chris@320 100 if (!stepSize) {
Chris@320 101 if (!blockSize) blockSize = 1024;
Chris@320 102 stepSize = blockSize;
Chris@320 103 } else {
Chris@320 104 if (!blockSize) blockSize = stepSize;
Chris@320 105 }
Chris@320 106 } else {
Chris@320 107 domain = vp->getInputDomain();
Chris@320 108 if (!stepSize) stepSize = vp->getPreferredStepSize();
Chris@320 109 if (!blockSize) blockSize = vp->getPreferredBlockSize();
Chris@320 110 if (!blockSize) blockSize = 1024;
Chris@320 111 if (!stepSize) {
Chris@320 112 if (domain == Vamp::Plugin::FrequencyDomain) {
Chris@320 113 // std::cerr << "frequency domain, step = " << blockSize/2 << std::endl;
Chris@320 114 stepSize = blockSize/2;
Chris@320 115 } else {
Chris@320 116 // std::cerr << "time domain, step = " << blockSize/2 << std::endl;
Chris@320 117 stepSize = blockSize;
Chris@320 118 }
Chris@320 119 }
Chris@320 120 }
Chris@320 121 }
Chris@320 122
Chris@320 123