merge new directory/file structure from newer vamp version via 2.0 (3993:4905)

git-svn-id: svn://localhost/ardour2/branches/3.0@4983 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2009-04-16 12:32:55 +00:00
parent 1ff9e8afc0
commit b90424cf80
33 changed files with 2558 additions and 330 deletions

View file

@ -5,18 +5,18 @@ import os.path
import glob import glob
vampsdk_files = Split (""" vampsdk_files = Split ("""
vamp-sdk/PluginAdapter.cpp src/vamp-sdk/PluginAdapter.cpp
vamp-sdk/RealTime.cpp src/vamp-sdk/RealTime.cpp
""") """)
vamphostsdk_files = Split (""" vamphostsdk_files = Split ("""
vamp-sdk/PluginHostAdapter.cpp src/vamp-hostsdk/PluginHostAdapter.cpp
vamp-sdk/hostext/PluginBufferingAdapter.cpp src/vamp-hostsdk/PluginBufferingAdapter.cpp
vamp-sdk/hostext/PluginChannelAdapter.cpp src/vamp-hostsdk/PluginChannelAdapter.cpp
vamp-sdk/hostext/PluginInputDomainAdapter.cpp src/vamp-hostsdk/PluginInputDomainAdapter.cpp
vamp-sdk/hostext/PluginLoader.cpp src/vamp-hostsdk/PluginLoader.cpp
vamp-sdk/hostext/PluginWrapper.cpp src/vamp-hostsdk/PluginWrapper.cpp
vamp-sdk/RealTime.cpp src/vamp-hostsdk/RealTime.cpp
""") """)
Import('env install_prefix libraries') Import('env install_prefix libraries')
@ -43,4 +43,4 @@ env.Alias('tarball', env.Distribute (env['DISTTREE'],
vamphostsdk_files + vamphostsdk_files +
glob.glob('vamp/*.h') + glob.glob('vamp/*.h') +
glob.glob('vamp-sdk/*.h') + glob.glob('vamp-sdk/*.h') +
glob.glob('vamp-sdk/hostext/*.h'))) glob.glob('vamp-hostsdk/*.h')))

View file

@ -7,7 +7,7 @@
Centre for Digital Music, Queen Mary, University of London. Centre for Digital Music, Queen Mary, University of London.
Copyright 2006-2007 Chris Cannam and QMUL. Copyright 2006-2007 Chris Cannam and QMUL.
This file by Mark Levy and Chris Cannam. This file by Mark Levy and Chris Cannam, Copyright 2007-2008 QMUL.
Permission is hereby granted, free of charge, to any person Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation obtaining a copy of this software and associated documentation
@ -38,11 +38,13 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include "PluginBufferingAdapter.h" #include <vamp-hostsdk/PluginBufferingAdapter.h>
using std::vector; using std::vector;
using std::map; using std::map;
_VAMP_SDK_HOSTSPACE_BEGIN(PluginBufferingAdapter.cpp)
namespace Vamp { namespace Vamp {
namespace HostExt { namespace HostExt {
@ -52,11 +54,19 @@ class PluginBufferingAdapter::Impl
public: public:
Impl(Plugin *plugin, float inputSampleRate); Impl(Plugin *plugin, float inputSampleRate);
~Impl(); ~Impl();
void setPluginStepSize(size_t stepSize);
void setPluginBlockSize(size_t blockSize);
bool initialise(size_t channels, size_t stepSize, size_t blockSize); bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void getActualStepAndBlockSizes(size_t &stepSize, size_t &blockSize);
OutputList getOutputDescriptors() const; OutputList getOutputDescriptors() const;
void setParameter(std::string, float);
void selectProgram(std::string);
void reset(); void reset();
FeatureSet process(const float *const *inputBuffers, RealTime timestamp); FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
@ -219,19 +229,22 @@ protected:
}; };
Plugin *m_plugin; Plugin *m_plugin;
size_t m_inputStepSize; size_t m_inputStepSize; // value passed to wrapper initialise()
size_t m_inputBlockSize; size_t m_inputBlockSize; // value passed to wrapper initialise()
size_t m_stepSize; size_t m_setStepSize; // value passed to setPluginStepSize()
size_t m_blockSize; size_t m_setBlockSize; // value passed to setPluginBlockSize()
size_t m_stepSize; // value actually used to initialise plugin
size_t m_blockSize; // value actually used to initialise plugin
size_t m_channels; size_t m_channels;
vector<RingBuffer *> m_queue; vector<RingBuffer *> m_queue;
float **m_buffers; float **m_buffers;
float m_inputSampleRate; float m_inputSampleRate;
RealTime m_timestamp; long m_frame;
bool m_unrun; bool m_unrun;
OutputList m_outputs; mutable OutputList m_outputs;
mutable std::map<int, bool> m_rewriteOutputTimes;
void processBlock(FeatureSet& allFeatureSets, RealTime timestamp); void processBlock(FeatureSet& allFeatureSets);
}; };
PluginBufferingAdapter::PluginBufferingAdapter(Plugin *plugin) : PluginBufferingAdapter::PluginBufferingAdapter(Plugin *plugin) :
@ -244,6 +257,49 @@ PluginBufferingAdapter::~PluginBufferingAdapter()
{ {
delete m_impl; delete m_impl;
} }
size_t
PluginBufferingAdapter::getPreferredStepSize() const
{
return getPreferredBlockSize();
}
size_t
PluginBufferingAdapter::getPreferredBlockSize() const
{
return PluginWrapper::getPreferredBlockSize();
}
size_t
PluginBufferingAdapter::getPluginPreferredStepSize() const
{
return PluginWrapper::getPreferredStepSize();
}
size_t
PluginBufferingAdapter::getPluginPreferredBlockSize() const
{
return PluginWrapper::getPreferredBlockSize();
}
void
PluginBufferingAdapter::setPluginStepSize(size_t stepSize)
{
m_impl->setPluginStepSize(stepSize);
}
void
PluginBufferingAdapter::setPluginBlockSize(size_t blockSize)
{
m_impl->setPluginBlockSize(blockSize);
}
void
PluginBufferingAdapter::getActualStepAndBlockSizes(size_t &stepSize,
size_t &blockSize)
{
m_impl->getActualStepAndBlockSizes(stepSize, blockSize);
}
bool bool
PluginBufferingAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize) PluginBufferingAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize)
@ -257,6 +313,18 @@ PluginBufferingAdapter::getOutputDescriptors() const
return m_impl->getOutputDescriptors(); return m_impl->getOutputDescriptors();
} }
void
PluginBufferingAdapter::setParameter(std::string name, float value)
{
m_impl->setParameter(name, value);
}
void
PluginBufferingAdapter::selectProgram(std::string name)
{
m_impl->selectProgram(name);
}
void void
PluginBufferingAdapter::reset() PluginBufferingAdapter::reset()
{ {
@ -280,16 +348,18 @@ PluginBufferingAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) :
m_plugin(plugin), m_plugin(plugin),
m_inputStepSize(0), m_inputStepSize(0),
m_inputBlockSize(0), m_inputBlockSize(0),
m_setStepSize(0),
m_setBlockSize(0),
m_stepSize(0), m_stepSize(0),
m_blockSize(0), m_blockSize(0),
m_channels(0), m_channels(0),
m_queue(0), m_queue(0),
m_buffers(0), m_buffers(0),
m_inputSampleRate(inputSampleRate), m_inputSampleRate(inputSampleRate),
m_timestamp(RealTime::zeroTime), m_frame(0),
m_unrun(true) m_unrun(true)
{ {
m_outputs = plugin->getOutputDescriptors(); (void)getOutputDescriptors(); // set up m_outputs and m_rewriteOutputTimes
} }
PluginBufferingAdapter::Impl::~Impl() PluginBufferingAdapter::Impl::~Impl()
@ -302,13 +372,35 @@ PluginBufferingAdapter::Impl::~Impl()
} }
delete[] m_buffers; delete[] m_buffers;
} }
size_t void
PluginBufferingAdapter::getPreferredStepSize() const PluginBufferingAdapter::Impl::setPluginStepSize(size_t stepSize)
{ {
return getPreferredBlockSize(); if (m_inputStepSize != 0) {
std::cerr << "PluginBufferingAdapter::setPluginStepSize: ERROR: Cannot be called after initialise()" << std::endl;
return;
}
m_setStepSize = stepSize;
} }
void
PluginBufferingAdapter::Impl::setPluginBlockSize(size_t blockSize)
{
if (m_inputBlockSize != 0) {
std::cerr << "PluginBufferingAdapter::setPluginBlockSize: ERROR: Cannot be called after initialise()" << std::endl;
return;
}
m_setBlockSize = blockSize;
}
void
PluginBufferingAdapter::Impl::getActualStepAndBlockSizes(size_t &stepSize,
size_t &blockSize)
{
stepSize = m_stepSize;
blockSize = m_blockSize;
}
bool bool
PluginBufferingAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize) PluginBufferingAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize)
{ {
@ -320,37 +412,64 @@ PluginBufferingAdapter::Impl::initialise(size_t channels, size_t stepSize, size_
m_channels = channels; m_channels = channels;
m_inputStepSize = stepSize; m_inputStepSize = stepSize;
m_inputBlockSize = blockSize; m_inputBlockSize = blockSize;
// if the user has requested particular step or block sizes, use
// those; otherwise use the step and block sizes which the plugin
// prefers
m_stepSize = 0;
m_blockSize = 0;
if (m_setStepSize > 0) {
m_stepSize = m_setStepSize;
}
if (m_setBlockSize > 0) {
m_blockSize = m_setBlockSize;
}
if (m_stepSize == 0 && m_blockSize == 0) {
m_stepSize = m_plugin->getPreferredStepSize();
m_blockSize = m_plugin->getPreferredBlockSize();
}
// use the step and block sizes which the plugin prefers bool freq = (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain);
m_stepSize = m_plugin->getPreferredStepSize();
m_blockSize = m_plugin->getPreferredBlockSize();
// or sensible defaults if it has no preference // or sensible defaults if it has no preference
if (m_blockSize == 0) { if (m_blockSize == 0) {
m_blockSize = 1024; if (m_stepSize == 0) {
} m_blockSize = 1024;
if (m_stepSize == 0) { if (freq) {
if (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) { m_stepSize = m_blockSize / 2;
m_stepSize = m_blockSize/2; } else {
} else { m_stepSize = m_blockSize;
m_stepSize = m_blockSize; }
} } else if (freq) {
} else if (m_stepSize > m_blockSize) {
if (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
m_blockSize = m_stepSize * 2; m_blockSize = m_stepSize * 2;
} else { } else {
m_blockSize = m_stepSize; m_blockSize = m_stepSize;
} }
} else if (m_stepSize == 0) { // m_blockSize != 0 (that was handled above)
if (freq) {
m_stepSize = m_blockSize/2;
} else {
m_stepSize = m_blockSize;
}
} }
// std::cerr << "PluginBufferingAdapter::initialise: stepSize " << m_inputStepSize << " -> " << m_stepSize
// << ", blockSize " << m_inputBlockSize << " -> " << m_blockSize << std::endl;
// current implementation breaks if step is greater than block // current implementation breaks if step is greater than block
if (m_stepSize > m_blockSize) { if (m_stepSize > m_blockSize) {
std::cerr << "PluginBufferingAdapter::initialise: plugin's preferred stepSize greater than blockSize, giving up!" << std::endl; size_t newBlockSize;
return false; if (freq) {
newBlockSize = m_stepSize * 2;
} else {
newBlockSize = m_stepSize;
}
std::cerr << "PluginBufferingAdapter::initialise: WARNING: step size " << m_stepSize << " is greater than block size " << m_blockSize << ": cannot handle this in adapter; adjusting block size to " << newBlockSize << std::endl;
m_blockSize = newBlockSize;
} }
// std::cerr << "PluginBufferingAdapter::initialise: NOTE: stepSize " << m_inputStepSize << " -> " << m_stepSize
// << ", blockSize " << m_inputBlockSize << " -> " << m_blockSize << std::endl;
m_buffers = new float *[m_channels]; m_buffers = new float *[m_channels];
@ -359,41 +478,108 @@ PluginBufferingAdapter::Impl::initialise(size_t channels, size_t stepSize, size_
m_buffers[i] = new float[m_blockSize]; m_buffers[i] = new float[m_blockSize];
} }
return m_plugin->initialise(m_channels, m_stepSize, m_blockSize); bool success = m_plugin->initialise(m_channels, m_stepSize, m_blockSize);
// std::cerr << "PluginBufferingAdapter::initialise: success = " << success << std::endl;
if (success) {
// Re-query outputs; properties such as bin count may have
// changed on initialise
m_outputs.clear();
(void)getOutputDescriptors();
}
return success;
} }
PluginBufferingAdapter::OutputList PluginBufferingAdapter::OutputList
PluginBufferingAdapter::Impl::getOutputDescriptors() const PluginBufferingAdapter::Impl::getOutputDescriptors() const
{ {
OutputList outs = m_plugin->getOutputDescriptors(); if (m_outputs.empty()) {
for (size_t i = 0; i < outs.size(); ++i) { // std::cerr << "PluginBufferingAdapter::getOutputDescriptors: querying anew" << std::endl;
if (outs[i].sampleType == OutputDescriptor::OneSamplePerStep) {
outs[i].sampleRate = 1.f / m_stepSize; m_outputs = m_plugin->getOutputDescriptors();
}
outs[i].sampleType = OutputDescriptor::VariableSampleRate;
} }
PluginBufferingAdapter::OutputList outs = m_outputs;
for (size_t i = 0; i < outs.size(); ++i) {
switch (outs[i].sampleType) {
case OutputDescriptor::OneSamplePerStep:
outs[i].sampleType = OutputDescriptor::FixedSampleRate;
outs[i].sampleRate = (1.f / m_inputSampleRate) * m_stepSize;
m_rewriteOutputTimes[i] = true;
break;
case OutputDescriptor::FixedSampleRate:
if (outs[i].sampleRate == 0.f) {
outs[i].sampleRate = (1.f / m_inputSampleRate) * m_stepSize;
}
// We actually only need to rewrite output times for
// features that don't have timestamps already, but we
// can't tell from here whether our features will have
// timestamps or not
m_rewriteOutputTimes[i] = true;
break;
case OutputDescriptor::VariableSampleRate:
m_rewriteOutputTimes[i] = false;
break;
}
}
return outs; return outs;
} }
void
PluginBufferingAdapter::Impl::setParameter(std::string name, float value)
{
m_plugin->setParameter(name, value);
// Re-query outputs; properties such as bin count may have changed
m_outputs.clear();
(void)getOutputDescriptors();
}
void
PluginBufferingAdapter::Impl::selectProgram(std::string name)
{
m_plugin->selectProgram(name);
// Re-query outputs; properties such as bin count may have changed
m_outputs.clear();
(void)getOutputDescriptors();
}
void void
PluginBufferingAdapter::Impl::reset() PluginBufferingAdapter::Impl::reset()
{ {
m_timestamp = RealTime::zeroTime; m_frame = 0;
m_unrun = true; m_unrun = true;
for (size_t i = 0; i < m_queue.size(); ++i) { for (size_t i = 0; i < m_queue.size(); ++i) {
m_queue[i]->reset(); m_queue[i]->reset();
} }
m_plugin->reset();
} }
PluginBufferingAdapter::FeatureSet PluginBufferingAdapter::FeatureSet
PluginBufferingAdapter::Impl::process(const float *const *inputBuffers, PluginBufferingAdapter::Impl::process(const float *const *inputBuffers,
RealTime timestamp) RealTime timestamp)
{ {
if (m_inputStepSize == 0) {
std::cerr << "PluginBufferingAdapter::process: ERROR: Plugin has not been initialised" << std::endl;
return FeatureSet();
}
FeatureSet allFeatureSets; FeatureSet allFeatureSets;
if (m_unrun) { if (m_unrun) {
m_timestamp = timestamp; m_frame = RealTime::realTime2Frame(timestamp,
int(m_inputSampleRate + 0.5));
m_unrun = false; m_unrun = false;
} }
@ -414,7 +600,7 @@ PluginBufferingAdapter::Impl::process(const float *const *inputBuffers,
// process as much as we can // process as much as we can
while (m_queue[0]->getReadSpace() >= int(m_blockSize)) { while (m_queue[0]->getReadSpace() >= int(m_blockSize)) {
processBlock(allFeatureSets, timestamp); processBlock(allFeatureSets);
} }
return allFeatureSets; return allFeatureSets;
@ -427,7 +613,7 @@ PluginBufferingAdapter::Impl::getRemainingFeatures()
// process remaining samples in queue // process remaining samples in queue
while (m_queue[0]->getReadSpace() >= int(m_blockSize)) { while (m_queue[0]->getReadSpace() >= int(m_blockSize)) {
processBlock(allFeatureSets, m_timestamp); processBlock(allFeatureSets);
} }
// pad any last samples remaining and process // pad any last samples remaining and process
@ -435,7 +621,7 @@ PluginBufferingAdapter::Impl::getRemainingFeatures()
for (size_t i = 0; i < m_channels; ++i) { for (size_t i = 0; i < m_channels; ++i) {
m_queue[i]->zero(m_blockSize - m_queue[i]->getReadSpace()); m_queue[i]->zero(m_blockSize - m_queue[i]->getReadSpace());
} }
processBlock(allFeatureSets, m_timestamp); processBlock(allFeatureSets);
} }
// get remaining features // get remaining features
@ -454,44 +640,58 @@ PluginBufferingAdapter::Impl::getRemainingFeatures()
} }
void void
PluginBufferingAdapter::Impl::processBlock(FeatureSet& allFeatureSets, PluginBufferingAdapter::Impl::processBlock(FeatureSet& allFeatureSets)
RealTime timestamp)
{ {
for (size_t i = 0; i < m_channels; ++i) { for (size_t i = 0; i < m_channels; ++i) {
m_queue[i]->peek(m_buffers[i], m_blockSize); m_queue[i]->peek(m_buffers[i], m_blockSize);
} }
FeatureSet featureSet = m_plugin->process(m_buffers, m_timestamp); long frame = m_frame;
RealTime timestamp = RealTime::frame2RealTime
(frame, int(m_inputSampleRate + 0.5));
FeatureSet featureSet = m_plugin->process(m_buffers, timestamp);
for (map<int, FeatureList>::iterator iter = featureSet.begin(); for (FeatureSet::iterator iter = featureSet.begin();
iter != featureSet.end(); ++iter) { iter != featureSet.end(); ++iter) {
FeatureList featureList = iter->second;
int outputNo = iter->first; int outputNo = iter->first;
if (m_rewriteOutputTimes[outputNo]) {
FeatureList featureList = iter->second;
for (size_t i = 0; i < featureList.size(); ++i) { for (size_t i = 0; i < featureList.size(); ++i) {
switch (m_outputs[outputNo].sampleType) {
case OutputDescriptor::OneSamplePerStep:
// use our internal timestamp, always
featureList[i].timestamp = timestamp;
featureList[i].hasTimestamp = true;
break;
case OutputDescriptor::FixedSampleRate:
// use our internal timestamp if feature lacks one
if (!featureList[i].hasTimestamp) {
featureList[i].timestamp = timestamp;
featureList[i].hasTimestamp = true;
}
break;
case OutputDescriptor::VariableSampleRate:
break; // plugin must set timestamp
default:
break;
}
// make sure the timestamp is set allFeatureSets[outputNo].push_back(featureList[i]);
switch (m_outputs[outputNo].sampleType) { }
} else {
case OutputDescriptor::OneSamplePerStep: for (size_t i = 0; i < iter->second.size(); ++i) {
// use our internal timestamp - OK???? allFeatureSets[outputNo].push_back(iter->second[i]);
featureList[i].timestamp = m_timestamp;
break;
case OutputDescriptor::FixedSampleRate:
// use our internal timestamp
featureList[i].timestamp = m_timestamp;
break;
case OutputDescriptor::VariableSampleRate:
break; // plugin must set timestamp
default:
break;
} }
allFeatureSets[outputNo].push_back(featureList[i]);
} }
} }
@ -501,16 +701,12 @@ PluginBufferingAdapter::Impl::processBlock(FeatureSet& allFeatureSets,
m_queue[i]->skip(m_stepSize); m_queue[i]->skip(m_stepSize);
} }
// fake up the timestamp each time we step forward // increment internal frame counter each time we step forward
m_frame += m_stepSize;
long frame = RealTime::realTime2Frame(m_timestamp,
int(m_inputSampleRate + 0.5));
m_timestamp = RealTime::frame2RealTime(frame + m_stepSize,
int(m_inputSampleRate + 0.5));
} }
} }
} }
_VAMP_SDK_HOSTSPACE_END(PluginBufferingAdapter.cpp)

