cannam@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@0
|
2
|
cannam@0
|
3 /*
|
cannam@0
|
4 Vamp
|
cannam@0
|
5
|
cannam@0
|
6 An API for audio analysis and feature extraction plugins.
|
cannam@0
|
7
|
cannam@0
|
8 Centre for Digital Music, Queen Mary, University of London.
|
cannam@0
|
9 Copyright 2006 Chris Cannam.
|
cannam@0
|
10
|
cannam@0
|
11 Permission is hereby granted, free of charge, to any person
|
cannam@0
|
12 obtaining a copy of this software and associated documentation
|
cannam@0
|
13 files (the "Software"), to deal in the Software without
|
cannam@0
|
14 restriction, including without limitation the rights to use, copy,
|
cannam@0
|
15 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@0
|
16 of the Software, and to permit persons to whom the Software is
|
cannam@0
|
17 furnished to do so, subject to the following conditions:
|
cannam@0
|
18
|
cannam@0
|
19 The above copyright notice and this permission notice shall be
|
cannam@0
|
20 included in all copies or substantial portions of the Software.
|
cannam@0
|
21
|
cannam@0
|
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@0
|
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@0
|
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@0
|
25 NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR
|
cannam@0
|
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@0
|
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@0
|
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@0
|
29
|
cannam@0
|
30 Except as contained in this notice, the names of the Centre for
|
cannam@0
|
31 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@0
|
32 shall not be used in advertising or otherwise to promote the sale,
|
cannam@0
|
33 use or other dealings in this Software without prior written
|
cannam@0
|
34 authorization.
|
cannam@0
|
35 */
|
cannam@0
|
36
|
cannam@0
|
37 #include "PluginAdapter.h"
|
cannam@0
|
38
|
cannam@0
|
39 namespace Vamp {
|
cannam@0
|
40
|
cannam@0
|
41 PluginAdapterBase::PluginAdapterBase() :
|
cannam@0
|
42 m_populated(false)
|
cannam@0
|
43 {
|
cannam@0
|
44 }
|
cannam@0
|
45
|
cannam@0
|
46 const VampPluginDescriptor *
|
cannam@0
|
47 PluginAdapterBase::getDescriptor()
|
cannam@0
|
48 {
|
cannam@0
|
49 if (m_populated) return &m_descriptor;
|
cannam@0
|
50
|
cannam@0
|
51 Plugin *plugin = createPlugin(48000);
|
cannam@0
|
52
|
cannam@0
|
53 m_parameters = plugin->getParameterDescriptors();
|
cannam@0
|
54 m_programs = plugin->getPrograms();
|
cannam@0
|
55
|
cannam@0
|
56 m_descriptor.name = strdup(plugin->getName().c_str());
|
cannam@0
|
57 m_descriptor.description = strdup(plugin->getDescription().c_str());
|
cannam@0
|
58 m_descriptor.maker = strdup(plugin->getMaker().c_str());
|
cannam@0
|
59 m_descriptor.pluginVersion = plugin->getPluginVersion();
|
cannam@0
|
60 m_descriptor.copyright = strdup(plugin->getCopyright().c_str());
|
cannam@0
|
61
|
cannam@0
|
62 m_descriptor.parameterCount = m_parameters.size();
|
cannam@0
|
63 m_descriptor.parameters = (const VampParameterDescriptor **)
|
cannam@0
|
64 malloc(m_parameters.size() * sizeof(VampParameterDescriptor));
|
cannam@0
|
65
|
cannam@0
|
66 for (unsigned int i = 0; i < m_parameters.size(); ++i) {
|
cannam@0
|
67 VampParameterDescriptor *desc = (VampParameterDescriptor *)
|
cannam@0
|
68 malloc(sizeof(VampParameterDescriptor));
|
cannam@0
|
69 desc->name = strdup(m_parameters[i].name.c_str());
|
cannam@0
|
70 desc->description = strdup(m_parameters[i].description.c_str());
|
cannam@0
|
71 desc->unit = strdup(m_parameters[i].unit.c_str());
|
cannam@0
|
72 desc->minValue = m_parameters[i].minValue;
|
cannam@0
|
73 desc->maxValue = m_parameters[i].maxValue;
|
cannam@0
|
74 desc->defaultValue = m_parameters[i].defaultValue;
|
cannam@0
|
75 desc->isQuantized = m_parameters[i].isQuantized;
|
cannam@0
|
76 desc->quantizeStep = m_parameters[i].quantizeStep;
|
cannam@0
|
77 m_descriptor.parameters[i] = desc;
|
cannam@0
|
78 }
|
cannam@0
|
79
|
cannam@0
|
80 m_descriptor.programCount = m_programs.size();
|
cannam@0
|
81 m_descriptor.programs = (const char **)
|
cannam@0
|
82 malloc(m_programs.size() * sizeof(const char *));
|
cannam@0
|
83
|
cannam@0
|
84 for (unsigned int i = 0; i < m_programs.size(); ++i) {
|
cannam@0
|
85 m_descriptor.programs[i] = strdup(m_programs[i].c_str());
|
cannam@0
|
86 }
|
cannam@0
|
87
|
cannam@0
|
88 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
|
cannam@0
|
89 m_descriptor.inputDomain = vampFrequencyDomain;
|
cannam@0
|
90 } else {
|
cannam@0
|
91 m_descriptor.inputDomain = vampTimeDomain;
|
cannam@0
|
92 }
|
cannam@0
|
93
|
cannam@0
|
94 m_descriptor.instantiate = vampInstantiate;
|
cannam@0
|
95 m_descriptor.cleanup = vampCleanup;
|
cannam@0
|
96 m_descriptor.initialise = vampInitialise;
|
cannam@0
|
97 m_descriptor.reset = vampReset;
|
cannam@0
|
98 m_descriptor.getParameter = vampGetParameter;
|
cannam@0
|
99 m_descriptor.setParameter = vampSetParameter;
|
cannam@0
|
100 m_descriptor.getCurrentProgram = vampGetCurrentProgram;
|
cannam@0
|
101 m_descriptor.selectProgram = vampSelectProgram;
|
cannam@0
|
102 m_descriptor.getPreferredStepSize = vampGetPreferredStepSize;
|
cannam@0
|
103 m_descriptor.getPreferredBlockSize = vampGetPreferredBlockSize;
|
cannam@0
|
104 m_descriptor.getMinChannelCount = vampGetMinChannelCount;
|
cannam@0
|
105 m_descriptor.getMaxChannelCount = vampGetMaxChannelCount;
|
cannam@0
|
106 m_descriptor.getOutputCount = vampGetOutputCount;
|
cannam@0
|
107 m_descriptor.getOutputDescriptor = vampGetOutputDescriptor;
|
cannam@0
|
108 m_descriptor.releaseOutputDescriptor = vampReleaseOutputDescriptor;
|
cannam@0
|
109 m_descriptor.process = vampProcess;
|
cannam@0
|
110 m_descriptor.getRemainingFeatures = vampGetRemainingFeatures;
|
cannam@0
|
111 m_descriptor.releaseFeatureSet = vampReleaseFeatureSet;
|
cannam@0
|
112
|
cannam@0
|
113 m_adapterMap[&m_descriptor] = this;
|
cannam@0
|
114
|
cannam@0
|
115 delete plugin;
|
cannam@0
|
116
|
cannam@0
|
117 m_populated = true;
|
cannam@0
|
118 return &m_descriptor;
|
cannam@0
|
119 }
|
cannam@0
|
120
|
cannam@0
|
121 PluginAdapterBase::~PluginAdapterBase()
|
cannam@0
|
122 {
|
cannam@0
|
123 if (!m_populated) return;
|
cannam@0
|
124
|
cannam@0
|
125 free((void *)m_descriptor.name);
|
cannam@0
|
126 free((void *)m_descriptor.description);
|
cannam@0
|
127 free((void *)m_descriptor.maker);
|
cannam@0
|
128 free((void *)m_descriptor.copyright);
|
cannam@0
|
129
|
cannam@0
|
130 for (unsigned int i = 0; i < m_descriptor.parameterCount; ++i) {
|
cannam@0
|
131 const VampParameterDescriptor *desc = m_descriptor.parameters[i];
|
cannam@0
|
132 free((void *)desc->name);
|
cannam@0
|
133 free((void *)desc->description);
|
cannam@0
|
134 free((void *)desc->unit);
|
cannam@0
|
135 }
|
cannam@0
|
136 free((void *)m_descriptor.parameters);
|
cannam@0
|
137
|
cannam@0
|
138 for (unsigned int i = 0; i < m_descriptor.programCount; ++i) {
|
cannam@0
|
139 free((void *)m_descriptor.programs[i]);
|
cannam@0
|
140 }
|
cannam@0
|
141 free((void *)m_descriptor.programs);
|
cannam@0
|
142
|
cannam@0
|
143 m_adapterMap.erase(&m_descriptor);
|
cannam@0
|
144 }
|
cannam@0
|
145
|
cannam@0
|
146 PluginAdapterBase *
|
cannam@0
|
147 PluginAdapterBase::lookupAdapter(VampPluginHandle handle)
|
cannam@0
|
148 {
|
cannam@0
|
149 AdapterMap::const_iterator i = m_adapterMap.find(handle);
|
cannam@0
|
150 if (i == m_adapterMap.end()) return 0;
|
cannam@0
|
151 return i->second;
|
cannam@0
|
152 }
|
cannam@0
|
153
|
cannam@0
|
154 VampPluginHandle
|
cannam@0
|
155 PluginAdapterBase::vampInstantiate(const VampPluginDescriptor *desc,
|
cannam@0
|
156 float inputSampleRate)
|
cannam@0
|
157 {
|
cannam@0
|
158 if (m_adapterMap.find(desc) == m_adapterMap.end()) return 0;
|
cannam@0
|
159 PluginAdapterBase *adapter = m_adapterMap[desc];
|
cannam@0
|
160 if (desc != &adapter->m_descriptor) return 0;
|
cannam@0
|
161
|
cannam@0
|
162 Plugin *plugin = adapter->createPlugin(inputSampleRate);
|
cannam@0
|
163 if (plugin) {
|
cannam@0
|
164 m_adapterMap[plugin] = adapter;
|
cannam@0
|
165 }
|
cannam@0
|
166
|
cannam@0
|
167 return plugin;
|
cannam@0
|
168 }
|
cannam@0
|
169
|
cannam@0
|
170 void
|
cannam@0
|
171 PluginAdapterBase::vampCleanup(VampPluginHandle handle)
|
cannam@0
|
172 {
|
cannam@0
|
173 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
174 if (!adapter) {
|
cannam@0
|
175 delete ((Plugin *)handle);
|
cannam@0
|
176 return;
|
cannam@0
|
177 }
|
cannam@0
|
178 adapter->cleanup(((Plugin *)handle));
|
cannam@0
|
179 }
|
cannam@0
|
180
|
cannam@0
|
181 int
|
cannam@0
|
182 PluginAdapterBase::vampInitialise(VampPluginHandle handle,
|
cannam@0
|
183 unsigned int channels,
|
cannam@0
|
184 unsigned int stepSize,
|
cannam@0
|
185 unsigned int blockSize)
|
cannam@0
|
186 {
|
cannam@0
|
187 bool result = ((Plugin *)handle)->initialise
|
cannam@0
|
188 (channels, stepSize, blockSize);
|
cannam@0
|
189 return result ? 1 : 0;
|
cannam@0
|
190 }
|
cannam@0
|
191
|
cannam@0
|
192 void
|
cannam@0
|
193 PluginAdapterBase::vampReset(VampPluginHandle handle)
|
cannam@0
|
194 {
|
cannam@0
|
195 ((Plugin *)handle)->reset();
|
cannam@0
|
196 }
|
cannam@0
|
197
|
cannam@0
|
198 float
|
cannam@0
|
199 PluginAdapterBase::vampGetParameter(VampPluginHandle handle,
|
cannam@0
|
200 int param)
|
cannam@0
|
201 {
|
cannam@0
|
202 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
203 if (!adapter) return 0.0;
|
cannam@0
|
204 Plugin::ParameterList &list = adapter->m_parameters;
|
cannam@0
|
205 return ((Plugin *)handle)->getParameter(list[param].name);
|
cannam@0
|
206 }
|
cannam@0
|
207
|
cannam@0
|
208 void
|
cannam@0
|
209 PluginAdapterBase::vampSetParameter(VampPluginHandle handle,
|
cannam@0
|
210 int param, float value)
|
cannam@0
|
211 {
|
cannam@0
|
212 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
213 if (!adapter) return;
|
cannam@0
|
214 Plugin::ParameterList &list = adapter->m_parameters;
|
cannam@0
|
215 ((Plugin *)handle)->setParameter(list[param].name, value);
|
cannam@0
|
216 }
|
cannam@0
|
217
|
cannam@0
|
218 unsigned int
|
cannam@0
|
219 PluginAdapterBase::vampGetCurrentProgram(VampPluginHandle handle)
|
cannam@0
|
220 {
|
cannam@0
|
221 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
222 if (!adapter) return 0;
|
cannam@0
|
223 Plugin::ProgramList &list = adapter->m_programs;
|
cannam@0
|
224 std::string program = ((Plugin *)handle)->getCurrentProgram();
|
cannam@0
|
225 for (unsigned int i = 0; i < list.size(); ++i) {
|
cannam@0
|
226 if (list[i] == program) return i;
|
cannam@0
|
227 }
|
cannam@0
|
228 return 0;
|
cannam@0
|
229 }
|
cannam@0
|
230
|
cannam@0
|
231 void
|
cannam@0
|
232 PluginAdapterBase::vampSelectProgram(VampPluginHandle handle,
|
cannam@0
|
233 unsigned int program)
|
cannam@0
|
234 {
|
cannam@0
|
235 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
236 if (!adapter) return;
|
cannam@0
|
237 Plugin::ProgramList &list = adapter->m_programs;
|
cannam@0
|
238 ((Plugin *)handle)->selectProgram(list[program]);
|
cannam@0
|
239 }
|
cannam@0
|
240
|
cannam@0
|
241 unsigned int
|
cannam@0
|
242 PluginAdapterBase::vampGetPreferredStepSize(VampPluginHandle handle)
|
cannam@0
|
243 {
|
cannam@0
|
244 return ((Plugin *)handle)->getPreferredStepSize();
|
cannam@0
|
245 }
|
cannam@0
|
246
|
cannam@0
|
247 unsigned int
|
cannam@0
|
248 PluginAdapterBase::vampGetPreferredBlockSize(VampPluginHandle handle)
|
cannam@0
|
249 {
|
cannam@0
|
250 return ((Plugin *)handle)->getPreferredBlockSize();
|
cannam@0
|
251 }
|
cannam@0
|
252
|
cannam@0
|
253 unsigned int
|
cannam@0
|
254 PluginAdapterBase::vampGetMinChannelCount(VampPluginHandle handle)
|
cannam@0
|
255 {
|
cannam@0
|
256 return ((Plugin *)handle)->getMinChannelCount();
|
cannam@0
|
257 }
|
cannam@0
|
258
|
cannam@0
|
259 unsigned int
|
cannam@0
|
260 PluginAdapterBase::vampGetMaxChannelCount(VampPluginHandle handle)
|
cannam@0
|
261 {
|
cannam@0
|
262 return ((Plugin *)handle)->getMaxChannelCount();
|
cannam@0
|
263 }
|
cannam@0
|
264
|
cannam@0
|
265 unsigned int
|
cannam@0
|
266 PluginAdapterBase::vampGetOutputCount(VampPluginHandle handle)
|
cannam@0
|
267 {
|
cannam@0
|
268 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
269 if (!adapter) return 0;
|
cannam@0
|
270 return adapter->getOutputCount((Plugin *)handle);
|
cannam@0
|
271 }
|
cannam@0
|
272
|
cannam@0
|
273 VampOutputDescriptor *
|
cannam@0
|
274 PluginAdapterBase::vampGetOutputDescriptor(VampPluginHandle handle,
|
cannam@0
|
275 unsigned int i)
|
cannam@0
|
276 {
|
cannam@0
|
277 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
278 if (!adapter) return 0;
|
cannam@0
|
279 return adapter->getOutputDescriptor((Plugin *)handle, i);
|
cannam@0
|
280 }
|
cannam@0
|
281
|
cannam@0
|
282 void
|
cannam@0
|
283 PluginAdapterBase::vampReleaseOutputDescriptor(VampOutputDescriptor *desc)
|
cannam@0
|
284 {
|
cannam@0
|
285 if (desc->name) free((void *)desc->name);
|
cannam@0
|
286 if (desc->description) free((void *)desc->description);
|
cannam@0
|
287 if (desc->unit) free((void *)desc->unit);
|
cannam@0
|
288 for (unsigned int i = 0; i < desc->valueCount; ++i) {
|
cannam@0
|
289 free((void *)desc->valueNames[i]);
|
cannam@0
|
290 }
|
cannam@0
|
291 if (desc->valueNames) free((void *)desc->valueNames);
|
cannam@0
|
292 free((void *)desc);
|
cannam@0
|
293 }
|
cannam@0
|
294
|
cannam@0
|
295 VampFeatureList **
|
cannam@0
|
296 PluginAdapterBase::vampProcess(VampPluginHandle handle,
|
cannam@0
|
297 float **inputBuffers,
|
cannam@0
|
298 int sec,
|
cannam@0
|
299 int nsec)
|
cannam@0
|
300 {
|
cannam@0
|
301 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
302 if (!adapter) return 0;
|
cannam@0
|
303 return adapter->process((Plugin *)handle,
|
cannam@0
|
304 inputBuffers, sec, nsec);
|
cannam@0
|
305 }
|
cannam@0
|
306
|
cannam@0
|
307 VampFeatureList **
|
cannam@0
|
308 PluginAdapterBase::vampGetRemainingFeatures(VampPluginHandle handle)
|
cannam@0
|
309 {
|
cannam@0
|
310 PluginAdapterBase *adapter = lookupAdapter(handle);
|
cannam@0
|
311 if (!adapter) return 0;
|
cannam@0
|
312 return adapter->getRemainingFeatures((Plugin *)handle);
|
cannam@0
|
313 }
|
cannam@0
|
314
|
cannam@0
|
315 void
|
cannam@0
|
316 PluginAdapterBase::vampReleaseFeatureSet(VampFeatureList **fs)
|
cannam@0
|
317 {
|
cannam@0
|
318 if (!fs) return;
|
cannam@0
|
319 for (unsigned int i = 0; fs[i]; ++i) {
|
cannam@0
|
320 for (unsigned int j = 0; j < fs[i]->featureCount; ++j) {
|
cannam@0
|
321 VampFeature *feature = &fs[i]->features[j];
|
cannam@0
|
322 if (feature->values) free((void *)feature->values);
|
cannam@0
|
323 if (feature->label) free((void *)feature->label);
|
cannam@0
|
324 free((void *)feature);
|
cannam@0
|
325 }
|
cannam@0
|
326 if (fs[i]->features) free((void *)fs[i]->features);
|
cannam@0
|
327 free((void *)fs[i]);
|
cannam@0
|
328 }
|
cannam@0
|
329 free((void *)fs);
|
cannam@0
|
330 }
|
cannam@0
|
331
|
cannam@0
|
332 void
|
cannam@0
|
333 PluginAdapterBase::cleanup(Plugin *plugin)
|
cannam@0
|
334 {
|
cannam@0
|
335 if (m_pluginOutputs.find(plugin) != m_pluginOutputs.end()) {
|
cannam@0
|
336 delete m_pluginOutputs[plugin];
|
cannam@0
|
337 m_pluginOutputs.erase(plugin);
|
cannam@0
|
338 }
|
cannam@0
|
339 m_adapterMap.erase(plugin);
|
cannam@0
|
340 delete ((Plugin *)plugin);
|
cannam@0
|
341 }
|
cannam@0
|
342
|
cannam@0
|
343 void
|
cannam@0
|
344 PluginAdapterBase::checkOutputMap(Plugin *plugin)
|
cannam@0
|
345 {
|
cannam@0
|
346 if (!m_pluginOutputs[plugin]) {
|
cannam@0
|
347 m_pluginOutputs[plugin] = new Plugin::OutputList
|
cannam@0
|
348 (plugin->getOutputDescriptors());
|
cannam@0
|
349 }
|
cannam@0
|
350 }
|
cannam@0
|
351
|
cannam@0
|
352 unsigned int
|
cannam@0
|
353 PluginAdapterBase::getOutputCount(Plugin *plugin)
|
cannam@0
|
354 {
|
cannam@0
|
355 checkOutputMap(plugin);
|
cannam@0
|
356 return m_pluginOutputs[plugin]->size();
|
cannam@0
|
357 }
|
cannam@0
|
358
|
cannam@0
|
359 VampOutputDescriptor *
|
cannam@0
|
360 PluginAdapterBase::getOutputDescriptor(Plugin *plugin,
|
cannam@0
|
361 unsigned int i)
|
cannam@0
|
362 {
|
cannam@0
|
363 checkOutputMap(plugin);
|
cannam@0
|
364 Plugin::OutputDescriptor &od =
|
cannam@0
|
365 (*m_pluginOutputs[plugin])[i];
|
cannam@0
|
366
|
cannam@0
|
367 VampOutputDescriptor *desc = (VampOutputDescriptor *)
|
cannam@0
|
368 malloc(sizeof(VampOutputDescriptor));
|
cannam@0
|
369
|
cannam@0
|
370 desc->name = strdup(od.name.c_str());
|
cannam@0
|
371 desc->description = strdup(od.description.c_str());
|
cannam@0
|
372 desc->unit = strdup(od.unit.c_str());
|
cannam@0
|
373 desc->hasFixedValueCount = od.hasFixedValueCount;
|
cannam@0
|
374 desc->valueCount = od.valueCount;
|
cannam@0
|
375
|
cannam@0
|
376 desc->valueNames = (const char **)
|
cannam@0
|
377 malloc(od.valueCount * sizeof(const char *));
|
cannam@0
|
378
|
cannam@0
|
379 for (unsigned int i = 0; i < od.valueCount; ++i) {
|
cannam@0
|
380 if (i < od.valueNames.size()) {
|
cannam@0
|
381 desc->valueNames[i] = strdup(od.valueNames[i].c_str());
|
cannam@0
|
382 } else {
|
cannam@0
|
383 desc->valueNames[i] = 0;
|
cannam@0
|
384 }
|
cannam@0
|
385 }
|
cannam@0
|
386
|
cannam@0
|
387 desc->hasKnownExtents = od.hasKnownExtents;
|
cannam@0
|
388 desc->minValue = od.minValue;
|
cannam@0
|
389 desc->maxValue = od.maxValue;
|
cannam@0
|
390 desc->isQuantized = od.isQuantized;
|
cannam@0
|
391 desc->quantizeStep = od.quantizeStep;
|
cannam@0
|
392
|
cannam@0
|
393 switch (od.sampleType) {
|
cannam@0
|
394 case Plugin::OutputDescriptor::OneSamplePerStep:
|
cannam@0
|
395 desc->sampleType = vampOneSamplePerStep; break;
|
cannam@0
|
396 case Plugin::OutputDescriptor::FixedSampleRate:
|
cannam@0
|
397 desc->sampleType = vampFixedSampleRate; break;
|
cannam@0
|
398 case Plugin::OutputDescriptor::VariableSampleRate:
|
cannam@0
|
399 desc->sampleType = vampVariableSampleRate; break;
|
cannam@0
|
400 }
|
cannam@0
|
401
|
cannam@0
|
402 desc->sampleRate = od.sampleRate;
|
cannam@0
|
403
|
cannam@0
|
404 return desc;
|
cannam@0
|
405 }
|
cannam@0
|
406
|
cannam@0
|
407 VampFeatureList **
|
cannam@0
|
408 PluginAdapterBase::process(Plugin *plugin,
|
cannam@0
|
409 float **inputBuffers,
|
cannam@0
|
410 int sec, int nsec)
|
cannam@0
|
411 {
|
cannam@0
|
412 RealTime rt(sec, nsec);
|
cannam@0
|
413 return convertFeatures(plugin->process(inputBuffers, rt));
|
cannam@0
|
414 }
|
cannam@0
|
415
|
cannam@0
|
416 VampFeatureList **
|
cannam@0
|
417 PluginAdapterBase::getRemainingFeatures(Plugin *plugin)
|
cannam@0
|
418 {
|
cannam@0
|
419 return convertFeatures(plugin->getRemainingFeatures());
|
cannam@0
|
420 }
|
cannam@0
|
421
|
cannam@0
|
422 VampFeatureList **
|
cannam@0
|
423 PluginAdapterBase::convertFeatures(const Plugin::FeatureSet &features)
|
cannam@0
|
424 {
|
cannam@0
|
425 unsigned int n = 0;
|
cannam@0
|
426 if (features.begin() != features.end()) {
|
cannam@0
|
427 Plugin::FeatureSet::const_iterator i = features.end();
|
cannam@0
|
428 --i;
|
cannam@0
|
429 n = i->first + 1;
|
cannam@0
|
430 }
|
cannam@0
|
431
|
cannam@0
|
432 if (!n) return 0;
|
cannam@0
|
433
|
cannam@0
|
434 VampFeatureList **fs = (VampFeatureList **)
|
cannam@0
|
435 malloc((n + 1) * sizeof(VampFeatureList *));
|
cannam@0
|
436
|
cannam@0
|
437 for (unsigned int i = 0; i < n; ++i) {
|
cannam@0
|
438 fs[i] = (VampFeatureList *)malloc(sizeof(VampFeatureList));
|
cannam@0
|
439 if (features.find(i) == features.end()) {
|
cannam@0
|
440 fs[i]->featureCount = 0;
|
cannam@0
|
441 fs[i]->features = 0;
|
cannam@0
|
442 } else {
|
cannam@0
|
443 Plugin::FeatureSet::const_iterator fi =
|
cannam@0
|
444 features.find(i);
|
cannam@0
|
445 const Plugin::FeatureList &fl = fi->second;
|
cannam@0
|
446 fs[i]->featureCount = fl.size();
|
cannam@0
|
447 fs[i]->features = (VampFeature *)malloc(fl.size() *
|
cannam@0
|
448 sizeof(VampFeature));
|
cannam@0
|
449 for (unsigned int j = 0; j < fl.size(); ++j) {
|
cannam@0
|
450 fs[i]->features[j].hasTimestamp = fl[j].hasTimestamp;
|
cannam@0
|
451 fs[i]->features[j].sec = fl[j].timestamp.sec;
|
cannam@0
|
452 fs[i]->features[j].nsec = fl[j].timestamp.nsec;
|
cannam@0
|
453 fs[i]->features[j].valueCount = fl[j].values.size();
|
cannam@0
|
454 fs[i]->features[j].values = (float *)malloc
|
cannam@0
|
455 (fs[i]->features[j].valueCount * sizeof(float));
|
cannam@0
|
456 for (unsigned int k = 0; k < fs[i]->features[j].valueCount; ++k) {
|
cannam@0
|
457 fs[i]->features[j].values[k] = fl[j].values[k];
|
cannam@0
|
458 }
|
cannam@0
|
459 fs[i]->features[j].label = strdup(fl[j].label.c_str());
|
cannam@0
|
460 }
|
cannam@0
|
461 }
|
cannam@0
|
462 }
|
cannam@0
|
463
|
cannam@0
|
464 fs[n] = 0;
|
cannam@0
|
465
|
cannam@0
|
466 return fs;
|
cannam@0
|
467 }
|
cannam@0
|
468
|
cannam@0
|
469 PluginAdapterBase::AdapterMap
|
cannam@0
|
470 PluginAdapterBase::m_adapterMap;
|
cannam@0
|
471
|
cannam@0
|
472 }
|
cannam@0
|
473
|