comparison plugin/transform/PluginTransform.cpp @ 320:32e50b620a6c

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