View file

@ -34,7 +34,9 @@
authorization. authorization.
*/ */
#include "PluginChannelAdapter.h" #include <vamp-hostsdk/PluginChannelAdapter.h>
_VAMP_SDK_HOSTSPACE_BEGIN(PluginChannelAdapter.cpp)
namespace Vamp { namespace Vamp {
@ -49,6 +51,7 @@ public:
bool initialise(size_t channels, size_t stepSize, size_t blockSize); bool initialise(size_t channels, size_t stepSize, size_t blockSize);
FeatureSet process(const float *const *inputBuffers, RealTime timestamp); FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet processInterleaved(const float *inputBuffers, RealTime timestamp);
protected: protected:
Plugin *m_plugin; Plugin *m_plugin;
@ -56,6 +59,7 @@ protected:
size_t m_inputChannels; size_t m_inputChannels;
size_t m_pluginChannels; size_t m_pluginChannels;
float **m_buffer; float **m_buffer;
float **m_deinterleave;
const float **m_forwardPtrs; const float **m_forwardPtrs;
}; };
@ -83,12 +87,20 @@ PluginChannelAdapter::process(const float *const *inputBuffers,
return m_impl->process(inputBuffers, timestamp); return m_impl->process(inputBuffers, timestamp);
} }
PluginChannelAdapter::FeatureSet
PluginChannelAdapter::processInterleaved(const float *inputBuffers,
RealTime timestamp)
{
return m_impl->processInterleaved(inputBuffers, timestamp);
}
PluginChannelAdapter::Impl::Impl(Plugin *plugin) : PluginChannelAdapter::Impl::Impl(Plugin *plugin) :
m_plugin(plugin), m_plugin(plugin),
m_blockSize(0), m_blockSize(0),
m_inputChannels(0), m_inputChannels(0),
m_pluginChannels(0), m_pluginChannels(0),
m_buffer(0), m_buffer(0),
m_deinterleave(0),
m_forwardPtrs(0) m_forwardPtrs(0)
{ {
} }
@ -109,6 +121,14 @@ PluginChannelAdapter::Impl::~Impl()
m_buffer = 0; m_buffer = 0;
} }
if (m_deinterleave) {
for (size_t i = 0; i < m_inputChannels; ++i) {
delete[] m_deinterleave[i];
}
delete[] m_deinterleave;
m_deinterleave = 0;
}
if (m_forwardPtrs) { if (m_forwardPtrs) {
delete[] m_forwardPtrs; delete[] m_forwardPtrs;
m_forwardPtrs = 0; m_forwardPtrs = 0;
@ -143,7 +163,7 @@ PluginChannelAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t
m_pluginChannels = minch; m_pluginChannels = minch;
// std::cerr << "PluginChannelAdapter::initialise: expanding " << m_inputChannels << " to " << m_pluginChannels << " for plugin" << std::endl; // std::cerr << "PluginChannelAdapter::initialise: expanding " << m_inputChannels << " to " << m_pluginChannels << " for plugin" << std::endl;
} else if (m_inputChannels > maxch) { } else if (m_inputChannels > maxch) {
@ -155,24 +175,44 @@ PluginChannelAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t
m_buffer = new float *[1]; m_buffer = new float *[1];
m_buffer[0] = new float[blockSize]; m_buffer[0] = new float[blockSize];
// std::cerr << "PluginChannelAdapter::initialise: mixing " << m_inputChannels << " to mono for plugin" << std::endl; // std::cerr << "PluginChannelAdapter::initialise: mixing " << m_inputChannels << " to mono for plugin" << std::endl;
} else { } else {
// std::cerr << "PluginChannelAdapter::initialise: reducing " << m_inputChannels << " to " << m_pluginChannels << " for plugin" << std::endl; // std::cerr << "PluginChannelAdapter::initialise: reducing " << m_inputChannels << " to " << m_pluginChannels << " for plugin" << std::endl;
} }
m_pluginChannels = maxch; m_pluginChannels = maxch;
} else { } else {
// std::cerr << "PluginChannelAdapter::initialise: accepting given number of channels (" << m_inputChannels << ")" << std::endl; // std::cerr << "PluginChannelAdapter::initialise: accepting given number of channels (" << m_inputChannels << ")" << std::endl;
m_pluginChannels = m_inputChannels; m_pluginChannels = m_inputChannels;
} }
return m_plugin->initialise(m_pluginChannels, stepSize, blockSize); return m_plugin->initialise(m_pluginChannels, stepSize, blockSize);
} }
PluginChannelAdapter::FeatureSet
PluginChannelAdapter::Impl::processInterleaved(const float *inputBuffers,
RealTime timestamp)
{
if (!m_deinterleave) {
m_deinterleave = new float *[m_inputChannels];
for (size_t i = 0; i < m_inputChannels; ++i) {
m_deinterleave[i] = new float[m_blockSize];
}
}
for (size_t i = 0; i < m_inputChannels; ++i) {
for (size_t j = 0; j < m_blockSize; ++j) {
m_deinterleave[i][j] = inputBuffers[j * m_inputChannels + i];
}
}
return process(m_deinterleave, timestamp);
}
PluginChannelAdapter::FeatureSet PluginChannelAdapter::FeatureSet
PluginChannelAdapter::Impl::process(const float *const *inputBuffers, PluginChannelAdapter::Impl::process(const float *const *inputBuffers,
RealTime timestamp) RealTime timestamp)
@ -225,4 +265,6 @@ PluginChannelAdapter::Impl::process(const float *const *inputBuffers,
} }
_VAMP_SDK_HOSTSPACE_END(PluginChannelAdapter.cpp)

View file

@ -34,10 +34,14 @@
authorization. authorization.
*/ */
#include <vamp-hostsdk/PluginHostAdapter.h>
#include <cstdlib> #include <cstdlib>
#include "PluginHostAdapter.h"
#include <cstdlib> #if ( VAMP_SDK_MAJOR_VERSION != 2 || VAMP_SDK_MINOR_VERSION != 0 )
#error Incorrect Vamp SDK header included (not the expected 2.0 SDK)
#endif
_VAMP_SDK_HOSTSPACE_BEGIN(PluginHostAdapter.cpp)
namespace Vamp namespace Vamp
{ {
@ -94,7 +98,7 @@ PluginHostAdapter::getPluginPath()
} }
#ifdef _WIN32 #ifdef _WIN32
char *cpfiles = getenv("ProgramFiles"); char *cpfiles = getenv("ProgramFiles");
if (!cpfiles) cpfiles = "C:\\Program Files"; if (!cpfiles) cpfiles = (char *)"C:\\Program Files";
std::string pfiles(cpfiles); std::string pfiles(cpfiles);
std::string::size_type f; std::string::size_type f;
while ((f = envPath.find("%ProgramFiles%")) != std::string::npos && while ((f = envPath.find("%ProgramFiles%")) != std::string::npos &&
@ -129,7 +133,11 @@ PluginHostAdapter::initialise(size_t channels,
void void
PluginHostAdapter::reset() PluginHostAdapter::reset()
{ {
if (!m_handle) return; if (!m_handle) {
// std::cerr << "PluginHostAdapter::reset: no handle" << std::endl;
return;
}
// std::cerr << "PluginHostAdapter::reset(" << m_handle << ")" << std::endl;
m_descriptor->reset(m_handle); m_descriptor->reset(m_handle);
} }
@ -321,7 +329,7 @@ PluginHostAdapter::getOutputDescriptors() const
d.unit = sd->unit; d.unit = sd->unit;
d.hasFixedBinCount = sd->hasFixedBinCount; d.hasFixedBinCount = sd->hasFixedBinCount;
d.binCount = sd->binCount; d.binCount = sd->binCount;
if (d.hasFixedBinCount) { if (d.hasFixedBinCount && sd->binNames) {
for (unsigned int j = 0; j < sd->binCount; ++j) { for (unsigned int j = 0; j < sd->binCount; ++j) {
d.binNames.push_back(sd->binNames[j] ? sd->binNames[j] : ""); d.binNames.push_back(sd->binNames[j] ? sd->binNames[j] : "");
} }
@ -343,6 +351,12 @@ PluginHostAdapter::getOutputDescriptors() const
d.sampleRate = sd->sampleRate; d.sampleRate = sd->sampleRate;
if (m_descriptor->vampApiVersion >= 2) {
d.hasDuration = sd->hasDuration;
} else {
d.hasDuration = false;
}
list.push_back(d); list.push_back(d);
m_descriptor->releaseOutputDescriptor(sd); m_descriptor->releaseOutputDescriptor(sd);
@ -397,25 +411,46 @@ PluginHostAdapter::convertFeatures(VampFeatureList *features,
if (list.featureCount > 0) { if (list.featureCount > 0) {
for (unsigned int j = 0; j < list.featureCount; ++j) { Feature feature;
feature.values.reserve(list.features[0].v1.valueCount);
Feature feature;
feature.hasTimestamp = list.features[j].hasTimestamp;
feature.timestamp = RealTime(list.features[j].sec,
list.features[j].nsec);
for (unsigned int k = 0; k < list.features[j].valueCount; ++k) { for (unsigned int j = 0; j < list.featureCount; ++j) {
feature.values.push_back(list.features[j].values[k]);
feature.hasTimestamp = list.features[j].v1.hasTimestamp;
feature.timestamp = RealTime(list.features[j].v1.sec,
list.features[j].v1.nsec);
feature.hasDuration = false;
if (m_descriptor->vampApiVersion >= 2) {
unsigned int j2 = j + list.featureCount;
feature.hasDuration = list.features[j2].v2.hasDuration;
feature.duration = RealTime(list.features[j2].v2.durationSec,
list.features[j2].v2.durationNsec);
} }
if (list.features[j].label) { for (unsigned int k = 0; k < list.features[j].v1.valueCount; ++k) {
feature.label = list.features[j].label; feature.values.push_back(list.features[j].v1.values[k]);
}
if (list.features[j].v1.label) {
feature.label = list.features[j].v1.label;
} }
fs[i].push_back(feature); fs[i].push_back(feature);
if (list.features[j].v1.valueCount > 0) {
feature.values.clear();
}
if (list.features[j].v1.label) {
feature.label = "";
}
} }
} }
} }
} }
} }
_VAMP_SDK_HOSTSPACE_END(PluginHostAdapter.cpp)

