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@3
|
37 #include "PluginAdapter.h"
|
cannam@3
|
38
|
cannam@3
|
39 namespace Vamp {
|
cannam@3
|
40
|
cannam@3
|
41 PluginAdapterBase::PluginAdapterBase() :
|
cannam@3
|
42 m_populated(false)
|
cannam@3
|
43 {
|
cannam@3
|
44 }
|
cannam@3
|
45
|
cannam@3
|
46 const VampPluginDescriptor *
|
cannam@3
|
47 PluginAdapterBase::getDescriptor()
|
cannam@3
|
48 {
|
cannam@3
|
49 if (m_populated) return &m_descriptor;
|
cannam@3
|
50
|
cannam@3
|
51 Plugin *plugin = createPlugin(48000);
|
cannam@3
|
52
|
cannam@3
|
53 m_parameters = plugin->getParameterDescriptors();
|
cannam@3
|
54 m_programs = plugin->getPrograms();
|
cannam@3
|
55
|
cannam@3
|
56 m_descriptor.name = strdup(plugin->getName().c_str());
|
cannam@3
|
57 m_descriptor.description = strdup(plugin->getDescription().c_str());
|
cannam@3
|
58 m_descriptor.maker = strdup(plugin->getMaker().c_str());
|
cannam@3
|
59 m_descriptor.pluginVersion = plugin->getPluginVersion();
|
cannam@3
|
60 m_descriptor.copyright = strdup(plugin->getCopyright().c_str());
|
cannam@3
|
61
|
cannam@3
|
62 m_descriptor.parameterCount = m_parameters.size();
|
cannam@3
|
63 m_descriptor.parameters = (const VampParameterDescriptor **)
|
cannam@3
|
64 malloc(m_parameters.size() * sizeof(VampParameterDescriptor));
|
cannam@7
|
65
|
cannam@7
|
66 unsigned int i;
|
cannam@3
|
67
|
cannam@7
|
68 for (i = 0; i < m_parameters.size(); ++i) {
|
cannam@3
|
69 VampParameterDescriptor *desc = (VampParameterDescriptor *)
|
cannam@3
|
70 malloc(sizeof(VampParameterDescriptor));
|
cannam@3
|
71 desc->name = strdup(m_parameters[i].name.c_str());
|
cannam@3
|
72 desc->description = strdup(m_parameters[i].description.c_str());
|
cannam@3
|
73 desc->unit = strdup(m_parameters[i].unit.c_str());
|
cannam@3
|
74 desc->minValue = m_parameters[i].minValue;
|
cannam@3
|
75 desc->maxValue = m_parameters[i].maxValue;
|
cannam@3
|
76 desc->defaultValue = m_parameters[i].defaultValue;
|
cannam@3
|
77 desc->isQuantized = m_parameters[i].isQuantized;
|
cannam@3
|
78 desc->quantizeStep = m_parameters[i].quantizeStep;
|
cannam@3
|
79 m_descriptor.parameters[i] = desc;
|
cannam@3
|
80 }
|
cannam@3
|
81
|
cannam@3
|
82 m_descriptor.programCount = m_programs.size();
|
cannam@3
|
83 m_descriptor.programs = (const char **)
|
cannam@3
|
84 malloc(m_programs.size() * sizeof(const char *));
|
cannam@3
|
85
|
cannam@7
|
86 for (i = 0; i < m_programs.size(); ++i) {
|
cannam@3
|
87 m_descriptor.programs[i] = strdup(m_programs[i].c_str());
|
cannam@3
|
88 }
|
cannam@3
|
89
|
cannam@3
|
90 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
|
cannam@3
|
91 m_descriptor.inputDomain = vampFrequencyDomain;
|
cannam@3
|
92 } else {
|
cannam@3
|
93 m_descriptor.inputDomain = vampTimeDomain;
|
cannam@3
|
94 }
|
cannam@3
|
95
|
cannam@3
|
96 m_descriptor.instantiate = vampInstantiate;
|
cannam@3
|
97 m_descriptor.cleanup = vampCleanup;
|
cannam@3
|
98 m_descriptor.initialise = vampInitialise;
|
cannam@3
|
99 m_descriptor.reset = vampReset;
|
cannam@3
|
100 m_descriptor.getParameter = vampGetParameter;
|
cannam@3
|
101 m_descriptor.setParameter = vampSetParameter;
|
cannam@3
|
102 m_descriptor.getCurrentProgram = vampGetCurrentProgram;
|
cannam@3
|
103 m_descriptor.selectProgram = vampSelectProgram;
|
cannam@3
|
104 m_descriptor.getPreferredStepSize = vampGetPreferredStepSize;
|
cannam@3
|
105 m_descriptor.getPreferredBlockSize = vampGetPreferredBlockSize;
|
cannam@3
|
106 m_descriptor.getMinChannelCount = vampGetMinChannelCount;
|
cannam@3
|
107 m_descriptor.getMaxChannelCount = vampGetMaxChannelCount;
|
cannam@3
|
108 m_descriptor.getOutputCount = vampGetOutputCount;
|
cannam@3
|
109 m_descriptor.getOutputDescriptor = vampGetOutputDescriptor;
|
cannam@3
|
110 m_descriptor.releaseOutputDescriptor = vampReleaseOutputDescriptor;
|
cannam@3
|
111 m_descriptor.process = vampProcess;
|
cannam@3
|
112 m_descriptor.getRemainingFeatures = vampGetRemainingFeatures;
|
cannam@3
|
113 m_descriptor.releaseFeatureSet = vampReleaseFeatureSet;
|
cannam@3
|
114
|
cannam@3
|
115 m_adapterMap[&m_descriptor] = this;
|
cannam@3
|
116
|
cannam@3
|
117 delete plugin;
|
cannam@3
|
118
|
cannam@3
|
119 m_populated = true;
|
cannam@3
|
120 return &m_descriptor;
|
cannam@3
|
121 }
|
cannam@3
|
122
|
cannam@3
|
123 PluginAdapterBase::~PluginAdapterBase()
|
cannam@3
|
124 {
|
cannam@3
|
125 if (!m_populated) return;
|
cannam@3
|
126
|
cannam@3
|
127 free((void *)m_descriptor.name);
|
cannam@3
|
128 free((void *)m_descriptor.description);
|
cannam@3
|
129 free((void *)m_descriptor.maker);
|
cannam@3
|
130 free((void *)m_descriptor.copyright);
|
cannam@3
|
131
|
cannam@3
|
132 for (unsigned int i = 0; i < m_descriptor.parameterCount; ++i) {
|
cannam@3
|
133 const VampParameterDescriptor *desc = m_descriptor.parameters[i];
|
cannam@3
|
134 free((void *)desc->name);
|
cannam@3
|
135 free((void *)desc->description);
|
cannam@3
|
136 free((void *)desc->unit);
|
cannam@3
|
137 }
|
cannam@3
|
138 free((void *)m_descriptor.parameters);
|
cannam@3
|
139
|
cannam@3
|
140 for (unsigned int i = 0; i < m_descriptor.programCount; ++i) {
|
cannam@3
|
141 free((void *)m_descriptor.programs[i]);
|
cannam@3
|
142 }
|
cannam@3
|
143 free((void *)m_descriptor.programs);
|
cannam@3
|
144
|
cannam@3
|
145 m_adapterMap.erase(&m_descriptor);
|
cannam@3
|
146 }
|
cannam@3
|
147
|
cannam@3
|
148 PluginAdapterBase *
|
cannam@3
|
149 PluginAdapterBase::lookupAdapter(VampPluginHandle handle)
|
cannam@3
|
150 {
|
cannam@3
|
151 AdapterMap::const_iterator i = m_adapterMap.find(handle);
|
cannam@3
|
152 if (i == m_adapterMap.end()) return 0;
|
cannam@3
|
153 return i->second;
|
cannam@3
|
154 }
|
cannam@3
|
155
|
cannam@3
|
156 VampPluginHandle
|
cannam@3
|
157 PluginAdapterBase::vampInstantiate(const VampPluginDescriptor *desc,
|
cannam@3
|
158 float inputSampleRate)
|
cannam@3
|
159 {
|
cannam@3
|
160 if (m_adapterMap.find(desc) == m_adapterMap.end()) return 0;
|
cannam@3
|
161 PluginAdapterBase *adapter = m_adapterMap[desc];
|
cannam@3
|
162 if (desc != &adapter->m_descriptor) return 0;
|
cannam@3
|
163
|
cannam@3
|
164 Plugin *plugin = adapter->createPlugin(inputSampleRate);
|
cannam@3
|
165 if (plugin) {
|
cannam@3
|
166 m_adapterMap[plugin] = adapter;
|
cannam@3
|
167 }
|
cannam@3
|
168
|
cannam@3
|
169 return plugin;
|
cannam@3
|
170 }
|
cannam@3
|
171
|
cannam@3
|
172 void
|
cannam@3
|
173 PluginAdapterBase::vampCleanup(VampPluginHandle handle)
|
cannam@3
|
174 {
|
cannam@3
|
175 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
176 if (!adapter) {
|
cannam@3
|
177 delete ((Plugin *)handle);
|
cannam@3
|
178 return;
|
cannam@3
|
179 }
|
cannam@3
|
180 adapter->cleanup(((Plugin *)handle));
|
cannam@3
|
181 }
|
cannam@3
|
182
|
cannam@3
|
183 int
|
cannam@3
|
184 PluginAdapterBase::vampInitialise(VampPluginHandle handle,
|
cannam@3
|
185 unsigned int channels,
|
cannam@3
|
186 unsigned int stepSize,
|
cannam@3
|
187 unsigned int blockSize)
|
cannam@3
|
188 {
|
cannam@3
|
189 bool result = ((Plugin *)handle)->initialise
|
cannam@3
|
190 (channels, stepSize, blockSize);
|
cannam@3
|
191 return result ? 1 : 0;
|
cannam@3
|
192 }
|
cannam@3
|
193
|
cannam@3
|
194 void
|
cannam@3
|
195 PluginAdapterBase::vampReset(VampPluginHandle handle)
|
cannam@3
|
196 {
|
cannam@3
|
197 ((Plugin *)handle)->reset();
|
cannam@3
|
198 }
|
cannam@3
|
199
|
cannam@3
|
200 float
|
cannam@3
|
201 PluginAdapterBase::vampGetParameter(VampPluginHandle handle,
|
cannam@3
|
202 int param)
|
cannam@3
|
203 {
|
cannam@3
|
204 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
205 if (!adapter) return 0.0;
|
cannam@3
|
206 Plugin::ParameterList &list = adapter->m_parameters;
|
cannam@3
|
207 return ((Plugin *)handle)->getParameter(list[param].name);
|
cannam@3
|
208 }
|
cannam@3
|
209
|
cannam@3
|
210 void
|
cannam@3
|
211 PluginAdapterBase::vampSetParameter(VampPluginHandle handle,
|
cannam@3
|
212 int param, float value)
|
cannam@3
|
213 {
|
cannam@3
|
214 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
215 if (!adapter) return;
|
cannam@3
|
216 Plugin::ParameterList &list = adapter->m_parameters;
|
cannam@3
|
217 ((Plugin *)handle)->setParameter(list[param].name, value);
|
cannam@3
|
218 }
|
cannam@3
|
219
|
cannam@3
|
220 unsigned int
|
cannam@3
|
221 PluginAdapterBase::vampGetCurrentProgram(VampPluginHandle handle)
|
cannam@3
|
222 {
|
cannam@3
|
223 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
224 if (!adapter) return 0;
|
cannam@3
|
225 Plugin::ProgramList &list = adapter->m_programs;
|
cannam@3
|
226 std::string program = ((Plugin *)handle)->getCurrentProgram();
|
cannam@3
|
227 for (unsigned int i = 0; i < list.size(); ++i) {
|
cannam@3
|
228 if (list[i] == program) return i;
|
cannam@3
|
229 }
|
cannam@3
|
230 return 0;
|
cannam@3
|
231 }
|
cannam@3
|
232
|
cannam@3
|
233 void
|
cannam@3
|
234 PluginAdapterBase::vampSelectProgram(VampPluginHandle handle,
|
cannam@3
|
235 unsigned int program)
|
cannam@3
|
236 {
|
cannam@3
|
237 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
238 if (!adapter) return;
|
cannam@3
|
239 Plugin::ProgramList &list = adapter->m_programs;
|
cannam@3
|
240 ((Plugin *)handle)->selectProgram(list[program]);
|
cannam@3
|
241 }
|
cannam@3
|
242
|
cannam@3
|
243 unsigned int
|
cannam@3
|
244 PluginAdapterBase::vampGetPreferredStepSize(VampPluginHandle handle)
|
cannam@3
|
245 {
|
cannam@3
|
246 return ((Plugin *)handle)->getPreferredStepSize();
|
cannam@3
|
247 }
|
cannam@3
|
248
|
cannam@3
|
249 unsigned int
|
cannam@3
|
250 PluginAdapterBase::vampGetPreferredBlockSize(VampPluginHandle handle)
|
cannam@3
|
251 {
|
cannam@3
|
252 return ((Plugin *)handle)->getPreferredBlockSize();
|
cannam@3
|
253 }
|
cannam@3
|
254
|
cannam@3
|
255 unsigned int
|
cannam@3
|
256 PluginAdapterBase::vampGetMinChannelCount(VampPluginHandle handle)
|
cannam@3
|
257 {
|
cannam@3
|
258 return ((Plugin *)handle)->getMinChannelCount();
|
cannam@3
|
259 }
|
cannam@3
|
260
|
cannam@3
|
261 unsigned int
|
cannam@3
|
262 PluginAdapterBase::vampGetMaxChannelCount(VampPluginHandle handle)
|
cannam@3
|
263 {
|
cannam@3
|
264 return ((Plugin *)handle)->getMaxChannelCount();
|
cannam@3
|
265 }
|
cannam@3
|
266
|
cannam@3
|
267 unsigned int
|
cannam@3
|
268 PluginAdapterBase::vampGetOutputCount(VampPluginHandle handle)
|
cannam@3
|
269 {
|
cannam@3
|
270 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
271 if (!adapter) return 0;
|
cannam@3
|
272 return adapter->getOutputCount((Plugin *)handle);
|
cannam@3
|
273 }
|
cannam@3
|
274
|
cannam@3
|
275 VampOutputDescriptor *
|
cannam@3
|
276 PluginAdapterBase::vampGetOutputDescriptor(VampPluginHandle handle,
|
cannam@3
|
277 unsigned int i)
|
cannam@3
|
278 {
|
cannam@3
|
279 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
280 if (!adapter) return 0;
|
cannam@3
|
281 return adapter->getOutputDescriptor((Plugin *)handle, i);
|
cannam@3
|
282 }
|
cannam@3
|
283
|
cannam@3
|
284 void
|
cannam@3
|
285 PluginAdapterBase::vampReleaseOutputDescriptor(VampOutputDescriptor *desc)
|
cannam@3
|
286 {
|
cannam@3
|
287 if (desc->name) free((void *)desc->name);
|
cannam@3
|
288 if (desc->description) free((void *)desc->description);
|
cannam@3
|
289 if (desc->unit) free((void *)desc->unit);
|
cannam@3
|
290 for (unsigned int i = 0; i < desc->valueCount; ++i) {
|
cannam@3
|
291 free((void *)desc->valueNames[i]);
|
cannam@3
|
292 }
|
cannam@3
|
293 if (desc->valueNames) free((void *)desc->valueNames);
|
cannam@3
|
294 free((void *)desc);
|
cannam@3
|
295 }
|
cannam@3
|
296
|
cannam@3
|
297 VampFeatureList **
|
cannam@3
|
298 PluginAdapterBase::vampProcess(VampPluginHandle handle,
|
cannam@3
|
299 float **inputBuffers,
|
cannam@3
|
300 int sec,
|
cannam@3
|
301 int nsec)
|
cannam@3
|
302 {
|
cannam@3
|
303 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
304 if (!adapter) return 0;
|
cannam@3
|
305 return adapter->process((Plugin *)handle,
|
cannam@3
|
306 inputBuffers, sec, nsec);
|
cannam@3
|
307 }
|
cannam@3
|
308
|
cannam@3
|
309 VampFeatureList **
|
cannam@3
|
310 PluginAdapterBase::vampGetRemainingFeatures(VampPluginHandle handle)
|
cannam@3
|
311 {
|
cannam@3
|
312 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@3
|
313 if (!adapter) return 0;
|
cannam@3
|
314 return adapter->getRemainingFeatures((Plugin *)handle);
|
cannam@3
|
315 }
|
cannam@3
|
316
|
cannam@3
|
317 void
|
cannam@3
|
318 PluginAdapterBase::vampReleaseFeatureSet(VampFeatureList **fs)
|
cannam@3
|
319 {
|
cannam@3
|
320 if (!fs) return;
|
cannam@7
|
321
|
cannam@3
|
322 for (unsigned int i = 0; fs[i]; ++i) {
|
cannam@7
|
323
|
cannam@3
|
324 for (unsigned int j = 0; j < fs[i]->featureCount; ++j) {
|
cannam@3
|
325 VampFeature *feature = &fs[i]->features[j];
|
cannam@3
|
326 if (feature->values) free((void *)feature->values);
|
cannam@3
|
327 if (feature->label) free((void *)feature->label);
|
cannam@3
|
328 }
|
cannam@7
|
329
|
cannam@3
|
330 if (fs[i]->features) free((void *)fs[i]->features);
|
cannam@3
|
331 free((void *)fs[i]);
|
cannam@3
|
332 }
|
cannam@7
|
333
|
cannam@3
|
334 free((void *)fs);
|
cannam@3
|
335 }
|
cannam@3
|
336
|
cannam@3
|
337 void
|
cannam@3
|
338 PluginAdapterBase::cleanup(Plugin *plugin)
|
cannam@3
|
339 {
|
cannam@3
|
340 if (m_pluginOutputs.find(plugin) != m_pluginOutputs.end()) {
|
cannam@3
|
341 delete m_pluginOutputs[plugin];
|
cannam@3
|
342 m_pluginOutputs.erase(plugin);
|
cannam@3
|
343 }
|
cannam@3
|
344 m_adapterMap.erase(plugin);
|
cannam@3
|
345 delete ((Plugin *)plugin);
|
cannam@3
|
346 }
|
cannam@3
|
347
|
cannam@3
|
348 void
|
cannam@3
|
349 PluginAdapterBase::checkOutputMap(Plugin *plugin)
|
cannam@3
|
350 {
|
cannam@3
|
351 if (!m_pluginOutputs[plugin]) {
|
cannam@3
|
352 m_pluginOutputs[plugin] = new Plugin::OutputList
|
cannam@3
|
353 (plugin->getOutputDescriptors());
|
cannam@3
|
354 }
|
cannam@3
|
355 }
|
cannam@3
|
356
|
cannam@3
|
357 unsigned int
|
cannam@3
|
358 PluginAdapterBase::getOutputCount(Plugin *plugin)
|
cannam@3
|
359 {
|
cannam@3
|
360 checkOutputMap(plugin);
|
cannam@3
|
361 return m_pluginOutputs[plugin]->size();
|
cannam@3
|
362 }
|
cannam@3
|
363
|
cannam@3
|
364 VampOutputDescriptor *
|
cannam@3
|
365 PluginAdapterBase::getOutputDescriptor(Plugin *plugin,
|
cannam@3
|
366 unsigned int i)
|
cannam@3
|
367 {
|
cannam@3
|
368 checkOutputMap(plugin);
|
cannam@3
|
369 Plugin::OutputDescriptor &od =
|
cannam@3
|
370 (*m_pluginOutputs[plugin])[i];
|
cannam@3
|
371
|
cannam@3
|
372 VampOutputDescriptor *desc = (VampOutputDescriptor *)
|
cannam@3
|
373 malloc(sizeof(VampOutputDescriptor));
|
cannam@3
|
374
|
cannam@3
|
375 desc->name = strdup(od.name.c_str());
|
cannam@3
|
376 desc->description = strdup(od.description.c_str());
|
cannam@3
|
377 desc->unit = strdup(od.unit.c_str());
|
cannam@3
|
378 desc->hasFixedValueCount = od.hasFixedValueCount;
|
cannam@3
|
379 desc->valueCount = od.valueCount;
|
cannam@3
|
380
|
cannam@7
|
381 if (od.valueCount > 0) {
|
cannam@7
|
382 desc->valueNames = (const char **)
|
cannam@7
|
383 malloc(od.valueCount * sizeof(const char *));
|
cannam@3
|
384
|
cannam@7
|
385 for (unsigned int i = 0; i < od.valueCount; ++i) {
|
cannam@7
|
386 if (i < od.valueNames.size()) {
|
cannam@7
|
387 desc->valueNames[i] = strdup(od.valueNames[i].c_str());
|
cannam@7
|
388 } else {
|
cannam@7
|
389 desc->valueNames[i] = 0;
|
cannam@7
|
390 }
|
cannam@3
|
391 }
|
cannam@7
|
392 } else {
|
cannam@7
|
393 desc->valueNames = 0;
|
cannam@3
|
394 }
|
cannam@3
|
395
|
cannam@3
|
396 desc->hasKnownExtents = od.hasKnownExtents;
|
cannam@3
|
397 desc->minValue = od.minValue;
|
cannam@3
|
398 desc->maxValue = od.maxValue;
|
cannam@3
|
399 desc->isQuantized = od.isQuantized;
|
cannam@3
|
400 desc->quantizeStep = od.quantizeStep;
|
cannam@3
|
401
|
cannam@3
|
402 switch (od.sampleType) {
|
cannam@3
|
403 case Plugin::OutputDescriptor::OneSamplePerStep:
|
cannam@3
|
404 desc->sampleType = vampOneSamplePerStep; break;
|
cannam@3
|
405 case Plugin::OutputDescriptor::FixedSampleRate:
|
cannam@3
|
406 desc->sampleType = vampFixedSampleRate; break;
|
cannam@3
|
407 case Plugin::OutputDescriptor::VariableSampleRate:
|
cannam@3
|
408 desc->sampleType = vampVariableSampleRate; break;
|
cannam@3
|
409 }
|
cannam@3
|
410
|
cannam@3
|
411 desc->sampleRate = od.sampleRate;
|
cannam@3
|
412
|
cannam@3
|
413 return desc;
|
cannam@3
|
414 }
|
cannam@3
|
415
|
cannam@3
|
416 VampFeatureList **
|
cannam@3
|
417 PluginAdapterBase::process(Plugin *plugin,
|
cannam@3
|
418 float **inputBuffers,
|
cannam@3
|
419 int sec, int nsec)
|
cannam@3
|
420 {
|
cannam@3
|
421 RealTime rt(sec, nsec);
|
cannam@3
|
422 return convertFeatures(plugin->process(inputBuffers, rt));
|
cannam@3
|
423 }
|
cannam@3
|
424
|
cannam@3
|
425 VampFeatureList **
|
cannam@3
|
426 PluginAdapterBase::getRemainingFeatures(Plugin *plugin)
|
cannam@3
|
427 {
|
cannam@3
|
428 return convertFeatures(plugin->getRemainingFeatures());
|
cannam@3
|
429 }
|
cannam@3
|
430
|
cannam@3
|
431 VampFeatureList **
|
cannam@3
|
432 PluginAdapterBase::convertFeatures(const Plugin::FeatureSet &features)
|
cannam@3
|
433 {
|
cannam@3
|
434 unsigned int n = 0;
|
cannam@3
|
435 if (features.begin() != features.end()) {
|
cannam@3
|
436 Plugin::FeatureSet::const_iterator i = features.end();
|
cannam@3
|
437 --i;
|
cannam@3
|
438 n = i->first + 1;
|
cannam@3
|
439 }
|
cannam@3
|
440
|
cannam@3
|
441 if (!n) return 0;
|
cannam@3
|
442
|
cannam@3
|
443 VampFeatureList **fs = (VampFeatureList **)
|
cannam@3
|
444 malloc((n + 1) * sizeof(VampFeatureList *));
|
cannam@3
|
445
|
cannam@3
|
446 for (unsigned int i = 0; i < n; ++i) {
|
cannam@7
|
447
|
cannam@3
|
448 fs[i] = (VampFeatureList *)malloc(sizeof(VampFeatureList));
|
cannam@7
|
449
|
cannam@3
|
450 if (features.find(i) == features.end()) {
|
cannam@7
|
451
|
cannam@3
|
452 fs[i]->featureCount = 0;
|
cannam@3
|
453 fs[i]->features = 0;
|
cannam@7
|
454 continue;
|
cannam@7
|
455 }
|
cannam@7
|
456
|
cannam@7
|
457 Plugin::FeatureSet::const_iterator fi = features.find(i);
|
cannam@7
|
458
|
cannam@7
|
459 const Plugin::FeatureList &fl = fi->second;
|
cannam@7
|
460
|
cannam@7
|
461 fs[i]->featureCount = fl.size();
|
cannam@7
|
462
|
cannam@7
|
463 if (fs[i]->featureCount == 0) {
|
cannam@7
|
464 fs[i]->features = 0;
|
cannam@7
|
465 continue;
|
cannam@7
|
466 }
|
cannam@7
|
467
|
cannam@7
|
468 fs[i]->features = (VampFeature *)malloc(fl.size() * sizeof(VampFeature));
|
cannam@7
|
469
|
cannam@7
|
470 for (unsigned int j = 0; j < fl.size(); ++j) {
|
cannam@7
|
471
|
cannam@7
|
472 VampFeature *feature = &fs[i]->features[j];
|
cannam@7
|
473
|
cannam@7
|
474 feature->hasTimestamp = fl[j].hasTimestamp;
|
cannam@7
|
475 feature->sec = fl[j].timestamp.sec;
|
cannam@7
|
476 feature->nsec = fl[j].timestamp.nsec;
|
cannam@7
|
477 feature->valueCount = fl[j].values.size();
|
cannam@7
|
478 feature->label = strdup(fl[j].label.c_str());
|
cannam@7
|
479
|
cannam@7
|
480 if (feature->valueCount == 0) {
|
cannam@7
|
481 feature->values = 0;
|
cannam@7
|
482 continue;
|
cannam@7
|
483 }
|
cannam@7
|
484
|
cannam@7
|
485 feature->values = (float *)malloc
|
cannam@7
|
486 (feature->valueCount * sizeof(float));
|
cannam@7
|
487
|
cannam@7
|
488 for (unsigned int k = 0; k < feature->valueCount; ++k) {
|
cannam@7
|
489 feature->values[k] = fl[j].values[k];
|
cannam@3
|
490 }
|
cannam@3
|
491 }
|
cannam@3
|
492 }
|
cannam@3
|
493
|
cannam@3
|
494 fs[n] = 0;
|
cannam@3
|
495
|
cannam@3
|
496 return fs;
|
cannam@3
|
497 }
|
cannam@3
|
498
|
cannam@3
|
499 PluginAdapterBase::AdapterMap
|
cannam@3
|
500 PluginAdapterBase::m_adapterMap;
|
cannam@3
|
501
|
cannam@3
|
502 }
|
cannam@3
|
503
|