Mercurial > hg > vamp-plugin-sdk
comparison vamp-sdk/hostext/PluginBufferingAdapter.cpp @ 133:92ca8e401044
* PluginBufferingAdapter: Rewrite OneSamplePerStep to FixedSampleRate, not
VariableSampleRate (so result is still dense); do not change FixedSampleRate
to VariableSampleRate either; do not do the work of rewriting outputs that
don't need to be rewritten
author | cannam |
---|---|
date | Thu, 20 Mar 2008 13:22:02 +0000 |
parents | 08d8c8ee6097 |
children | c1dce0b033cb |
comparison
equal
deleted
inserted
replaced
132:f5fff1c6f06d | 133:92ca8e401044 |
---|---|
227 vector<RingBuffer *> m_queue; | 227 vector<RingBuffer *> m_queue; |
228 float **m_buffers; | 228 float **m_buffers; |
229 float m_inputSampleRate; | 229 float m_inputSampleRate; |
230 RealTime m_timestamp; | 230 RealTime m_timestamp; |
231 bool m_unrun; | 231 bool m_unrun; |
232 OutputList m_outputs; | 232 mutable OutputList m_outputs; |
233 mutable std::map<int, bool> m_rewriteOutputTimes; | |
233 | 234 |
234 void processBlock(FeatureSet& allFeatureSets, RealTime timestamp); | 235 void processBlock(FeatureSet& allFeatureSets, RealTime timestamp); |
235 }; | 236 }; |
236 | 237 |
237 PluginBufferingAdapter::PluginBufferingAdapter(Plugin *plugin) : | 238 PluginBufferingAdapter::PluginBufferingAdapter(Plugin *plugin) : |
287 m_buffers(0), | 288 m_buffers(0), |
288 m_inputSampleRate(inputSampleRate), | 289 m_inputSampleRate(inputSampleRate), |
289 m_timestamp(RealTime::zeroTime), | 290 m_timestamp(RealTime::zeroTime), |
290 m_unrun(true) | 291 m_unrun(true) |
291 { | 292 { |
292 m_outputs = plugin->getOutputDescriptors(); | 293 (void)getOutputDescriptors(); // set up m_outputs and m_rewriteOutputTimes |
293 } | 294 } |
294 | 295 |
295 PluginBufferingAdapter::Impl::~Impl() | 296 PluginBufferingAdapter::Impl::~Impl() |
296 { | 297 { |
297 // the adapter will delete the plugin | 298 // the adapter will delete the plugin |
363 } | 364 } |
364 | 365 |
365 PluginBufferingAdapter::OutputList | 366 PluginBufferingAdapter::OutputList |
366 PluginBufferingAdapter::Impl::getOutputDescriptors() const | 367 PluginBufferingAdapter::Impl::getOutputDescriptors() const |
367 { | 368 { |
368 OutputList outs = m_plugin->getOutputDescriptors(); | 369 if (m_outputs.empty()) { |
370 m_outputs = m_plugin->getOutputDescriptors(); | |
371 } | |
372 | |
373 PluginBufferingAdapter::OutputList outs; | |
374 | |
369 for (size_t i = 0; i < outs.size(); ++i) { | 375 for (size_t i = 0; i < outs.size(); ++i) { |
370 if (outs[i].sampleType == OutputDescriptor::OneSamplePerStep) { | 376 |
377 switch (outs[i].sampleType) { | |
378 | |
379 case OutputDescriptor::OneSamplePerStep: | |
380 outs[i].sampleType = OutputDescriptor::FixedSampleRate; | |
371 outs[i].sampleRate = 1.f / m_stepSize; | 381 outs[i].sampleRate = 1.f / m_stepSize; |
372 } | 382 m_rewriteOutputTimes[i] = true; |
373 outs[i].sampleType = OutputDescriptor::VariableSampleRate; | 383 break; |
374 } | 384 |
385 case OutputDescriptor::FixedSampleRate: | |
386 if (outs[i].sampleRate == 0.f) { | |
387 outs[i].sampleRate = 1.f / m_stepSize; | |
388 } | |
389 // We actually only need to rewrite output times for | |
390 // features that don't have timestamps already, but we | |
391 // can't tell from here whether our features will have | |
392 // timestamps or not | |
393 m_rewriteOutputTimes[i] = true; | |
394 break; | |
395 | |
396 case OutputDescriptor::VariableSampleRate: | |
397 m_rewriteOutputTimes[i] = false; | |
398 break; | |
399 } | |
400 } | |
401 | |
375 return outs; | 402 return outs; |
376 } | 403 } |
377 | 404 |
378 void | 405 void |
379 PluginBufferingAdapter::Impl::reset() | 406 PluginBufferingAdapter::Impl::reset() |
461 m_queue[i]->peek(m_buffers[i], m_blockSize); | 488 m_queue[i]->peek(m_buffers[i], m_blockSize); |
462 } | 489 } |
463 | 490 |
464 FeatureSet featureSet = m_plugin->process(m_buffers, m_timestamp); | 491 FeatureSet featureSet = m_plugin->process(m_buffers, m_timestamp); |
465 | 492 |
466 for (map<int, FeatureList>::iterator iter = featureSet.begin(); | 493 for (FeatureSet::iterator iter = featureSet.begin(); |
467 iter != featureSet.end(); ++iter) { | 494 iter != featureSet.end(); ++iter) { |
495 | |
496 int outputNo = iter->first; | |
497 | |
498 if (m_rewriteOutputTimes[outputNo]) { | |
499 | |
500 // Make sure the timestamp is always set | |
468 | 501 |
469 FeatureList featureList = iter->second; | 502 FeatureList featureList = iter->second; |
470 int outputNo = iter->first; | |
471 | 503 |
472 for (size_t i = 0; i < featureList.size(); ++i) { | 504 for (size_t i = 0; i < featureList.size(); ++i) { |
473 | 505 |
474 // make sure the timestamp is set | 506 switch (m_outputs[outputNo].sampleType) { |
475 switch (m_outputs[outputNo].sampleType) { | 507 |
476 | 508 case OutputDescriptor::OneSamplePerStep: |
477 case OutputDescriptor::OneSamplePerStep: | 509 // use our internal timestamp, always |
478 // use our internal timestamp - OK???? | 510 featureList[i].timestamp = m_timestamp; |
479 featureList[i].timestamp = m_timestamp; | 511 featureList[i].hasTimestamp = true; |
480 break; | 512 break; |
481 | 513 |
482 case OutputDescriptor::FixedSampleRate: | 514 case OutputDescriptor::FixedSampleRate: |
483 // use our internal timestamp | 515 // use our internal timestamp if feature lacks one |
484 featureList[i].timestamp = m_timestamp; | 516 if (!featureList[i].hasTimestamp) { |
485 break; | 517 featureList[i].timestamp = m_timestamp; |
486 | 518 featureList[i].hasTimestamp = true; |
487 case OutputDescriptor::VariableSampleRate: | 519 } |
488 break; // plugin must set timestamp | 520 break; |
489 | 521 |
490 default: | 522 case OutputDescriptor::VariableSampleRate: |
491 break; | 523 break; // plugin must set timestamp |
492 } | 524 |
493 | 525 default: |
494 allFeatureSets[outputNo].push_back(featureList[i]); | 526 break; |
527 } | |
528 | |
529 allFeatureSets[outputNo].push_back(featureList[i]); | |
530 } | |
531 } else { | |
532 for (size_t i = 0; i < iter->second.size(); ++i) { | |
533 allFeatureSets[outputNo].push_back(iter->second[i]); | |
534 } | |
495 } | 535 } |
496 } | 536 } |
497 | 537 |
498 // step forward | 538 // step forward |
499 | 539 |