View file

@ -37,10 +37,11 @@
authorization. authorization.
*/ */
#include "PluginInputDomainAdapter.h" #include <vamp-hostsdk/PluginInputDomainAdapter.h>
#include <cmath> #include <cmath>
/** /**
* If you want to compile using FFTW instead of the built-in FFT * If you want to compile using FFTW instead of the built-in FFT
* implementation for the PluginInputDomainAdapter, define HAVE_FFTW3 * implementation for the PluginInputDomainAdapter, define HAVE_FFTW3
@ -68,6 +69,9 @@
#include <fftw3.h> #include <fftw3.h>
#endif #endif
_VAMP_SDK_HOSTSPACE_BEGIN(PluginInputDomainAdapter.cpp)
namespace Vamp { namespace Vamp {
namespace HostExt { namespace HostExt {
@ -84,6 +88,8 @@ public:
size_t getPreferredBlockSize() const; size_t getPreferredBlockSize() const;
FeatureSet process(const float *const *inputBuffers, RealTime timestamp); FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
RealTime getTimestampAdjustment() const;
protected: protected:
Plugin *m_plugin; Plugin *m_plugin;
@ -149,6 +155,13 @@ PluginInputDomainAdapter::process(const float *const *inputBuffers, RealTime tim
return m_impl->process(inputBuffers, timestamp); return m_impl->process(inputBuffers, timestamp);
} }
RealTime
PluginInputDomainAdapter::getTimestampAdjustment() const
{
return m_impl->getTimestampAdjustment();
}
PluginInputDomainAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) : PluginInputDomainAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) :
m_plugin(plugin), m_plugin(plugin),
m_inputSampleRate(inputSampleRate), m_inputSampleRate(inputSampleRate),
@ -336,6 +349,17 @@ PluginInputDomainAdapter::Impl::makeBlockSizeAcceptable(size_t blockSize) const
return blockSize; return blockSize;
} }
RealTime
PluginInputDomainAdapter::Impl::getTimestampAdjustment() const
{
if (m_plugin->getInputDomain() == TimeDomain) {
return RealTime::zeroTime;
} else {
return RealTime::frame2RealTime
(m_blockSize/2, int(m_inputSampleRate + 0.5));
}
}
Plugin::FeatureSet Plugin::FeatureSet
PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers, PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers,
RealTime timestamp) RealTime timestamp)
@ -388,8 +412,7 @@ PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers,
// std::cerr << "PluginInputDomainAdapter: sampleRate " << m_inputSampleRate << ", blocksize " << m_blockSize << ", adjusting time from " << timestamp; // std::cerr << "PluginInputDomainAdapter: sampleRate " << m_inputSampleRate << ", blocksize " << m_blockSize << ", adjusting time from " << timestamp;
timestamp = timestamp + RealTime::frame2RealTime timestamp = timestamp + getTimestampAdjustment();
(m_blockSize/2, int(m_inputSampleRate + 0.5));
// std::cerr << " to " << timestamp << std::endl; // std::cerr << " to " << timestamp << std::endl;
@ -555,3 +578,5 @@ PluginInputDomainAdapter::Impl::fft(unsigned int n, bool inverse,
} }
_VAMP_SDK_HOSTSPACE_END(PluginInputDomainAdapter.cpp)

View file

@ -34,16 +34,15 @@
authorization. authorization.
*/ */
#include "vamp-sdk/PluginHostAdapter.h" #include <vamp-hostsdk/PluginHostAdapter.h>
#include "PluginLoader.h" #include <vamp-hostsdk/PluginLoader.h>
#include "PluginInputDomainAdapter.h" #include <vamp-hostsdk/PluginInputDomainAdapter.h>
#include "PluginChannelAdapter.h" #include <vamp-hostsdk/PluginChannelAdapter.h>
#include "PluginBufferingAdapter.h" #include <vamp-hostsdk/PluginBufferingAdapter.h>
#include <string>
#include <cstring>
#include <fstream> #include <fstream>
#include <cctype> // tolower #include <cctype> // tolower
#include <cstring> #include <cstring>
#ifdef _WIN32 #ifdef _WIN32
@ -67,6 +66,8 @@
using namespace std; using namespace std;
_VAMP_SDK_HOSTSPACE_BEGIN(PluginLoader.cpp)
namespace Vamp { namespace Vamp {
namespace HostExt { namespace HostExt {
@ -518,7 +519,7 @@ PluginLoader::Impl::loadLibrary(string path)
<< path << "\"" << endl; << path << "\"" << endl;
} }
#else #else
handle = dlopen(path.c_str(), RTLD_LAZY); handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (!handle) { if (!handle) {
cerr << "Vamp::HostExt::PluginLoader: Unable to load library \"" cerr << "Vamp::HostExt::PluginLoader: Unable to load library \""
<< path << "\": " << dlerror() << endl; << path << "\": " << dlerror() << endl;
@ -586,8 +587,6 @@ PluginLoader::Impl::listFiles(string dir, string extension)
struct dirent *e = 0; struct dirent *e = 0;
while ((e = readdir(d))) { while ((e = readdir(d))) {
if (!(e->d_type & DT_REG) && (e->d_type != DT_UNKNOWN)) continue;
if (!e->d_name) continue; if (!e->d_name) continue;
size_t len = strlen(e->d_name); size_t len = strlen(e->d_name);
@ -637,3 +636,6 @@ PluginLoader::Impl::PluginDeletionNotifyAdapter::~PluginDeletionNotifyAdapter()
} }
} }
_VAMP_SDK_HOSTSPACE_END(PluginLoader.cpp)

View file

@ -0,0 +1,952 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006-2008 Chris Cannam and QMUL.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#include <vamp-hostsdk/PluginSummarisingAdapter.h>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>
//#define DEBUG_PLUGIN_SUMMARISING_ADAPTER 1
//#define DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT 1
_VAMP_SDK_HOSTSPACE_BEGIN(PluginSummarisingAdapter.cpp)
namespace Vamp {
namespace HostExt {
class PluginSummarisingAdapter::Impl
{
public:
Impl(Plugin *plugin, float inputSampleRate);
~Impl();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet getRemainingFeatures();
void setSummarySegmentBoundaries(const SegmentBoundaries &);
FeatureList getSummaryForOutput(int output,
SummaryType type,
AveragingMethod avg);
FeatureSet getSummaryForAllOutputs(SummaryType type,
AveragingMethod avg);
protected:
Plugin *m_plugin;
float m_inputSampleRate;
size_t m_stepSize;
size_t m_blockSize;
SegmentBoundaries m_boundaries;
typedef std::vector<float> ValueList;
struct Result { // smaller than Feature
RealTime time;
RealTime duration;
ValueList values; // bin number -> value
};
typedef std::vector<Result> ResultList;
struct OutputAccumulator {
int bins;
ResultList results;
OutputAccumulator() : bins(0) { }
};
typedef std::map<int, OutputAccumulator> OutputAccumulatorMap;
OutputAccumulatorMap m_accumulators; // output number -> accumulator
typedef std::map<RealTime, OutputAccumulator> SegmentAccumulatorMap;
typedef std::map<int, SegmentAccumulatorMap> OutputSegmentAccumulatorMap;
OutputSegmentAccumulatorMap m_segmentedAccumulators; // output -> segmented
typedef std::map<int, RealTime> OutputTimestampMap;
OutputTimestampMap m_prevTimestamps; // output number -> timestamp
OutputTimestampMap m_prevDurations; // output number -> durations
struct OutputBinSummary {
int count;
// extents
double minimum;
double maximum;
double sum;
// sample-average results
double median;
double mode;
double variance;
// continuous-time average results
double median_c;
double mode_c;
double mean_c;
double variance_c;
};
typedef std::map<int, OutputBinSummary> OutputSummary;
typedef std::map<RealTime, OutputSummary> SummarySegmentMap;
typedef std::map<int, SummarySegmentMap> OutputSummarySegmentMap;
OutputSummarySegmentMap m_summaries;
bool m_reduced;
RealTime m_endTime;
void accumulate(const FeatureSet &fs, RealTime, bool final);
void accumulate(int output, const Feature &f, RealTime, bool final);
void accumulateFinalDurations();
void findSegmentBounds(RealTime t, RealTime &start, RealTime &end);
void segment();
void reduce();
std::string getSummaryLabel(SummaryType type, AveragingMethod avg);
};
static RealTime INVALID_DURATION(INT_MIN, INT_MIN);
PluginSummarisingAdapter::PluginSummarisingAdapter(Plugin *plugin) :
PluginWrapper(plugin)
{
m_impl = new Impl(plugin, m_inputSampleRate);
}
PluginSummarisingAdapter::~PluginSummarisingAdapter()
{
delete m_impl;
}
bool
PluginSummarisingAdapter::initialise(size_t channels,
size_t stepSize, size_t blockSize)
{
return
PluginWrapper::initialise(channels, stepSize, blockSize) &&
m_impl->initialise(channels, stepSize, blockSize);
}
void
PluginSummarisingAdapter::reset()
{
m_impl->reset();
}
Plugin::FeatureSet
PluginSummarisingAdapter::process(const float *const *inputBuffers, RealTime timestamp)
{
return m_impl->process(inputBuffers, timestamp);
}
Plugin::FeatureSet
PluginSummarisingAdapter::getRemainingFeatures()
{
return m_impl->getRemainingFeatures();
}
void
PluginSummarisingAdapter::setSummarySegmentBoundaries(const SegmentBoundaries &b)
{
m_impl->setSummarySegmentBoundaries(b);
}
Plugin::FeatureList
PluginSummarisingAdapter::getSummaryForOutput(int output,
SummaryType type,
AveragingMethod avg)
{
return m_impl->getSummaryForOutput(output, type, avg);
}
Plugin::FeatureSet
PluginSummarisingAdapter::getSummaryForAllOutputs(SummaryType type,
AveragingMethod avg)
{
return m_impl->getSummaryForAllOutputs(type, avg);
}
PluginSummarisingAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) :
m_plugin(plugin),
m_inputSampleRate(inputSampleRate),
m_reduced(false)
{
}
PluginSummarisingAdapter::Impl::~Impl()
{
}
bool
PluginSummarisingAdapter::Impl::initialise(size_t channels,
size_t stepSize, size_t blockSize)
{
m_stepSize = stepSize;
m_blockSize = blockSize;
return true;
}
void
PluginSummarisingAdapter::Impl::reset()
{
m_accumulators.clear();
m_segmentedAccumulators.clear();
m_prevTimestamps.clear();
m_prevDurations.clear();
m_summaries.clear();
m_reduced = false;
m_endTime = RealTime();
m_plugin->reset();
}
Plugin::FeatureSet
PluginSummarisingAdapter::Impl::process(const float *const *inputBuffers,
RealTime timestamp)
{
if (m_reduced) {
std::cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << std::endl;
}
FeatureSet fs = m_plugin->process(inputBuffers, timestamp);
accumulate(fs, timestamp, false);
m_endTime = timestamp +
RealTime::frame2RealTime(m_stepSize, int(m_inputSampleRate + 0.5));
return fs;
}
Plugin::FeatureSet
PluginSummarisingAdapter::Impl::getRemainingFeatures()
{
if (m_reduced) {
std::cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << std::endl;
}
FeatureSet fs = m_plugin->getRemainingFeatures();
accumulate(fs, m_endTime, true);
return fs;
}
void
PluginSummarisingAdapter::Impl::setSummarySegmentBoundaries(const SegmentBoundaries &b)
{
m_boundaries = b;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "PluginSummarisingAdapter::setSummarySegmentBoundaries: boundaries are:" << std::endl;
for (SegmentBoundaries::const_iterator i = m_boundaries.begin();
i != m_boundaries.end(); ++i) {
std::cerr << *i << " ";
}
std::cerr << std::endl;
#endif
}
Plugin::FeatureList
PluginSummarisingAdapter::Impl::getSummaryForOutput(int output,
SummaryType type,
AveragingMethod avg)
{
if (!m_reduced) {
accumulateFinalDurations();
segment();
reduce();
m_reduced = true;
}
bool continuous = (avg == ContinuousTimeAverage);
FeatureList fl;
for (SummarySegmentMap::const_iterator i = m_summaries[output].begin();
i != m_summaries[output].end(); ++i) {
Feature f;
f.hasTimestamp = true;
f.timestamp = i->first;
f.hasDuration = true;
SummarySegmentMap::const_iterator ii = i;
if (++ii == m_summaries[output].end()) {
f.duration = m_endTime - f.timestamp;
} else {
f.duration = ii->first - f.timestamp;
}
f.label = getSummaryLabel(type, avg);
for (OutputSummary::const_iterator j = i->second.begin();
j != i->second.end(); ++j) {
// these will be ordered by bin number, and no bin numbers
// will be missing except at the end (because of the way
// the accumulators were initially filled in accumulate())
const OutputBinSummary &summary = j->second;
double result = 0.f;
switch (type) {
case Minimum:
result = summary.minimum;
break;
case Maximum:
result = summary.maximum;
break;
case Mean:
if (continuous) {
result = summary.mean_c;
} else if (summary.count) {
result = summary.sum / summary.count;
}
break;
case Median:
if (continuous) result = summary.median_c;
else result = summary.median;
break;
case Mode:
if (continuous) result = summary.mode_c;
else result = summary.mode;
break;
case Sum:
result = summary.sum;
break;
case Variance:
if (continuous) result = summary.variance_c;
else result = summary.variance;
break;
case StandardDeviation:
if (continuous) result = sqrtf(summary.variance_c);
else result = sqrtf(summary.variance);
break;
case Count:
result = summary.count;
break;
case UnknownSummaryType:
break;
default:
break;
}
f.values.push_back(result);
}
fl.push_back(f);
}
return fl;
}
Plugin::FeatureSet
PluginSummarisingAdapter::Impl::getSummaryForAllOutputs(SummaryType type,
AveragingMethod avg)
{
if (!m_reduced) {
accumulateFinalDurations();
segment();
reduce();
m_reduced = true;
}
FeatureSet fs;
for (OutputSummarySegmentMap::const_iterator i = m_summaries.begin();
i != m_summaries.end(); ++i) {
fs[i->first] = getSummaryForOutput(i->first, type, avg);
}
return fs;
}
void
PluginSummarisingAdapter::Impl::accumulate(const FeatureSet &fs,
RealTime timestamp,
bool final)
{
for (FeatureSet::const_iterator i = fs.begin(); i != fs.end(); ++i) {
for (FeatureList::const_iterator j = i->second.begin();
j != i->second.end(); ++j) {
if (j->hasTimestamp) {
accumulate(i->first, *j, j->timestamp, final);
} else {
//!!! is this correct?
accumulate(i->first, *j, timestamp, final);
}
}
}
}
std::string
PluginSummarisingAdapter::Impl::getSummaryLabel(SummaryType type,
AveragingMethod avg)
{
std::string label;
std::string avglabel;
if (avg == SampleAverage) avglabel = ", sample average";
else avglabel = ", continuous-time average";
switch (type) {
case Minimum: label = "(minimum value)"; break;
case Maximum: label = "(maximum value)"; break;
case Mean: label = "(mean value" + avglabel + ")"; break;
case Median: label = "(median value" + avglabel + ")"; break;
case Mode: label = "(modal value" + avglabel + ")"; break;
case Sum: label = "(sum)"; break;
case Variance: label = "(variance" + avglabel + ")"; break;
case StandardDeviation: label = "(standard deviation" + avglabel + ")"; break;
case Count: label = "(count)"; break;
case UnknownSummaryType: label = "(unknown summary)"; break;
}
return label;
}
void
PluginSummarisingAdapter::Impl::accumulate(int output,
const Feature &f,
RealTime timestamp,
bool final)
{
// What should happen if a feature's duration spans a segment
// boundary? I think we probably want to chop it, and pretend
// that it appears in both. A very long feature (e.g. key, if the
// whole audio is in a single key) might span many or all
// segments, and we want that to be reflected in the results
// (e.g. it is the modal key in all of those segments, not just
// the first). This is actually quite complicated to do.
// If features spanning a boundary should be chopped, then we need
// to have per-segment accumulators (and the feature value goes
// into both -- with a separate phase to split the accumulator up
// into segments).
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "output " << output << ": timestamp " << timestamp << ", prev timestamp " << m_prevTimestamps[output] << ", final " << final << std::endl;
#endif
// At each process step, accumulate() is called once for each
// feature on each output within that process's returned feature
// list, and with the timestamp passed in being that of the start
// of the process block.
// At the end (in getRemainingFeatures), accumulate() is called
// once for each feature on each output within the feature list
// returned by getRemainingFeatures, and with the timestamp being
// the same as the last process block and final set to true.
// (What if getRemainingFeatures doesn't return any features? We
// still need to ensure that the final duration is written. Need
// a separate function to close the durations.)
// At each call, we pull out the value for the feature and stuff
// it into the accumulator's appropriate values array; and we
// calculate the duration for the _previous_ feature, or pull it
// from the prevDurations array if the previous feature had a
// duration in its structure, and stuff that into the
// accumulator's appropriate durations array.
if (m_prevDurations.find(output) != m_prevDurations.end()) {
// Not the first time accumulate has been called for this
// output -- there has been a previous feature
RealTime prevDuration;
// Note that m_prevDurations[output] only contains the
// duration field that was contained in the previous feature.
// If it didn't have an explicit duration,
// m_prevDurations[output] should be INVALID_DURATION and we
// will have to calculate the duration from the previous and
// current timestamps.
if (m_prevDurations[output] != INVALID_DURATION) {
prevDuration = m_prevDurations[output];
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "Previous duration from previous feature: " << prevDuration << std::endl;
#endif
} else {
prevDuration = timestamp - m_prevTimestamps[output];
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "Previous duration from diff: " << timestamp << " - "
<< m_prevTimestamps[output] << std::endl;
#endif
}
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "output " << output << ": ";
std::cerr << "Pushing previous duration as " << prevDuration << std::endl;
#endif
m_accumulators[output].results
[m_accumulators[output].results.size() - 1]
.duration = prevDuration;
}
if (f.hasDuration) m_prevDurations[output] = f.duration;
else m_prevDurations[output] = INVALID_DURATION;
m_prevTimestamps[output] = timestamp;
if (f.hasDuration) {
RealTime et = timestamp;
et = et + f.duration;
if (et > m_endTime) m_endTime = et;
}
Result result;
result.time = timestamp;
result.duration = INVALID_DURATION;
if (int(f.values.size()) > m_accumulators[output].bins) {
m_accumulators[output].bins = f.values.size();
}
for (int i = 0; i < int(f.values.size()); ++i) {
result.values.push_back(f.values[i]);
}
m_accumulators[output].results.push_back(result);
}
void
PluginSummarisingAdapter::Impl::accumulateFinalDurations()
{
for (OutputTimestampMap::iterator i = m_prevTimestamps.begin();
i != m_prevTimestamps.end(); ++i) {
int output = i->first;
int acount = m_accumulators[output].results.size();
if (acount == 0) continue;
RealTime prevTimestamp = i->second;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "output " << output << ": ";
#endif
if (m_prevDurations.find(output) != m_prevDurations.end() &&
m_prevDurations[output] != INVALID_DURATION) {
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "Pushing final duration from feature as " << m_prevDurations[output] << std::endl;
#endif
m_accumulators[output].results[acount - 1].duration =
m_prevDurations[output];
} else {
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "Pushing final duration from diff as " << m_endTime << " - " << m_prevTimestamps[output] << std::endl;
#endif
m_accumulators[output].results[acount - 1].duration =
m_endTime - m_prevTimestamps[output];
}
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "so duration for result no " << acount-1 << " is "
<< m_accumulators[output].results[acount-1].duration
<< std::endl;
#endif
}
}
void
PluginSummarisingAdapter::Impl::findSegmentBounds(RealTime t,
RealTime &start,
RealTime &end)
{
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT
std::cerr << "findSegmentBounds: t = " << t << std::endl;
#endif
SegmentBoundaries::const_iterator i = std::upper_bound
(m_boundaries.begin(), m_boundaries.end(), t);
start = RealTime::zeroTime;
end = m_endTime;
if (i != m_boundaries.end()) {
end = *i;
}
if (i != m_boundaries.begin()) {
start = *--i;
}
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT
std::cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << std::endl;
#endif
}
void
PluginSummarisingAdapter::Impl::segment()
{
SegmentBoundaries::iterator boundaryitr = m_boundaries.begin();
RealTime segmentStart = RealTime::zeroTime;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT
std::cerr << "segment: starting" << std::endl;
#endif
for (OutputAccumulatorMap::iterator i = m_accumulators.begin();
i != m_accumulators.end(); ++i) {
int output = i->first;
OutputAccumulator &source = i->second;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT
std::cerr << "segment: total results for output " << output << " = "
<< source.results.size() << std::endl;
#endif
// This is basically nonsense if the results have no values
// (i.e. their times and counts are the only things of
// interest)... but perhaps it's the user's problem if they
// ask for segmentation (or any summary at all) in that case
for (int n = 0; n < int(source.results.size()); ++n) {
// This result spans source.results[n].time to
// source.results[n].time + source.results[n].duration.
// We need to dispose it into segments appropriately
RealTime resultStart = source.results[n].time;
RealTime resultEnd = resultStart + source.results[n].duration;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT
std::cerr << "output: " << output << ", result start = " << resultStart << ", end = " << resultEnd << std::endl;
#endif
RealTime segmentStart = RealTime::zeroTime;
RealTime segmentEnd = resultEnd - RealTime(1, 0);
RealTime prevSegmentStart = segmentStart - RealTime(1, 0);
while (segmentEnd < resultEnd) {
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT
std::cerr << "segment end " << segmentEnd << " < result end "
<< resultEnd << " (with result start " << resultStart << ")" << std::endl;
#endif
findSegmentBounds(resultStart, segmentStart, segmentEnd);
if (segmentStart == prevSegmentStart) {
// This can happen when we reach the end of the
// input, if a feature's end time overruns the
// input audio end time
break;
}
prevSegmentStart = segmentStart;
RealTime chunkStart = resultStart;
if (chunkStart < segmentStart) chunkStart = segmentStart;
RealTime chunkEnd = resultEnd;
if (chunkEnd > segmentEnd) chunkEnd = segmentEnd;
m_segmentedAccumulators[output][segmentStart].bins = source.bins;
Result chunk;
chunk.time = chunkStart;
chunk.duration = chunkEnd - chunkStart;
chunk.values = source.results[n].values;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT
std::cerr << "chunk for segment " << segmentStart << ": from " << chunk.time << ", duration " << chunk.duration << std::endl;
#endif
m_segmentedAccumulators[output][segmentStart].results
.push_back(chunk);
resultStart = chunkEnd;
}
}
}
}
struct ValueDurationFloatPair
{
float value;
float duration;
ValueDurationFloatPair() : value(0), duration(0) { }
ValueDurationFloatPair(float v, float d) : value(v), duration(d) { }
ValueDurationFloatPair &operator=(const ValueDurationFloatPair &p) {
value = p.value;
duration = p.duration;
return *this;
}
bool operator<(const ValueDurationFloatPair &p) const {
return value < p.value;
}
};
static double toSec(const RealTime &r)
{
return r.sec + double(r.nsec) / 1000000000.0;
}
void
PluginSummarisingAdapter::Impl::reduce()
{
for (OutputSegmentAccumulatorMap::iterator i =
m_segmentedAccumulators.begin();
i != m_segmentedAccumulators.end(); ++i) {
int output = i->first;
SegmentAccumulatorMap &segments = i->second;
for (SegmentAccumulatorMap::iterator j = segments.begin();
j != segments.end(); ++j) {
RealTime segmentStart = j->first;
OutputAccumulator &accumulator = j->second;
int sz = accumulator.results.size();
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "reduce: segment starting at " << segmentStart
<< " on output " << output << " has " << sz << " result(s)" << std::endl;
#endif
double totalDuration = 0.0;
//!!! is this right?
if (sz > 0) {
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "last time = " << accumulator.results[sz-1].time
<< ", duration = " << accumulator.results[sz-1].duration
<< " (step = " << m_stepSize << ", block = " << m_blockSize << ")"
<< std::endl;
#endif
totalDuration = toSec((accumulator.results[sz-1].time +
accumulator.results[sz-1].duration) -
segmentStart);
}
for (int bin = 0; bin < accumulator.bins; ++bin) {
// work on all values over time for a single bin
OutputBinSummary summary;
summary.count = sz;
summary.minimum = 0.f;
summary.maximum = 0.f;
summary.median = 0.f;
summary.mode = 0.f;
summary.sum = 0.f;
summary.variance = 0.f;
summary.median_c = 0.f;
summary.mode_c = 0.f;
summary.mean_c = 0.f;
summary.variance_c = 0.f;
if (sz == 0) continue;
std::vector<ValueDurationFloatPair> valvec;
for (int k = 0; k < sz; ++k) {
while (int(accumulator.results[k].values.size()) <
accumulator.bins) {
accumulator.results[k].values.push_back(0.f);
}
}
for (int k = 0; k < sz; ++k) {
float value = accumulator.results[k].values[bin];
valvec.push_back(ValueDurationFloatPair
(value,
toSec(accumulator.results[k].duration)));
}
std::sort(valvec.begin(), valvec.end());
summary.minimum = valvec[0].value;
summary.maximum = valvec[sz-1].value;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "total duration = " << totalDuration << std::endl;
#endif
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
/*
std::cerr << "value vector for medians:" << std::endl;
for (int k = 0; k < sz; ++k) {
std::cerr << "(" << valvec[k].value << "," << valvec[k].duration << ") ";
}
std::cerr << std::endl;
*/
#endif
if (sz % 2 == 1) {
summary.median = valvec[sz/2].value;
} else {
summary.median = (valvec[sz/2].value + valvec[sz/2 + 1].value) / 2;
}
double duracc = 0.0;
summary.median_c = valvec[sz-1].value;
for (int k = 0; k < sz; ++k) {
duracc += valvec[k].duration;
if (duracc > totalDuration/2) {
summary.median_c = valvec[k].value;
break;
}
}
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "median_c = " << summary.median_c << std::endl;
std::cerr << "median = " << summary.median << std::endl;
#endif
std::map<float, int> distribution;
for (int k = 0; k < sz; ++k) {
summary.sum += accumulator.results[k].values[bin];
distribution[accumulator.results[k].values[bin]] += 1;
}
int md = 0;
for (std::map<float, int>::iterator di = distribution.begin();
di != distribution.end(); ++di) {
if (di->second > md) {
md = di->second;
summary.mode = di->first;
}
}
distribution.clear();
std::map<float, double> distribution_c;
for (int k = 0; k < sz; ++k) {
distribution_c[accumulator.results[k].values[bin]]
+= toSec(accumulator.results[k].duration);
}
double mrd = 0.0;
for (std::map<float, double>::iterator di = distribution_c.begin();
di != distribution_c.end(); ++di) {
if (di->second > mrd) {
mrd = di->second;
summary.mode_c = di->first;
}
}
distribution_c.clear();
if (totalDuration > 0.0) {
double sum_c = 0.0;
for (int k = 0; k < sz; ++k) {
double value = accumulator.results[k].values[bin]
* toSec(accumulator.results[k].duration);
sum_c += value;
}
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "mean_c = " << sum_c << " / " << totalDuration << " = "
<< sum_c / totalDuration << " (sz = " << sz << ")" << std::endl;
#endif
summary.mean_c = sum_c / totalDuration;
for (int k = 0; k < sz; ++k) {
double value = accumulator.results[k].values[bin];
// * toSec(accumulator.results[k].duration);
summary.variance_c +=
(value - summary.mean_c) * (value - summary.mean_c)
* toSec(accumulator.results[k].duration);
}
// summary.variance_c /= summary.count;
summary.variance_c /= totalDuration;
}
double mean = summary.sum / summary.count;
#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER
std::cerr << "mean = " << summary.sum << " / " << summary.count << " = "
<< summary.sum / summary.count << std::endl;
#endif
for (int k = 0; k < sz; ++k) {
float value = accumulator.results[k].values[bin];
summary.variance += (value - mean) * (value - mean);
}
summary.variance /= summary.count;
m_summaries[output][segmentStart][bin] = summary;
}
}
}
m_segmentedAccumulators.clear();
m_accumulators.clear();
}
}
}
_VAMP_SDK_HOSTSPACE_END(PluginSummarisingAdapter.cpp)

View file

@ -34,7 +34,9 @@
authorization. authorization.
*/ */
#include "PluginWrapper.h" #include <vamp-hostsdk/PluginWrapper.h>
_VAMP_SDK_HOSTSPACE_BEGIN(PluginWrapper.cpp)
namespace Vamp { namespace Vamp {
@ -199,3 +201,4 @@ PluginWrapper::getRemainingFeatures()
} }
_VAMP_SDK_HOSTSPACE_END(PluginWrapper.cpp)

View file

@ -0,0 +1,39 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#include <vamp-hostsdk/RealTime.h>
#include "../vamp-sdk/RealTime.cpp"

View file

@ -34,15 +34,19 @@
authorization. authorization.
*/ */
#include <cstring> #include <vamp-sdk/PluginAdapter.h>
#include <cstdlib>
#include "PluginAdapter.h"
#include <cstdlib>
#include <cstring> #include <cstring>
#include <cstdlib>
#if ( VAMP_SDK_MAJOR_VERSION != 2 || VAMP_SDK_MINOR_VERSION != 0 )
#error Incorrect Vamp SDK header included (not the expected 2.0 SDK)
#endif
//#define DEBUG_PLUGIN_ADAPTER 1 //#define DEBUG_PLUGIN_ADAPTER 1
_VAMP_SDK_PLUGSPACE_BEGIN(PluginAdapter.cpp)
namespace Vamp { namespace Vamp {
@ -58,7 +62,7 @@ protected:
PluginAdapterBase *m_base; PluginAdapterBase *m_base;
static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc, static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc,
float inputSampleRate); float inputSampleRate);
static void vampCleanup(VampPluginHandle handle); static void vampCleanup(VampPluginHandle handle);
@ -94,8 +98,10 @@ protected:
static void vampReleaseFeatureSet(VampFeatureList *fs); static void vampReleaseFeatureSet(VampFeatureList *fs);
void cleanup(Plugin *plugin);
void checkOutputMap(Plugin *plugin); void checkOutputMap(Plugin *plugin);
void markOutputsChanged(Plugin *plugin);
void cleanup(Plugin *plugin);
unsigned int getOutputCount(Plugin *plugin); unsigned int getOutputCount(Plugin *plugin);
VampOutputDescriptor *getOutputDescriptor(Plugin *plugin, VampOutputDescriptor *getOutputDescriptor(Plugin *plugin,
unsigned int i); unsigned int i);
@ -165,10 +171,13 @@ PluginAdapterBase::Impl::getDescriptor()
if (plugin->getVampApiVersion() != VAMP_API_VERSION) { if (plugin->getVampApiVersion() != VAMP_API_VERSION) {
std::cerr << "Vamp::PluginAdapterBase::Impl::getDescriptor: ERROR: " std::cerr << "Vamp::PluginAdapterBase::Impl::getDescriptor: ERROR: "
<< "Plugin object API version " << "API version " << plugin->getVampApiVersion()
<< plugin->getVampApiVersion() << " for\nplugin \"" << plugin->getIdentifier() << "\" "
<< " does not match actual API version " << "differs from version "
<< VAMP_API_VERSION << std::endl; << VAMP_API_VERSION << " for adapter.\n"
<< "This plugin is probably linked against a different version of the Vamp SDK\n"
<< "from the version it was compiled with. It will need to be re-linked correctly\n"
<< "before it can be used." << std::endl;
delete plugin; delete plugin;
return 0; return 0;
} }
@ -318,7 +327,7 @@ PluginAdapterBase::Impl::lookupAdapter(VampPluginHandle handle)
VampPluginHandle VampPluginHandle
PluginAdapterBase::Impl::vampInstantiate(const VampPluginDescriptor *desc, PluginAdapterBase::Impl::vampInstantiate(const VampPluginDescriptor *desc,
float inputSampleRate) float inputSampleRate)
{ {
#ifdef DEBUG_PLUGIN_ADAPTER #ifdef DEBUG_PLUGIN_ADAPTER
std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << std::endl; std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << std::endl;
@ -365,16 +374,18 @@ PluginAdapterBase::Impl::vampCleanup(VampPluginHandle handle)
int int
PluginAdapterBase::Impl::vampInitialise(VampPluginHandle handle, PluginAdapterBase::Impl::vampInitialise(VampPluginHandle handle,
unsigned int channels, unsigned int channels,
unsigned int stepSize, unsigned int stepSize,
unsigned int blockSize) unsigned int blockSize)
{ {
#ifdef DEBUG_PLUGIN_ADAPTER #ifdef DEBUG_PLUGIN_ADAPTER
std::cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl; std::cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl;
#endif #endif
bool result = ((Plugin *)handle)->initialise Impl *adapter = lookupAdapter(handle);
(channels, stepSize, blockSize); if (!adapter) return 0;
bool result = ((Plugin *)handle)->initialise(channels, stepSize, blockSize);
adapter->markOutputsChanged((Plugin *)handle);
return result ? 1 : 0; return result ? 1 : 0;
} }
@ -414,6 +425,7 @@ PluginAdapterBase::Impl::vampSetParameter(VampPluginHandle handle,
if (!adapter) return; if (!adapter) return;
Plugin::ParameterList &list = adapter->m_parameters; Plugin::ParameterList &list = adapter->m_parameters;
((Plugin *)handle)->setParameter(list[param].identifier, value); ((Plugin *)handle)->setParameter(list[param].identifier, value);
adapter->markOutputsChanged((Plugin *)handle);
} }
unsigned int unsigned int
@ -435,7 +447,7 @@ PluginAdapterBase::Impl::vampGetCurrentProgram(VampPluginHandle handle)
void void
PluginAdapterBase::Impl::vampSelectProgram(VampPluginHandle handle, PluginAdapterBase::Impl::vampSelectProgram(VampPluginHandle handle,
unsigned int program) unsigned int program)
{ {
#ifdef DEBUG_PLUGIN_ADAPTER #ifdef DEBUG_PLUGIN_ADAPTER
std::cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << std::endl; std::cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << std::endl;
@ -443,8 +455,11 @@ PluginAdapterBase::Impl::vampSelectProgram(VampPluginHandle handle,
Impl *adapter = lookupAdapter(handle); Impl *adapter = lookupAdapter(handle);
if (!adapter) return; if (!adapter) return;
Plugin::ProgramList &list = adapter->m_programs; Plugin::ProgramList &list = adapter->m_programs;
((Plugin *)handle)->selectProgram(list[program]); ((Plugin *)handle)->selectProgram(list[program]);
adapter->markOutputsChanged((Plugin *)handle);
} }
unsigned int unsigned int
@ -504,7 +519,7 @@ PluginAdapterBase::Impl::vampGetOutputCount(VampPluginHandle handle)
VampOutputDescriptor * VampOutputDescriptor *
PluginAdapterBase::Impl::vampGetOutputDescriptor(VampPluginHandle handle, PluginAdapterBase::Impl::vampGetOutputDescriptor(VampPluginHandle handle,
unsigned int i) unsigned int i)
{ {
#ifdef DEBUG_PLUGIN_ADAPTER #ifdef DEBUG_PLUGIN_ADAPTER
std::cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl; std::cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl;
@ -542,9 +557,9 @@ PluginAdapterBase::Impl::vampReleaseOutputDescriptor(VampOutputDescriptor *desc)
VampFeatureList * VampFeatureList *
PluginAdapterBase::Impl::vampProcess(VampPluginHandle handle, PluginAdapterBase::Impl::vampProcess(VampPluginHandle handle,
const float *const *inputBuffers, const float *const *inputBuffers,
int sec, int sec,
int nsec) int nsec)
{ {
#ifdef DEBUG_PLUGIN_ADAPTER #ifdef DEBUG_PLUGIN_ADAPTER
std::cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl; std::cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl;
@ -552,8 +567,7 @@ PluginAdapterBase::Impl::vampProcess(VampPluginHandle handle,
Impl *adapter = lookupAdapter(handle); Impl *adapter = lookupAdapter(handle);
if (!adapter) return 0; if (!adapter) return 0;
return adapter->process((Plugin *)handle, return adapter->process((Plugin *)handle, inputBuffers, sec, nsec);
inputBuffers, sec, nsec);
} }
VampFeatureList * VampFeatureList *
@ -587,11 +601,11 @@ PluginAdapterBase::Impl::cleanup(Plugin *plugin)
VampFeatureList *list = m_fs[plugin]; VampFeatureList *list = m_fs[plugin];
for (unsigned int i = 0; i < outputCount; ++i) { for (unsigned int i = 0; i < outputCount; ++i) {
for (unsigned int j = 0; j < m_fsizes[plugin][i]; ++j) { for (unsigned int j = 0; j < m_fsizes[plugin][i]; ++j) {
if (list[i].features[j].label) { if (list[i].features[j].v1.label) {
free(list[i].features[j].label); free(list[i].features[j].v1.label);
} }
if (list[i].features[j].values) { if (list[i].features[j].v1.values) {
free(list[i].features[j].values); free(list[i].features[j].v1.values);
} }
} }
if (list[i].features) free(list[i].features); if (list[i].features) free(list[i].features);
@ -621,26 +635,46 @@ PluginAdapterBase::Impl::cleanup(Plugin *plugin)
void void
PluginAdapterBase::Impl::checkOutputMap(Plugin *plugin) PluginAdapterBase::Impl::checkOutputMap(Plugin *plugin)
{ {
if (m_pluginOutputs.find(plugin) == m_pluginOutputs.end() || OutputMap::iterator i = m_pluginOutputs.find(plugin);
!m_pluginOutputs[plugin]) {
if (i == m_pluginOutputs.end() || !i->second) {
m_pluginOutputs[plugin] = new Plugin::OutputList m_pluginOutputs[plugin] = new Plugin::OutputList
(plugin->getOutputDescriptors()); (plugin->getOutputDescriptors());
// std::cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << std::endl; // std::cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << std::endl;
} }
} }
void
PluginAdapterBase::Impl::markOutputsChanged(Plugin *plugin)
{
OutputMap::iterator i = m_pluginOutputs.find(plugin);
// std::cerr << "PluginAdapterBase::Impl::markOutputsChanged" << std::endl;
if (i != m_pluginOutputs.end()) {
Plugin::OutputList *list = i->second;
m_pluginOutputs.erase(i);
delete list;
}
}
unsigned int unsigned int
PluginAdapterBase::Impl::getOutputCount(Plugin *plugin) PluginAdapterBase::Impl::getOutputCount(Plugin *plugin)
{ {
checkOutputMap(plugin); checkOutputMap(plugin);
return m_pluginOutputs[plugin]->size(); return m_pluginOutputs[plugin]->size();
} }
VampOutputDescriptor * VampOutputDescriptor *
PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin, PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin,
unsigned int i) unsigned int i)
{ {
checkOutputMap(plugin); checkOutputMap(plugin);
Plugin::OutputDescriptor &od = Plugin::OutputDescriptor &od =
(*m_pluginOutputs[plugin])[i]; (*m_pluginOutputs[plugin])[i];
@ -654,7 +688,12 @@ PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin,
desc->hasFixedBinCount = od.hasFixedBinCount; desc->hasFixedBinCount = od.hasFixedBinCount;
desc->binCount = od.binCount; desc->binCount = od.binCount;
if (od.hasFixedBinCount && od.binCount > 0) { if (od.hasFixedBinCount && od.binCount > 0
// We would like to do "&& !od.binNames.empty()" here -- but we
// can't, because it will crash older versions of the host adapter
// which try to copy the names across whenever the bin count is
// non-zero, regardless of whether they exist or not
) {
desc->binNames = (const char **) desc->binNames = (const char **)
malloc(od.binCount * sizeof(const char *)); malloc(od.binCount * sizeof(const char *));
@ -685,14 +724,15 @@ PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin,
} }
desc->sampleRate = od.sampleRate; desc->sampleRate = od.sampleRate;
desc->hasDuration = od.hasDuration;
return desc; return desc;
} }
VampFeatureList * VampFeatureList *
PluginAdapterBase::Impl::process(Plugin *plugin, PluginAdapterBase::Impl::process(Plugin *plugin,
const float *const *inputBuffers, const float *const *inputBuffers,
int sec, int nsec) int sec, int nsec)
{ {
// std::cerr << "PluginAdapterBase::Impl::process" << std::endl; // std::cerr << "PluginAdapterBase::Impl::process" << std::endl;
RealTime rt(sec, nsec); RealTime rt(sec, nsec);
@ -710,7 +750,7 @@ PluginAdapterBase::Impl::getRemainingFeatures(Plugin *plugin)
VampFeatureList * VampFeatureList *
PluginAdapterBase::Impl::convertFeatures(Plugin *plugin, PluginAdapterBase::Impl::convertFeatures(Plugin *plugin,
const Plugin::FeatureSet &features) const Plugin::FeatureSet &features)
{ {
int lastN = -1; int lastN = -1;
@ -720,6 +760,8 @@ PluginAdapterBase::Impl::convertFeatures(Plugin *plugin,
resizeFS(plugin, outputCount); resizeFS(plugin, outputCount);
VampFeatureList *fs = m_fs[plugin]; VampFeatureList *fs = m_fs[plugin];
// std::cerr << "PluginAdapter(v2)::convertFeatures: NOTE: sizeof(Feature) == " << sizeof(Plugin::Feature) << ", sizeof(VampFeature) == " << sizeof(VampFeature) << ", sizeof(VampFeatureList) == " << sizeof(VampFeatureList) << std::endl;
for (Plugin::FeatureSet::const_iterator fi = features.begin(); for (Plugin::FeatureSet::const_iterator fi = features.begin();
fi != features.end(); ++fi) { fi != features.end(); ++fi) {
@ -748,13 +790,19 @@ PluginAdapterBase::Impl::convertFeatures(Plugin *plugin,
// std::cerr << "PluginAdapterBase::Impl::convertFeatures: j = " << j << std::endl; // std::cerr << "PluginAdapterBase::Impl::convertFeatures: j = " << j << std::endl;
VampFeature *feature = &fs[n].features[j]; VampFeature *feature = &fs[n].features[j].v1;
feature->hasTimestamp = fl[j].hasTimestamp; feature->hasTimestamp = fl[j].hasTimestamp;
feature->sec = fl[j].timestamp.sec; feature->sec = fl[j].timestamp.sec;
feature->nsec = fl[j].timestamp.nsec; feature->nsec = fl[j].timestamp.nsec;
feature->valueCount = fl[j].values.size(); feature->valueCount = fl[j].values.size();
VampFeatureV2 *v2 = &fs[n].features[j + sz].v2;
v2->hasDuration = fl[j].hasDuration;
v2->durationSec = fl[j].duration.sec;
v2->durationNsec = fl[j].duration.nsec;
if (feature->label) free(feature->label); if (feature->label) free(feature->label);
if (fl[j].label.empty()) { if (fl[j].label.empty()) {
@ -784,6 +832,12 @@ PluginAdapterBase::Impl::convertFeatures(Plugin *plugin,
} }
} }
// std::cerr << "PluginAdapter(v2)::convertFeatures: NOTE: have " << outputCount << " outputs" << std::endl;
// for (int i = 0; i < outputCount; ++i) {
// std::cerr << "PluginAdapter(v2)::convertFeatures: NOTE: output " << i << " has " << fs[i].featureCount << " features" << std::endl;
// }
return fs; return fs;
} }
@ -820,13 +874,15 @@ PluginAdapterBase::Impl::resizeFL(Plugin *plugin, int n, size_t sz)
// std::cerr << "resizing from " << i << std::endl; // std::cerr << "resizing from " << i << std::endl;
m_fs[plugin][n].features = (VampFeature *)realloc m_fs[plugin][n].features = (VampFeatureUnion *)realloc
(m_fs[plugin][n].features, sz * sizeof(VampFeature)); (m_fs[plugin][n].features, 2 * sz * sizeof(VampFeatureUnion));
while (m_fsizes[plugin][n] < sz) { while (m_fsizes[plugin][n] < sz) {
m_fs[plugin][n].features[m_fsizes[plugin][n]].valueCount = 0; m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.hasTimestamp = 0;
m_fs[plugin][n].features[m_fsizes[plugin][n]].values = 0; m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.valueCount = 0;
m_fs[plugin][n].features[m_fsizes[plugin][n]].label = 0; m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.values = 0;
m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.label = 0;
m_fs[plugin][n].features[m_fsizes[plugin][n] + sz].v2.hasDuration = 0;
m_fvsizes[plugin][n].push_back(0); m_fvsizes[plugin][n].push_back(0);
m_fsizes[plugin][n]++; m_fsizes[plugin][n]++;
} }
@ -843,8 +899,8 @@ PluginAdapterBase::Impl::resizeFV(Plugin *plugin, int n, int j, size_t sz)
// std::cerr << "resizing from " << i << std::endl; // std::cerr << "resizing from " << i << std::endl;
m_fs[plugin][n].features[j].values = (float *)realloc m_fs[plugin][n].features[j].v1.values = (float *)realloc
(m_fs[plugin][n].features[j].values, sz * sizeof(float)); (m_fs[plugin][n].features[j].v1.values, sz * sizeof(float));
m_fvsizes[plugin][n][j] = sz; m_fvsizes[plugin][n][j] = sz;
} }
@ -854,3 +910,5 @@ PluginAdapterBase::Impl::m_adapterMap = 0;
} }
_VAMP_SDK_PLUGSPACE_END(PluginAdapter.cpp)

View file

@ -53,12 +53,14 @@
using std::cerr; using std::cerr;
using std::endl; using std::endl;
#include "RealTime.h"
#ifndef _WIN32 #ifndef _WIN32
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <vamp-sdk/RealTime.h>
_VAMP_SDK_PLUGSPACE_BEGIN(RealTime.cpp)
namespace Vamp { namespace Vamp {
// A RealTime consists of two ints that must be at least 32 bits each. // A RealTime consists of two ints that must be at least 32 bits each.
@ -224,17 +226,8 @@ long
RealTime::realTime2Frame(const RealTime &time, unsigned int sampleRate) RealTime::realTime2Frame(const RealTime &time, unsigned int sampleRate)
{ {
if (time < zeroTime) return -realTime2Frame(-time, sampleRate); if (time < zeroTime) return -realTime2Frame(-time, sampleRate);
double s = time.sec + double(time.nsec + 1) / 1000000000.0;
// We like integers. The last term is always zero unless the return long(s * sampleRate);
// sample rate is greater than 1MHz, but hell, you never know...
long frame =
time.sec * sampleRate +
(time.msec() * sampleRate) / 1000 +
((time.usec() - 1000 * time.msec()) * sampleRate) / 1000000 +
((time.nsec - 1000 * time.usec()) * sampleRate) / 1000000000;
return frame;
} }
RealTime RealTime
@ -245,10 +238,15 @@ RealTime::frame2RealTime(long frame, unsigned int sampleRate)
RealTime rt; RealTime rt;
rt.sec = frame / long(sampleRate); rt.sec = frame / long(sampleRate);
frame -= rt.sec * long(sampleRate); frame -= rt.sec * long(sampleRate);
rt.nsec = (int)(((float(frame) * 1000000) / long(sampleRate)) * 1000); rt.nsec = (int)(((double(frame) * 1000000.0) / sampleRate) * 1000.0);
return rt; return rt;
} }
const RealTime RealTime::zeroTime(0,0); const RealTime RealTime::zeroTime(0,0);
} }
_VAMP_SDK_PLUGSPACE_END(RealTime.cpp)

View file

@ -0,0 +1,47 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_HOSTSDK_PLUGIN_H_
#define _VAMP_HOSTSDK_PLUGIN_H_
// Do not include vamp-sdk/Plugin.h directly from host code. Always
// use this header instead.
#include "hostguard.h"
#include <vamp-sdk/Plugin.h>
#endif

View file

@ -0,0 +1,47 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_HOSTSDK_PLUGIN_BASE_H_
#define _VAMP_HOSTSDK_PLUGIN_BASE_H_
// Do not include vamp-sdk/PluginBase.h directly from host code.
// Always use this header instead.
#include "hostguard.h"
#include <vamp-sdk/PluginBase.h>
#endif

View file

@ -0,0 +1,194 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006-2007 Chris Cannam and QMUL.
This file by Mark Levy and Chris Cannam, Copyright 2007-2008 QMUL.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_PLUGIN_BUFFERING_ADAPTER_H_
#define _VAMP_PLUGIN_BUFFERING_ADAPTER_H_
#include "hostguard.h"
#include "PluginWrapper.h"
_VAMP_SDK_HOSTSPACE_BEGIN(PluginBufferingAdapter.h)
namespace Vamp {
namespace HostExt {
/**
* \class PluginBufferingAdapter PluginBufferingAdapter.h <vamp-hostsdk/PluginBufferingAdapter.h>
*
* PluginBufferingAdapter is a Vamp plugin adapter that allows plugins
* to be used by a host supplying an audio stream in non-overlapping
* buffers of arbitrary size.
*
* A host using PluginBufferingAdapter may ignore the preferred step
* and block size reported by the plugin, and still expect the plugin
* to run. The value of blockSize and stepSize passed to initialise
* should be the size of the buffer which the host will supply; the
* stepSize should be equal to the blockSize.
*
* If the internal step size used for the plugin differs from that
* supplied by the host, the adapter will modify the sample type and
* rate specifications for the plugin outputs appropriately, and set
* timestamps on the output features for outputs that formerly used a
* different sample rate specification. This is necessary in order to
* obtain correct time stamping.
*
* In other respects, the PluginBufferingAdapter behaves identically
* to the plugin that it wraps. The wrapped plugin will be deleted
* when the wrapper is deleted.
*/
class PluginBufferingAdapter : public PluginWrapper
{
public:
/**
* Construct a PluginBufferingAdapter wrapping the given plugin.
* The adapter takes ownership of the plugin, which will be
* deleted when the adapter is deleted.
*/
PluginBufferingAdapter(Plugin *plugin);
virtual ~PluginBufferingAdapter();
/**
* Return the preferred step size for this adapter.
*
* Because of the way this adapter works, its preferred step size
* will always be the same as its preferred block size. This may
* or may not be the same as the preferred step size of the
* underlying plugin, which may be obtained by calling
* getPluginPreferredStepSize().
*/
size_t getPreferredStepSize() const;
/**
* Return the preferred block size for this adapter.
*
* This may or may not be the same as the preferred block size of
* the underlying plugin, which may be obtained by calling
* getPluginPreferredBlockSize().
*
* Note that this adapter may be initialised with any block size,
* not just its supposedly preferred one.
*/
size_t getPreferredBlockSize() const;
/**
* Initialise the adapter (and therefore the plugin) for the given
* number of channels. Initialise the adapter for the given step
* and block size, which must be equal.
*
* The step and block size used for the underlying plugin will
* depend on its preferences, or any values previously passed to
* setPluginStepSize and setPluginBlockSize.
*/
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
/**
* Return the preferred step size of the plugin wrapped by this
* adapter.
*
* This is included mainly for informational purposes. This value
* is not likely to be a valid step size for the adapter itself,
* and it is not usually of any use in interpreting the results
* (because the adapter re-writes OneSamplePerStep outputs to
* FixedSampleRate so that the hop size no longer needs to be
* known beforehand in order to interpret them).
*/
size_t getPluginPreferredStepSize() const;
/**
* Return the preferred block size of the plugin wrapped by this
* adapter.
*
* This is included mainly for informational purposes.
*/
size_t getPluginPreferredBlockSize() const;
/**
* Set the step size that will be used for the underlying plugin
* when initialise() is called. If this is not set, the plugin's
* own preferred step size will be used. You will not usually
* need to call this function. If you do call it, it must be
* before the first call to initialise().
*/
void setPluginStepSize(size_t stepSize);
/**
* Set the block size that will be used for the underlying plugin
* when initialise() is called. If this is not set, the plugin's
* own preferred block size will be used. You will not usually
* need to call this function. If you do call it, it must be
* before the first call to initialise().
*/
void setPluginBlockSize(size_t blockSize);
/**
* Return the step and block sizes that were actually used when
* initialising the underlying plugin.
*
* This is included mainly for informational purposes. You will
* not usually need to call this function. If this is called
* before initialise(), it will return 0 for both values. If it
* is called after a failed call to initialise(), it will return
* the values that were used in the failed call to the plugin's
* initialise() function.
*/
void getActualStepAndBlockSizes(size_t &stepSize, size_t &blockSize);
void setParameter(std::string, float);
void selectProgram(std::string);
OutputList getOutputDescriptors() const;
void reset();
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet getRemainingFeatures();
protected:
class Impl;
Impl *m_impl;
};
}
}
_VAMP_SDK_HOSTSPACE_END(PluginBufferingAdapter.h)
#endif

View file

@ -37,14 +37,17 @@
#ifndef _VAMP_PLUGIN_CHANNEL_ADAPTER_H_ #ifndef _VAMP_PLUGIN_CHANNEL_ADAPTER_H_
#define _VAMP_PLUGIN_CHANNEL_ADAPTER_H_ #define _VAMP_PLUGIN_CHANNEL_ADAPTER_H_
#include "hostguard.h"
#include "PluginWrapper.h" #include "PluginWrapper.h"
_VAMP_SDK_HOSTSPACE_BEGIN(PluginChannelAdapter.h)
namespace Vamp { namespace Vamp {
namespace HostExt { namespace HostExt {
/** /**
* \class PluginChannelAdapter PluginChannelAdapter.h <vamp-sdk/hostext/PluginChannelAdapter.h> * \class PluginChannelAdapter PluginChannelAdapter.h <vamp-hostsdk/PluginChannelAdapter.h>
* *
* PluginChannelAdapter is a Vamp plugin adapter that implements a * PluginChannelAdapter is a Vamp plugin adapter that implements a
* policy for management of plugins that expect a different number of * policy for management of plugins that expect a different number of
@ -109,13 +112,29 @@ namespace HostExt {
class PluginChannelAdapter : public PluginWrapper class PluginChannelAdapter : public PluginWrapper
{ {
public: public:
PluginChannelAdapter(Plugin *plugin); // I take ownership of plugin /**
* Construct a PluginChannelAdapter wrapping the given plugin.
* The adapter takes ownership of the plugin, which will be
* deleted when the adapter is deleted.
*/
PluginChannelAdapter(Plugin *plugin);
virtual ~PluginChannelAdapter(); virtual ~PluginChannelAdapter();
bool initialise(size_t channels, size_t stepSize, size_t blockSize); bool initialise(size_t channels, size_t stepSize, size_t blockSize);
FeatureSet process(const float *const *inputBuffers, RealTime timestamp); FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
/**
* Call process(), providing interleaved audio data with the
* number of channels passed to initialise(). The adapter will
* de-interleave into temporary buffers as appropriate before
* calling process().
*
* \note This function was introduced in version 1.4 of the Vamp
* plugin SDK.
*/
FeatureSet processInterleaved(const float *inputBuffer, RealTime timestamp);
protected: protected:
class Impl; class Impl;
Impl *m_impl; Impl *m_impl;
@ -125,4 +144,6 @@ protected:
} }
_VAMP_SDK_HOSTSPACE_END(PluginChannelAdapter.h)
#endif #endif

View file

@ -37,15 +37,19 @@
#ifndef _VAMP_PLUGIN_HOST_ADAPTER_H_ #ifndef _VAMP_PLUGIN_HOST_ADAPTER_H_
#define _VAMP_PLUGIN_HOST_ADAPTER_H_ #define _VAMP_PLUGIN_HOST_ADAPTER_H_
#include "hostguard.h"
#include "Plugin.h"
#include <vamp/vamp.h> #include <vamp/vamp.h>
#include <vamp-sdk/Plugin.h>
#include <vector> #include <vector>
_VAMP_SDK_HOSTSPACE_BEGIN(PluginHostAdapter.h)
namespace Vamp { namespace Vamp {
/** /**
* \class PluginHostAdapter PluginHostAdapter.h <vamp-sdk/PluginHostAdapter.h> * \class PluginHostAdapter PluginHostAdapter.h <vamp-hostsdk/PluginHostAdapter.h>
* *
* PluginHostAdapter is a wrapper class that a Vamp host can use to * PluginHostAdapter is a wrapper class that a Vamp host can use to
* make the C-language VampPluginDescriptor object appear as a C++ * make the C-language VampPluginDescriptor object appear as a C++
@ -112,6 +116,8 @@ protected:
} }
_VAMP_SDK_HOSTSPACE_END(PluginHostAdapter.h)
#endif #endif

View file

@ -37,14 +37,17 @@
#ifndef _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_ #ifndef _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_
#define _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_ #define _VAMP_PLUGIN_INPUT_DOMAIN_ADAPTER_H_
#include "hostguard.h"
#include "PluginWrapper.h" #include "PluginWrapper.h"
_VAMP_SDK_HOSTSPACE_BEGIN(PluginInputDomainAdapter.h)
namespace Vamp { namespace Vamp {
namespace HostExt { namespace HostExt {
/** /**
* \class PluginInputDomainAdapter PluginInputDomainAdapter.h <vamp-sdk/hostext/PluginInputDomainAdapter.h> * \class PluginInputDomainAdapter PluginInputDomainAdapter.h <vamp-hostsdk/PluginInputDomainAdapter.h>
* *
* PluginInputDomainAdapter is a Vamp plugin adapter that converts * PluginInputDomainAdapter is a Vamp plugin adapter that converts
* time-domain input into frequency-domain input for plugins that need * time-domain input into frequency-domain input for plugins that need
@ -79,7 +82,12 @@ namespace HostExt {
class PluginInputDomainAdapter : public PluginWrapper class PluginInputDomainAdapter : public PluginWrapper
{ {
public: public:
PluginInputDomainAdapter(Plugin *plugin); // I take ownership of plugin /**
* Construct a PluginInputDomainAdapter wrapping the given plugin.
* The adapter takes ownership of the plugin, which will be
* deleted when the adapter is deleted.
*/
PluginInputDomainAdapter(Plugin *plugin);
virtual ~PluginInputDomainAdapter(); virtual ~PluginInputDomainAdapter();
bool initialise(size_t channels, size_t stepSize, size_t blockSize); bool initialise(size_t channels, size_t stepSize, size_t blockSize);
@ -91,6 +99,29 @@ public:
FeatureSet process(const float *const *inputBuffers, RealTime timestamp); FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
/**
* Return the amount by which the timestamps supplied to process()
* are being incremented when they are passed to the plugin's own
* process() implementation.
*
* The Vamp API mandates that the timestamp passed to the plugin
* for time-domain input should be the time of the first sample in
* the block, but the timestamp passed for frequency-domain input
* should be the timestamp of the centre of the block.
*
* The PluginInputDomainAdapter adjusts its timestamps properly so
* that the plugin receives correct times, but in some
* circumstances (such as for establishing the correct timing of
* implicitly-timed features, i.e. features without their own
* timestamps) the host may need to be aware that this adjustment
* is taking place.
*
* If the plugin requires time-domain input, this function will
* return zero. The result of calling this function before
* initialise() has been called is undefined.
*/
RealTime getTimestampAdjustment() const;
protected: protected:
class Impl; class Impl;
Impl *m_impl; Impl *m_impl;
@ -100,4 +131,6 @@ protected:
} }
_VAMP_SDK_HOSTSPACE_END(PluginInputDomainAdapter.h)
#endif #endif

View file

@ -41,8 +41,11 @@
#include <string> #include <string>
#include <map> #include <map>
#include "hostguard.h"
#include "PluginWrapper.h" #include "PluginWrapper.h"
_VAMP_SDK_HOSTSPACE_BEGIN(PluginLoader.h)
namespace Vamp { namespace Vamp {
class Plugin; class Plugin;
@ -50,7 +53,7 @@ class Plugin;
namespace HostExt { namespace HostExt {
/** /**
* \class PluginLoader PluginLoader.h <vamp-sdk/hostext/PluginLoader.h> * \class PluginLoader PluginLoader.h <vamp-hostsdk/PluginLoader.h>
* *
* Vamp::HostExt::PluginLoader is a convenience class for discovering * Vamp::HostExt::PluginLoader is a convenience class for discovering
* and loading Vamp plugins using the typical plugin-path, library * and loading Vamp plugins using the typical plugin-path, library
@ -234,5 +237,7 @@ protected:
} }
_VAMP_SDK_HOSTSPACE_END(PluginLoader.h)
#endif #endif

View file

@ -0,0 +1,197 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006-2008 Chris Cannam and QMUL.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_PLUGIN_SUMMARISING_ADAPTER_H_
#define _VAMP_PLUGIN_SUMMARISING_ADAPTER_H_
#include "hostguard.h"
#include "PluginWrapper.h"
#include <set>
_VAMP_SDK_HOSTSPACE_BEGIN(PluginSummarisingAdapter.h)
namespace Vamp {
namespace HostExt {
/**
* \class PluginSummarisingAdapter PluginSummarisingAdapter.h <vamp-hostsdk/PluginSummarisingAdapter.h>
*
* PluginSummarisingAdapter is a Vamp plugin adapter that provides
* summarisation methods such as mean and median averages of output
* features, for use in any context where an available plugin produces
* individual values but the result that is actually needed is some
* sort of aggregate.
*
* To make use of PluginSummarisingAdapter, the host should configure,
* initialise and run the plugin through the adapter interface just as
* normal. Then, after the process and getRemainingFeatures methods
* have been properly called and processing is complete, the host may
* call getSummaryForOutput or getSummaryForAllOutputs to obtain
* summarised features: averages, maximum values, etc, depending on
* the SummaryType passed to the function.
*
* By default PluginSummarisingAdapter calculates a single summary of
* each output's feature across the whole duration of processed audio.
* A host needing summaries of sub-segments of the whole audio may
* call setSummarySegmentBoundaries before retrieving the summaries,
* providing a list of times such that one summary will be provided
* for each segment between two consecutive times.
*
* PluginSummarisingAdapter is straightforward rather than fast. It
* calculates all of the summary types for all outputs always, and
* then returns only the ones that are requested. It is designed on
* the basis that, for most features, summarising and storing
* summarised results is far cheaper than calculating the results in
* the first place. If this is not true for your particular feature,
* PluginSummarisingAdapter may not be the best approach for you.
*
* \note This class was introduced in version 2.0 of the Vamp plugin SDK.
*/
class PluginSummarisingAdapter : public PluginWrapper
{
public:
/**
* Construct a PluginSummarisingAdapter wrapping the given plugin.
* The adapter takes ownership of the plugin, which will be
* deleted when the adapter is deleted.
*/
PluginSummarisingAdapter(Plugin *plugin);
virtual ~PluginSummarisingAdapter();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet getRemainingFeatures();
typedef std::set<RealTime> SegmentBoundaries;
/**
* Specify a series of segment boundaries, such that one summary
* will be returned for each of the contiguous intra-boundary
* segments. This function must be called before
* getSummaryForOutput or getSummaryForAllOutputs.
*
* Note that you cannot retrieve results with multiple different
* segmentations by repeatedly calling this function followed by
* one of the getSummary functions. The summaries are all
* calculated at the first call to any getSummary function, and
* once the summaries have been calculated, they remain
* calculated.
*/
void setSummarySegmentBoundaries(const SegmentBoundaries &);
enum SummaryType {
Minimum = 0,
Maximum = 1,
Mean = 2,
Median = 3,
Mode = 4,
Sum = 5,
Variance = 6,
StandardDeviation = 7,
Count = 8,
UnknownSummaryType = 999
};
/**
* AveragingMethod indicates how the adapter should handle
* average-based summaries of features whose results are not
* equally spaced in time.
*
* If SampleAverage is specified, summary types based on averages
* will be calculated by treating each result individually without
* regard to its time: for example, the mean will be the sum of
* all values divided by the number of values.
*
* If ContinuousTimeAverage is specified, each feature will be
* considered to have a duration, either as specified in the
* feature's duration field, or until the following feature: thus,
* for example, the mean will be the sum of the products of values
* and durations, divided by the total duration.
*
* Although SampleAverage is useful for many types of feature,
* ContinuousTimeAverage is essential for some situations, for
* example finding the result that spans the largest proportion of
* the input given a feature that emits a new result only when the
* value changes (the modal value integrated over time).
*/
enum AveragingMethod {
SampleAverage = 0,
ContinuousTimeAverage = 1,
};
/**
* Return summaries of the features that were returned on the
* given output, using the given SummaryType and AveragingMethod.
*
* The plugin must have been fully run (process() and
* getRemainingFeatures() calls all made as appropriate) before
* this function is called.
*/
FeatureList getSummaryForOutput(int output,
SummaryType type,
AveragingMethod method = SampleAverage);
/**
* Return summaries of the features that were returned on all of
* the plugin's outputs, using the given SummaryType and
* AveragingMethod.
*
* The plugin must have been fully run (process() and
* getRemainingFeatures() calls all made as appropriate) before
* this function is called.
*/
FeatureSet getSummaryForAllOutputs(SummaryType type,
AveragingMethod method = SampleAverage);
protected:
class Impl;
Impl *m_impl;
};
}
}
_VAMP_SDK_HOSTSPACE_END(PluginSummarisingAdapter.h)
#endif

View file

@ -37,14 +37,17 @@
#ifndef _VAMP_PLUGIN_WRAPPER_H_ #ifndef _VAMP_PLUGIN_WRAPPER_H_
#define _VAMP_PLUGIN_WRAPPER_H_ #define _VAMP_PLUGIN_WRAPPER_H_
#include <vamp-sdk/Plugin.h> #include "hostguard.h"
#include <vamp-hostsdk/Plugin.h>
_VAMP_SDK_HOSTSPACE_BEGIN(PluginWrapper.h)
namespace Vamp { namespace Vamp {
namespace HostExt { namespace HostExt {
/** /**
* \class PluginWrapper PluginWrapper.h <vamp-sdk/hostext/PluginWrapper.h> * \class PluginWrapper PluginWrapper.h <vamp-hostsdk/PluginWrapper.h>
* *
* PluginWrapper is a simple base class for adapter plugins. It takes * PluginWrapper is a simple base class for adapter plugins. It takes
* a pointer to a "to be wrapped" Vamp plugin on construction, and * a pointer to a "to be wrapped" Vamp plugin on construction, and
@ -94,6 +97,30 @@ public:
FeatureSet getRemainingFeatures(); FeatureSet getRemainingFeatures();
/**
* Return a pointer to the plugin wrapper of type WrapperType
* surrounding this wrapper's plugin, if present.
*
* This is useful in situations where a plugin is wrapped by
* multiple different wrappers (one inside another) and the host
* wants to call some wrapper-specific function on one of the
* layers without having to care about the order in which they are
* wrapped. For example, the plugin returned by
* PluginLoader::loadPlugin may have more than one wrapper; if the
* host wanted to query or fine-tune some property of one of them,
* it would be hard to do so without knowing the order of the
* wrappers. This function therefore gives direct access to the
* wrapper of a particular type.
*/
template <typename WrapperType>
WrapperType *getWrapper() {
WrapperType *w = dynamic_cast<WrapperType *>(this);
if (w) return w;
PluginWrapper *pw = dynamic_cast<PluginWrapper *>(m_plugin);
if (pw) return pw->getWrapper<WrapperType>();
return 0;
}
protected: protected:
PluginWrapper(Plugin *plugin); // I take ownership of plugin PluginWrapper(Plugin *plugin); // I take ownership of plugin
Plugin *m_plugin; Plugin *m_plugin;
@ -103,4 +130,6 @@ protected:
} }
_VAMP_SDK_HOSTSPACE_END(PluginWrapper.h)
#endif #endif

View file

@ -0,0 +1,46 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_HOSTSDK_REALTIME_H_
#define _VAMP_HOSTSDK_REALTIME_H_
// Do not include vamp-sdk/RealTime.h directly from host code. Always
// use this header instead.
#include "hostguard.h"
#include <vamp-sdk/RealTime.h>
#endif

View file

@ -0,0 +1,69 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_HOSTSDK_HOSTGUARD_H_
#define _VAMP_HOSTSDK_HOSTGUARD_H_
#ifdef _VAMP_IN_PLUGINSDK
#error You have included headers from both vamp-sdk and vamp-hostsdk in the same source file. Please include only vamp-sdk headers in plugin code, and only vamp-hostsdk headers in host code.
#else
#define _VAMP_IN_HOSTSDK
#ifdef _VAMP_NO_HOST_NAMESPACE
#define _VAMP_SDK_HOSTSPACE_BEGIN(h)
#define _VAMP_SDK_HOSTSPACE_END(h)
#define _VAMP_SDK_PLUGSPACE_BEGIN(h)
#define _VAMP_SDK_PLUGSPACE_END(h)
#else
#define _VAMP_SDK_HOSTSPACE_BEGIN(h) \
namespace _VampHost {
#define _VAMP_SDK_HOSTSPACE_END(h) \
} \
using namespace _VampHost;
#define _VAMP_SDK_PLUGSPACE_BEGIN(h) \
namespace _VampHost {
#define _VAMP_SDK_PLUGSPACE_END(h) \
} \
using namespace _VampHost;
#endif
#endif
#endif

View file

@ -0,0 +1,53 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_HOSTSDK_SINGLE_INCLUDE_H_
#define _VAMP_HOSTSDK_SINGLE_INCLUDE_H_
#include "PluginBase.h"
#include "PluginBufferingAdapter.h"
#include "PluginChannelAdapter.h"
#include "Plugin.h"
#include "PluginHostAdapter.h"
#include "PluginInputDomainAdapter.h"
#include "PluginLoader.h"
#include "PluginSummarisingAdapter.h"
#include "PluginWrapper.h"
#include "RealTime.h"
#endif

View file

@ -34,16 +34,19 @@
authorization. authorization.
*/ */
#ifndef _VAMP_PLUGIN_H_ #ifndef _VAMP_SDK_PLUGIN_H_
#define _VAMP_PLUGIN_H_ #define _VAMP_SDK_PLUGIN_H_
#include "PluginBase.h"
#include "RealTime.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include "PluginBase.h"
#include "RealTime.h"
#include "plugguard.h"
_VAMP_SDK_PLUGSPACE_BEGIN(Plugin.h)
namespace Vamp { namespace Vamp {
/** /**
@ -200,7 +203,7 @@ public:
/** /**
* The name of the output, in computer-usable form. Should be * The name of the output, in computer-usable form. Should be
* reasonably short and without whitespace or punctuation, using * reasonably short and without whitespace or punctuation, using
* the characters [a-zA-Z0-9_] only. * the characters [a-zA-Z0-9_-] only.
* Example: "zero_crossing_count" * Example: "zero_crossing_count"
*/ */
std::string identifier; std::string identifier;
@ -304,6 +307,16 @@ public:
* this to zero if that behaviour is not desired. * this to zero if that behaviour is not desired.
*/ */
float sampleRate; float sampleRate;
/**
* True if the returned results for this output are known to
* have a duration field.
*/
bool hasDuration;
OutputDescriptor() : // defaults for mandatory non-class-type members
hasFixedBinCount(false), hasKnownExtents(false), isQuantized(false),
sampleType(OneSamplePerStep), hasDuration(false) { }
}; };
typedef std::vector<OutputDescriptor> OutputList; typedef std::vector<OutputDescriptor> OutputList;
@ -319,17 +332,34 @@ public:
{ {
/** /**
* True if an output feature has its own timestamp. This is * True if an output feature has its own timestamp. This is
* mandatory if the output has VariableSampleRate, and is * mandatory if the output has VariableSampleRate, optional if
* likely to be disregarded otherwise. * the output has FixedSampleRate, and unused if the output
* has OneSamplePerStep.
*/ */
bool hasTimestamp; bool hasTimestamp;
/** /**
* Timestamp of the output feature. This is mandatory if the * Timestamp of the output feature. This is mandatory if the
* output has VariableSampleRate, and is likely to be * output has VariableSampleRate or if the output has
* disregarded otherwise. Undefined if hasTimestamp is false. * FixedSampleRate and hasTimestamp is true, and unused
* otherwise.
*/ */
RealTime timestamp; RealTime timestamp;
/**
* True if an output feature has a specified duration. This
* is optional if the output has VariableSampleRate or
* FixedSampleRate, and and unused if the output has
* OneSamplePerStep.
*/
bool hasDuration;
/**
* Duration of the output feature. This is mandatory if the
* output has VariableSampleRate or FixedSampleRate and
* hasDuration is true, and unused otherwise.
*/
RealTime duration;
/** /**
* Results for a single sample of this feature. If the output * Results for a single sample of this feature. If the output
@ -342,9 +372,13 @@ public:
* Label for the sample of this feature. * Label for the sample of this feature.
*/ */
std::string label; std::string label;
Feature() : // defaults for mandatory non-class-type members
hasTimestamp(false), hasDuration(false) { }
}; };
typedef std::vector<Feature> FeatureList; typedef std::vector<Feature> FeatureList;
typedef std::map<int, FeatureList> FeatureSet; // key is output no typedef std::map<int, FeatureList> FeatureSet; // key is output no
/** /**
@ -353,9 +387,9 @@ public:
* If the plugin's inputDomain is TimeDomain, inputBuffers will * If the plugin's inputDomain is TimeDomain, inputBuffers will
* point to one array of floats per input channel, and each of * point to one array of floats per input channel, and each of
* these arrays will contain blockSize consecutive audio samples * these arrays will contain blockSize consecutive audio samples
* (the host will zero-pad as necessary). The timestamp will be * (the host will zero-pad as necessary). The timestamp in this
* the real time in seconds of the start of the supplied block of * case will be the real time in seconds of the start of the
* samples. * supplied block of samples.
* *
* If the plugin's inputDomain is FrequencyDomain, inputBuffers * If the plugin's inputDomain is FrequencyDomain, inputBuffers
* will point to one array of floats per input channel, and each * will point to one array of floats per input channel, and each
@ -399,6 +433,8 @@ protected:
} }
_VAMP_SDK_PLUGSPACE_END(Plugin.h)
#endif #endif

View file

@ -37,11 +37,13 @@
#ifndef _VAMP_PLUGIN_ADAPTER_H_ #ifndef _VAMP_PLUGIN_ADAPTER_H_
#define _VAMP_PLUGIN_ADAPTER_H_ #define _VAMP_PLUGIN_ADAPTER_H_
#include <map>
#include <vamp/vamp.h> #include <vamp/vamp.h>
#include "Plugin.h" #include "Plugin.h"
#include <map> #include "plugguard.h"
_VAMP_SDK_PLUGSPACE_BEGIN(PluginAdapter.h)
namespace Vamp { namespace Vamp {
@ -113,5 +115,7 @@ protected:
} }
_VAMP_SDK_PLUGSPACE_END(PluginAdapter.h)
#endif #endif

View file

@ -34,13 +34,18 @@
authorization. authorization.
*/ */
#ifndef _VAMP_PLUGIN_BASE_H_ #ifndef _VAMP_SDK_PLUGIN_BASE_H_
#define _VAMP_PLUGIN_BASE_H_ #define _VAMP_SDK_PLUGIN_BASE_H_
#include <string> #include <string>
#include <vector> #include <vector>
#define VAMP_SDK_VERSION "1.1" #define VAMP_SDK_VERSION "2.0"
#define VAMP_SDK_MAJOR_VERSION 2
#define VAMP_SDK_MINOR_VERSION 0
#include "plugguard.h"
_VAMP_SDK_PLUGSPACE_BEGIN(PluginBase.h)
namespace Vamp { namespace Vamp {
@ -64,12 +69,12 @@ public:
/** /**
* Get the Vamp API compatibility level of the plugin. * Get the Vamp API compatibility level of the plugin.
*/ */
virtual unsigned int getVampApiVersion() const { return 1; } virtual unsigned int getVampApiVersion() const { return 2; }
/** /**
* Get the computer-usable name of the plugin. This should be * Get the computer-usable name of the plugin. This should be
* reasonably short and contain no whitespace or punctuation * reasonably short and contain no whitespace or punctuation
* characters. It may only contain the characters [a-zA-Z0-9_]. * characters. It may only contain the characters [a-zA-Z0-9_-].
* This is the authoritative way for a program to identify a * This is the authoritative way for a program to identify a
* plugin within a given library. * plugin within a given library.
* *
@ -127,7 +132,7 @@ public:
/** /**
* The name of the parameter, in computer-usable form. Should * The name of the parameter, in computer-usable form. Should
* be reasonably short, and may only contain the characters * be reasonably short, and may only contain the characters
* [a-zA-Z0-9_]. * [a-zA-Z0-9_-].
*/ */
std::string identifier; std::string identifier;
@ -190,6 +195,9 @@ public:
* encoded in the names. * encoded in the names.
*/ */
std::vector<std::string> valueNames; std::vector<std::string> valueNames;
ParameterDescriptor() : // the defaults are invalid: you must set them
minValue(0), maxValue(0), defaultValue(0), isQuantized(false) { }
}; };
typedef std::vector<ParameterDescriptor> ParameterList; typedef std::vector<ParameterDescriptor> ParameterList;
@ -249,4 +257,6 @@ public:
} }
_VAMP_SDK_PLUGSPACE_END(PluginBase.h)
#endif #endif

View file

@ -51,6 +51,9 @@
struct timeval; struct timeval;
#endif #endif
#include "plugguard.h"
_VAMP_SDK_PLUGSPACE_BEGIN(RealTime.h)
namespace Vamp { namespace Vamp {
/** /**
@ -158,5 +161,7 @@ struct RealTime
std::ostream &operator<<(std::ostream &out, const RealTime &rt); std::ostream &operator<<(std::ostream &out, const RealTime &rt);
} }
_VAMP_SDK_PLUGSPACE_END(RealTime.h)
#endif #endif

View file

@ -1,99 +0,0 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006-2007 Chris Cannam and QMUL.
This file by Mark Levy, Copyright 2007 QMUL.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_PLUGIN_BUFFERING_ADAPTER_H_
#define _VAMP_PLUGIN_BUFFERING_ADAPTER_H_
#include "PluginWrapper.h"
namespace Vamp {
namespace HostExt {
/**
* \class PluginBufferingAdapter PluginBufferingAdapter.h <vamp-sdk/hostext/PluginBufferingAdapter.h>
*
* PluginBufferingAdapter is a Vamp plugin adapter that allows plugins
* to be used by a host supplying an audio stream in non-overlapping
* buffers of arbitrary size.
*
* A host using PluginBufferingAdapter may ignore the preferred step
* and block size reported by the plugin, and still expect the plugin
* to run. The value of blockSize and stepSize passed to initialise
* should be the size of the buffer which the host will supply; the
* stepSize should be equal to the blockSize.
*
* If the internal step size used for the plugin differs from that
* supplied by the host, the adapter will modify the sample rate
* specifications for the plugin outputs (setting them all to
* VariableSampleRate) and set timestamps on the output features for
* outputs that formerly used a different sample rate specification.
* This is necessary in order to obtain correct time stamping.
*
* In other respects, the PluginBufferingAdapter behaves identically
* to the plugin that it wraps. The wrapped plugin will be deleted
* when the wrapper is deleted.
*/
class PluginBufferingAdapter : public PluginWrapper
{
public:
PluginBufferingAdapter(Plugin *plugin); // I take ownership of plugin
virtual ~PluginBufferingAdapter();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
size_t getPreferredStepSize() const;
OutputList getOutputDescriptors() const;
void reset();
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet getRemainingFeatures();
protected:
class Impl;
Impl *m_impl;
};
}
}
#endif

View file

@ -1,9 +0,0 @@
dlname='%LINK_ABI%'
library_names='%LIBNAME% %LINK_ABI% %LINK_DEV%'
old_library='%STATIC%'
dependency_libs=''
current=2
age=0
revision=0
installed=yes
libdir='%LIBS%'

View file

@ -1,9 +0,0 @@
dlname='%LINK_ABI%'
library_names='%LIBNAME% %LINK_ABI% %LINK_DEV%'
old_library='%STATIC%'
dependency_libs=''
current=1
age=1
revision=0
installed=yes
libdir='%LIBS%'

View file

@ -0,0 +1,98 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_SDK_PLUGGUARD_H_
#define _VAMP_SDK_PLUGGUARD_H_
/**
* Normal usage should be:
*
* - Plugins include vamp-sdk/Plugin.h or vamp-sdk/PluginBase.h.
* These files include this header, which specifies an appropriate
* namespace for the plugin classes to avoid any risk of conflict
* with non-plugin class implementations in the host on load.
*
* - Hosts include vamp-hostsdk/Plugin.h, vamp-hostsdk/PluginBase.h,
* vamp-hostsdk/PluginHostAdapter, vamp-hostsdk/PluginLoader.h etc.
* These files include vamp-hostsdk/hostguard.h, which makes a note
* that we are in a host. A file such as vamp-hostsdk/Plugin.h
* then simply includes vamp-sdk/Plugin.h, and this guard header
* takes notice of the fact that it has been included from a host
* and leaves the plugin namespace unset.
*
* Problems will occur when a host includes files directly from the
* vamp-sdk directory. There are two reasons this might happen:
* mistake, perhaps owing to ignorance of the fact that this isn't
* allowed (particularly since it was the normal mechanism in v1 of
* the SDK); and a wish to incorporate plugin code directly into the
* host rather than having to load it.
*
* What if the host does include a vamp-sdk header by mistake? We can
* catch it if it's included before something from vamp-hostsdk. If
* it's included after something from vamp-hostsdk, it will work OK
* anyway. The remaining problem case is where nothing from
* vamp-hostsdk is included in the same file. We can't catch that.
*/
#ifndef _VAMP_IN_HOSTSDK
#define _VAMP_IN_PLUGINSDK 1
#ifdef _VAMP_NO_PLUGIN_NAMESPACE
#define _VAMP_SDK_PLUGSPACE_BEGIN(h)
#define _VAMP_SDK_PLUGSPACE_END(h)
#else
#ifdef _VAMP_PLUGIN_IN_HOST_NAMESPACE
#define _VAMP_SDK_PLUGSPACE_BEGIN(h) \
namespace _VampHost {
#define _VAMP_SDK_PLUGSPACE_END(h) \
} \
using namespace _VampHost;
#else
#define _VAMP_SDK_PLUGSPACE_BEGIN(h) \
namespace _VampPlugin {
#define _VAMP_SDK_PLUGSPACE_END(h) \
} \
using namespace _VampPlugin;
#endif
#endif
#endif
#endif

View file

@ -0,0 +1,46 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp
An API for audio analysis and feature extraction plugins.
Centre for Digital Music, Queen Mary, University of London.
Copyright 2006 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music; Queen Mary, University of London; and Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _VAMP_SDK_SINGLE_INCLUDE_H_
#define _VAMP_SDK_SINGLE_INCLUDE_H_
#include "PluginBase.h"
#include "Plugin.h"
#include "RealTime.h"
#endif

View file

@ -50,7 +50,7 @@ extern "C" {
* See also the vampApiVersion field in the plugin descriptor, and the * See also the vampApiVersion field in the plugin descriptor, and the
* hostApiVersion argument to the vampGetPluginDescriptor function. * hostApiVersion argument to the vampGetPluginDescriptor function.
*/ */
#define VAMP_API_VERSION 1 #define VAMP_API_VERSION 2
/** /**
* C language API for Vamp plugins. * C language API for Vamp plugins.
@ -160,6 +160,15 @@ typedef struct _VampOutputDescriptor
"Resolution" of result, if sampleType is vampVariableSampleRate. */ "Resolution" of result, if sampleType is vampVariableSampleRate. */
float sampleRate; float sampleRate;
/** 1 if the returned results for this output are known to have a
duration field.
This field is new in Vamp API version 2; it must not be tested
for plugins that report an older API version in their plugin
descriptor.
*/
int hasDuration;
} VampOutputDescriptor; } VampOutputDescriptor;
typedef struct _VampFeature typedef struct _VampFeature
@ -184,13 +193,46 @@ typedef struct _VampFeature
} VampFeature; } VampFeature;
typedef struct _VampFeatureV2
{
/** 1 if the feature has a duration. */
int hasDuration;
/** Seconds component of duratiion. */
int durationSec;
/** Nanoseconds component of duration. */
int durationNsec;
} VampFeatureV2;
typedef union _VampFeatureUnion
{
// sizeof(featureV1) >= sizeof(featureV2) for backward compatibility
VampFeature v1;
VampFeatureV2 v2;
} VampFeatureUnion;
typedef struct _VampFeatureList typedef struct _VampFeatureList
{ {
/** Number of features in this feature list. */ /** Number of features in this feature list. */
unsigned int featureCount; unsigned int featureCount;
/** Features in this feature list. May be NULL if featureCount is zero. */ /** Features in this feature list. May be NULL if featureCount is
VampFeature *features; zero.
If present, this array must contain featureCount feature
structures for a Vamp API version 1 plugin, or 2*featureCount
feature unions for a Vamp API version 2 plugin.
The features returned by an API version 2 plugin must consist
of the same feature structures as in API version 1 for the
first featureCount array elements, followed by featureCount
unions that contain VampFeatureV2 structures (or NULL pointers
if no V2 feature structures are present).
*/
VampFeatureUnion *features;
} VampFeatureList; } VampFeatureList;
@ -289,7 +331,7 @@ typedef struct _VampPluginDescriptor
handle, or releaseOutputDescriptor for this descriptor. Host handle, or releaseOutputDescriptor for this descriptor. Host
must call releaseOutputDescriptor after use. */ must call releaseOutputDescriptor after use. */
VampOutputDescriptor *(*getOutputDescriptor)(VampPluginHandle, VampOutputDescriptor *(*getOutputDescriptor)(VampPluginHandle,
unsigned int); unsigned int);
/** Destroy a descriptor for a feature output. */ /** Destroy a descriptor for a feature output. */
void (*releaseOutputDescriptor)(VampOutputDescriptor *); void (*releaseOutputDescriptor)(VampOutputDescriptor *);
@ -312,6 +354,7 @@ typedef struct _VampPluginDescriptor
} VampPluginDescriptor; } VampPluginDescriptor;
/** Get the descriptor for a given plugin index in this library. /** Get the descriptor for a given plugin index in this library.
Return NULL if the index is outside the range of valid indices for Return NULL if the index is outside the range of valid indices for
this plugin library. this plugin library.
@ -324,10 +367,16 @@ typedef struct _VampPluginDescriptor
field for its actual compatibility level, the host should be able field for its actual compatibility level, the host should be able
to do the right thing with it: use it if possible, discard it to do the right thing with it: use it if possible, discard it
otherwise. otherwise.
This is the only symbol that a Vamp plugin actually needs to
export from its shared object; all others can be hidden. See the
accompanying documentation for notes on how to achieve this with
certain compilers.
*/ */
const VampPluginDescriptor *vampGetPluginDescriptor const VampPluginDescriptor *vampGetPluginDescriptor
(unsigned int hostApiVersion, unsigned int index); (unsigned int hostApiVersion, unsigned int index);
/** Function pointer type for vampGetPluginDescriptor. */ /** Function pointer type for vampGetPluginDescriptor. */
typedef const VampPluginDescriptor *(*VampGetPluginDescriptorFunction) typedef const VampPluginDescriptor *(*VampGetPluginDescriptorFunction)
(unsigned int, unsigned int); (unsigned int, unsigned int);