cannam@3
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@3
|
2
|
cannam@3
|
3 /*
|
cannam@3
|
4 Vamp
|
cannam@3
|
5
|
cannam@3
|
6 An API for audio analysis and feature extraction plugins.
|
cannam@3
|
7
|
cannam@3
|
8 Centre for Digital Music, Queen Mary, University of London.
|
cannam@3
|
9 Copyright 2006 Chris Cannam.
|
cannam@3
|
10
|
cannam@3
|
11 Permission is hereby granted, free of charge, to any person
|
cannam@3
|
12 obtaining a copy of this software and associated documentation
|
cannam@3
|
13 files (the "Software"), to deal in the Software without
|
cannam@3
|
14 restriction, including without limitation the rights to use, copy,
|
cannam@3
|
15 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@3
|
16 of the Software, and to permit persons to whom the Software is
|
cannam@3
|
17 furnished to do so, subject to the following conditions:
|
cannam@3
|
18
|
cannam@3
|
19 The above copyright notice and this permission notice shall be
|
cannam@3
|
20 included in all copies or substantial portions of the Software.
|
cannam@3
|
21
|
cannam@3
|
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@3
|
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@3
|
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@6
|
25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@3
|
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@3
|
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@3
|
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@3
|
29
|
cannam@3
|
30 Except as contained in this notice, the names of the Centre for
|
cannam@3
|
31 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@3
|
32 shall not be used in advertising or otherwise to promote the sale,
|
cannam@3
|
33 use or other dealings in this Software without prior written
|
cannam@3
|
34 authorization.
|
cannam@3
|
35 */
|
cannam@3
|
36
|
cannam@5
|
37 #ifndef _VAMP_PLUGIN_ADAPTER_H_
|
cannam@5
|
38 #define _VAMP_PLUGIN_ADAPTER_H_
|
cannam@3
|
39
|
cannam@3
|
40 #include "vamp.h"
|
cannam@3
|
41 #include "Plugin.h"
|
cannam@3
|
42
|
cannam@3
|
43 #include <map>
|
cannam@3
|
44
|
cannam@3
|
45 namespace Vamp {
|
cannam@3
|
46
|
cannam@3
|
47 class PluginAdapterBase
|
cannam@3
|
48 {
|
cannam@3
|
49 public:
|
cannam@3
|
50 virtual ~PluginAdapterBase();
|
cannam@3
|
51 const VampPluginDescriptor *getDescriptor();
|
cannam@3
|
52
|
cannam@3
|
53 protected:
|
cannam@3
|
54 PluginAdapterBase();
|
cannam@3
|
55
|
cannam@3
|
56 virtual Plugin *createPlugin(float inputSampleRate) = 0;
|
cannam@3
|
57
|
cannam@3
|
58 static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc,
|
cannam@3
|
59 float inputSampleRate);
|
cannam@3
|
60
|
cannam@3
|
61 static void vampCleanup(VampPluginHandle handle);
|
cannam@3
|
62
|
cannam@3
|
63 static int vampInitialise(VampPluginHandle handle, unsigned int channels,
|
cannam@3
|
64 unsigned int stepSize, unsigned int blockSize);
|
cannam@3
|
65
|
cannam@3
|
66 static void vampReset(VampPluginHandle handle);
|
cannam@3
|
67
|
cannam@3
|
68 static float vampGetParameter(VampPluginHandle handle, int param);
|
cannam@3
|
69 static void vampSetParameter(VampPluginHandle handle, int param, float value);
|
cannam@3
|
70
|
cannam@3
|
71 static unsigned int vampGetCurrentProgram(VampPluginHandle handle);
|
cannam@3
|
72 static void vampSelectProgram(VampPluginHandle handle, unsigned int program);
|
cannam@3
|
73
|
cannam@3
|
74 static unsigned int vampGetPreferredStepSize(VampPluginHandle handle);
|
cannam@3
|
75 static unsigned int vampGetPreferredBlockSize(VampPluginHandle handle);
|
cannam@3
|
76 static unsigned int vampGetMinChannelCount(VampPluginHandle handle);
|
cannam@3
|
77 static unsigned int vampGetMaxChannelCount(VampPluginHandle handle);
|
cannam@3
|
78
|
cannam@3
|
79 static unsigned int vampGetOutputCount(VampPluginHandle handle);
|
cannam@3
|
80
|
cannam@3
|
81 static VampOutputDescriptor *vampGetOutputDescriptor(VampPluginHandle handle,
|
cannam@3
|
82 unsigned int i);
|
cannam@3
|
83
|
cannam@3
|
84 static void vampReleaseOutputDescriptor(VampOutputDescriptor *desc);
|
cannam@3
|
85
|
cannam@3
|
86 static VampFeatureList **vampProcess(VampPluginHandle handle,
|
cannam@3
|
87 float **inputBuffers,
|
cannam@3
|
88 int sec,
|
cannam@3
|
89 int nsec);
|
cannam@3
|
90
|
cannam@3
|
91 static VampFeatureList **vampGetRemainingFeatures(VampPluginHandle handle);
|
cannam@3
|
92
|
cannam@3
|
93 static void vampReleaseFeatureSet(VampFeatureList **fs);
|
cannam@3
|
94
|
cannam@3
|
95 void cleanup(Plugin *plugin);
|
cannam@3
|
96 void checkOutputMap(Plugin *plugin);
|
cannam@3
|
97 unsigned int getOutputCount(Plugin *plugin);
|
cannam@3
|
98 VampOutputDescriptor *getOutputDescriptor(Plugin *plugin,
|
cannam@3
|
99 unsigned int i);
|
cannam@3
|
100 VampFeatureList **process(Plugin *plugin,
|
cannam@3
|
101 float **inputBuffers,
|
cannam@3
|
102 int sec, int nsec);
|
cannam@3
|
103 VampFeatureList **getRemainingFeatures(Plugin *plugin);
|
cannam@3
|
104 VampFeatureList **convertFeatures(const Plugin::FeatureSet &features);
|
cannam@3
|
105
|
cannam@3
|
106 typedef std::map<const void *, PluginAdapterBase *> AdapterMap;
|
cannam@3
|
107 static AdapterMap m_adapterMap;
|
cannam@3
|
108 static PluginAdapterBase *lookupAdapter(VampPluginHandle);
|
cannam@3
|
109
|
cannam@3
|
110 bool m_populated;
|
cannam@3
|
111 VampPluginDescriptor m_descriptor;
|
cannam@3
|
112 Plugin::ParameterList m_parameters;
|
cannam@3
|
113 Plugin::ProgramList m_programs;
|
cannam@3
|
114
|
cannam@3
|
115 typedef std::map<Plugin *, Plugin::OutputList *> OutputMap;
|
cannam@3
|
116 OutputMap m_pluginOutputs;
|
cannam@3
|
117
|
cannam@3
|
118 typedef std::map<Plugin *, VampFeature ***> FeatureBufferMap;
|
cannam@3
|
119 FeatureBufferMap m_pluginFeatures;
|
cannam@3
|
120 };
|
cannam@3
|
121
|
cannam@3
|
122 template <typename P>
|
cannam@3
|
123 class PluginAdapter : public PluginAdapterBase
|
cannam@3
|
124 {
|
cannam@3
|
125 public:
|
cannam@3
|
126 PluginAdapter() : PluginAdapterBase() { }
|
cannam@3
|
127 ~PluginAdapter() { }
|
cannam@3
|
128
|
cannam@3
|
129 protected:
|
cannam@3
|
130 Plugin *createPlugin(float inputSampleRate) {
|
cannam@3
|
131 P *p = new P(inputSampleRate);
|
cannam@3
|
132 Plugin *plugin = dynamic_cast<Plugin *>(p);
|
cannam@3
|
133 if (!plugin) {
|
cannam@3
|
134 std::cerr << "ERROR: PluginAdapter::createPlugin: "
|
cannam@3
|
135 << "Template type is not a plugin!"
|
cannam@3
|
136 << std::endl;
|
cannam@3
|
137 delete p;
|
cannam@3
|
138 return 0;
|
cannam@3
|
139 }
|
cannam@3
|
140 return plugin;
|
cannam@3
|
141 }
|
cannam@3
|
142 };
|
cannam@3
|
143
|
cannam@3
|
144 }
|
cannam@3
|
145
|
cannam@3
|
146 #endif
|
cannam@3
|
147
|