base rename

This commit is contained in:
chatlanin 2024-08-08 11:53:48 +03:00
parent 103f458e8e
commit e95b339dbb
37 changed files with 4225 additions and 6960 deletions

View File

@ -1,50 +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 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 _SYSTEM_H_
#define _SYSTEM_H_
#include <dlfcn.h>
#define DLOPEN(a,b) dlopen((a).c_str(),(b))
#define DLSYM(a,b) dlsym((a),(b))
#define DLCLOSE(a) dlclose((a))
#define DLERROR() dlerror()
#define PLUGIN_SUFFIX "so"
#define HAVE_OPENDIR 1
#endif

View File

@ -1,40 +0,0 @@
#include <vamp-hostsdk/host-c.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
int libcount = vhGetLibraryCount();
printf("Vamp plugin libraries found:\n");
for (i = 0; i < libcount; ++i) {
printf("%d: %s\n", i, vhGetLibraryName(i));
}
printf("Going to try loading qm-vamp-plugins...\n");
int libindex = vhGetLibraryIndex("qm-vamp-plugins");
vhLibrary lib = vhLoadLibrary(libindex);
if (!lib) {
printf("Failure!\n");
return 1;
}
int plugincount = vhGetPluginCount(lib);
printf("Success: it contains %d plugins; they are:\n", plugincount);
for (i = 0; i < plugincount; ++i) {
const VampPluginDescriptor *descriptor = vhGetPluginDescriptor(lib, i);
if (!descriptor) {
printf("<unknown! failed to load>\n");
} else {
printf("%s\n", descriptor->identifier);
}
}
vhUnloadLibrary(lib);
return 0;
}

View File

@ -1,863 +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 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.
*/
/*
* This "simple" Vamp plugin host is no longer as simple as it was; it
* now has a lot of options and includes a lot of code to handle the
* various useful listing modes it supports.
*
* However, the runPlugin function still contains a reasonable
* implementation of a fairly generic Vamp plugin host capable of
* evaluating a given output on a given plugin for a sound file read
* via libsndfile.
*/
#include <vamp-hostsdk/PluginHostAdapter.h>
#include <vamp-hostsdk/PluginInputDomainAdapter.h>
#include <vamp-hostsdk/PluginLoader.h>
#include <iostream>
#include <fstream>
#include <set>
#include <sndfile.h>
#include <cstring>
#include <cstdlib>
#include "system.h"
#include <cmath>
using namespace std;
using Vamp::Plugin;
using Vamp::PluginHostAdapter;
using Vamp::RealTime;
using Vamp::HostExt::PluginLoader;
using Vamp::HostExt::PluginWrapper;
using Vamp::HostExt::PluginInputDomainAdapter;
#define HOST_VERSION "1.5"
enum Verbosity {
PluginIds,
PluginOutputIds,
PluginInformation,
PluginInformationDetailed
};
void printFeatures(int, int,
const Plugin::OutputDescriptor &, int,
const Plugin::FeatureSet &, ofstream *, bool frames);
void transformInput(float *, size_t);
void fft(unsigned int, bool, double *, double *, double *, double *);
void printPluginPath(bool verbose);
void printPluginCategoryList();
void enumeratePlugins(Verbosity);
void listPluginsInLibrary(string soname);
int runPlugin(string myname, string soname, string id, string output,
int outputNo, string inputFile, string outfilename, bool frames);
void usage(const char *name)
{
cerr << "\n"
<< name << ": A command-line host for Vamp audio analysis plugins.\n\n"
"Centre for Digital Music, Queen Mary, University of London.\n"
"Copyright 2006-2009 Chris Cannam and QMUL.\n"
"Freely redistributable; published under a BSD-style license.\n\n"
"Usage:\n\n"
" " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin[:output] file.wav [-o out.txt]\n"
" " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin file.wav [outputno] [-o out.txt]\n\n"
" -- Load plugin id \"plugin\" from \"pluginlibrary\" and run it on the\n"
" audio data in \"file.wav\", retrieving the named \"output\", or output\n"
" number \"outputno\" (the first output by default) and dumping it to\n"
" standard output, or to \"out.txt\" if the -o option is given.\n\n"
" \"pluginlibrary\" should be a library name, not a file path; the\n"
" standard Vamp library search path will be used to locate it. If\n"
" a file path is supplied, the directory part(s) will be ignored.\n\n"
" If the -s option is given, results will be labelled with the audio\n"
" sample frame at which they occur. Otherwise, they will be labelled\n"
" with time in seconds.\n\n"
" " << name << " -l\n"
" " << name << " --list\n\n"
" -- List the plugin libraries and Vamp plugins in the library search path\n"
" in a verbose human-readable format.\n\n"
" " << name << " -L\n"
" " << name << " --list-full\n\n"
" -- List all data reported by all the Vamp plugins in the library search\n"
" path in a very verbose human-readable format.\n\n"
" " << name << " --list-ids\n\n"
" -- List the plugins in the search path in a terse machine-readable format,\n"
" in the form vamp:soname:identifier.\n\n"
" " << name << " --list-outputs\n\n"
" -- List the outputs for plugins in the search path in a machine-readable\n"
" format, in the form vamp:soname:identifier:output.\n\n"
" " << name << " --list-by-category\n\n"
" -- List the plugins as a plugin index by category, in a machine-readable\n"
" format. The format may change in future releases.\n\n"
" " << name << " -p\n\n"
" -- Print out the Vamp library search path.\n\n"
" " << name << " -v\n\n"
" -- Display version information only.\n"
<< endl;
exit(2);
}
int main(int argc, char **argv)
{
char *scooter = argv[0];
char *name = 0;
while (scooter && *scooter) {
if (*scooter == '/' || *scooter == '\\') name = ++scooter;
else ++scooter;
}
if (!name || !*name) name = argv[0];
if (argc < 2) usage(name);
if (argc == 2) {
if (!strcmp(argv[1], "-v")) {
cout << "Simple Vamp plugin host version: " << HOST_VERSION << endl
<< "Vamp API version: " << VAMP_API_VERSION << endl
<< "Vamp SDK version: " << VAMP_SDK_VERSION << endl;
return 0;
} else if (!strcmp(argv[1], "-l") || !strcmp(argv[1], "--list")) {
printPluginPath(true);
enumeratePlugins(PluginInformation);
return 0;
} else if (!strcmp(argv[1], "-L") || !strcmp(argv[1], "--list-full")) {
enumeratePlugins(PluginInformationDetailed);
return 0;
} else if (!strcmp(argv[1], "-p")) {
printPluginPath(false);
return 0;
} else if (!strcmp(argv[1], "--list-ids")) {
enumeratePlugins(PluginIds);
return 0;
} else if (!strcmp(argv[1], "--list-outputs")) {
enumeratePlugins(PluginOutputIds);
return 0;
} else if (!strcmp(argv[1], "--list-by-category")) {
printPluginCategoryList();
return 0;
} else usage(name);
}
if (argc < 3) usage(name);
bool useFrames = false;
int base = 1;
if (!strcmp(argv[1], "-s")) {
useFrames = true;
base = 2;
}
string soname = argv[base];
string wavname = argv[base+1];
string plugid = "";
string output = "";
int outputNo = -1;
string outfilename;
if (argc >= base+3) {
int idx = base+2;
if (isdigit(*argv[idx])) {
outputNo = atoi(argv[idx++]);
}
if (argc == idx + 2) {
if (!strcmp(argv[idx], "-o")) {
outfilename = argv[idx+1];
} else usage(name);
} else if (argc != idx) {
(usage(name));
}
}
cerr << endl << name << ": Running..." << endl;
cerr << "Reading file: \"" << wavname << "\", writing to ";
if (outfilename == "") {
cerr << "standard output" << endl;
} else {
cerr << "\"" << outfilename << "\"" << endl;
}
string::size_type sep = soname.find(':');
if (sep != string::npos) {
plugid = soname.substr(sep + 1);
soname = soname.substr(0, sep);
sep = plugid.find(':');
if (sep != string::npos) {
output = plugid.substr(sep + 1);
plugid = plugid.substr(0, sep);
}
}
if (plugid == "") {
usage(name);
}
if (output != "" && outputNo != -1) {
usage(name);
}
if (output == "" && outputNo == -1) {
outputNo = 0;
}
return runPlugin(name, soname, plugid, output, outputNo,
wavname, outfilename, useFrames);
}
int runPlugin(string myname, string soname, string id,
string output, int outputNo, string wavname,
string outfilename, bool useFrames)
{
PluginLoader *loader = PluginLoader::getInstance();
PluginLoader::PluginKey key = loader->composePluginKey(soname, id);
SNDFILE *sndfile;
SF_INFO sfinfo;
memset(&sfinfo, 0, sizeof(SF_INFO));
sndfile = sf_open(wavname.c_str(), SFM_READ, &sfinfo);
if (!sndfile) {
cerr << myname << ": ERROR: Failed to open input file \""
<< wavname << "\": " << sf_strerror(sndfile) << endl;
return 1;
}
ofstream *out = 0;
if (outfilename != "") {
out = new ofstream(outfilename.c_str(), ios::out);
if (!*out) {
cerr << myname << ": ERROR: Failed to open output file \""
<< outfilename << "\" for writing" << endl;
delete out;
return 1;
}
}
Plugin *plugin = loader->loadPlugin
(key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE);
if (!plugin) {
cerr << myname << ": ERROR: Failed to load plugin \"" << id
<< "\" from library \"" << soname << "\"" << endl;
sf_close(sndfile);
if (out) {
out->close();
delete out;
}
return 1;
}
cerr << "Running plugin: \"" << plugin->getIdentifier() << "\"..." << endl;
// Note that the following would be much simpler if we used a
// PluginBufferingAdapter as well -- i.e. if we had passed
// PluginLoader::ADAPT_ALL to loader->loadPlugin() above, instead
// of ADAPT_ALL_SAFE. Then we could simply specify our own block
// size, keep the step size equal to the block size, and ignore
// the plugin's bleatings. However, there are some issues with
// using a PluginBufferingAdapter that make the results sometimes
// technically different from (if effectively the same as) the
// un-adapted plugin, so we aren't doing that here. See the
// PluginBufferingAdapter documentation for details.
int blockSize = plugin->getPreferredBlockSize();
int stepSize = plugin->getPreferredStepSize();
if (blockSize == 0) {
blockSize = 1024;
}
if (stepSize == 0) {
if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
stepSize = blockSize/2;
} else {
stepSize = blockSize;
}
} else if (stepSize > blockSize) {
cerr << "WARNING: stepSize " << stepSize << " > blockSize " << blockSize << ", resetting blockSize to ";
if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
blockSize = stepSize * 2;
} else {
blockSize = stepSize;
}
cerr << blockSize << endl;
}
int overlapSize = blockSize - stepSize;
sf_count_t currentStep = 0;
int finalStepsRemaining = max(1, (blockSize / stepSize) - 1); // at end of file, this many part-silent frames needed after we hit EOF
int channels = sfinfo.channels;
float *filebuf = new float[blockSize * channels];
float **plugbuf = new float*[channels];
for (int c = 0; c < channels; ++c) plugbuf[c] = new float[blockSize + 2];
cerr << "Using block size = " << blockSize << ", step size = "
<< stepSize << endl;
// The channel queries here are for informational purposes only --
// a PluginChannelAdapter is being used automatically behind the
// scenes, and it will take case of any channel mismatch
int minch = plugin->getMinChannelCount();
int maxch = plugin->getMaxChannelCount();
cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl;
cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl;
Plugin::OutputList outputs = plugin->getOutputDescriptors();
Plugin::OutputDescriptor od;
Plugin::FeatureSet features;
int returnValue = 1;
int progress = 0;
RealTime rt;
PluginWrapper *wrapper = 0;
RealTime adjustment = RealTime::zeroTime;
if (outputs.empty()) {
cerr << "ERROR: Plugin has no outputs!" << endl;
goto done;
}
if (outputNo < 0) {
for (size_t oi = 0; oi < outputs.size(); ++oi) {
if (outputs[oi].identifier == output) {
outputNo = oi;
break;
}
}
if (outputNo < 0) {
cerr << "ERROR: Non-existent output \"" << output << "\" requested" << endl;
goto done;
}
} else {
if (int(outputs.size()) <= outputNo) {
cerr << "ERROR: Output " << outputNo << " requested, but plugin has only " << outputs.size() << " output(s)" << endl;
goto done;
}
}
od = outputs[outputNo];
cerr << "Output is: \"" << od.identifier << "\"" << endl;
if (!plugin->initialise(channels, stepSize, blockSize)) {
cerr << "ERROR: Plugin initialise (channels = " << channels
<< ", stepSize = " << stepSize << ", blockSize = "
<< blockSize << ") failed." << endl;
goto done;
}
wrapper = dynamic_cast<PluginWrapper *>(plugin);
if (wrapper) {
// See documentation for
// PluginInputDomainAdapter::getTimestampAdjustment
PluginInputDomainAdapter *ida =
wrapper->getWrapper<PluginInputDomainAdapter>();
if (ida) adjustment = ida->getTimestampAdjustment();
}
// Here we iterate over the frames, avoiding asking the numframes in case it's streaming input.
do {
int count;
if ((blockSize==stepSize) || (currentStep==0)) {
// read a full fresh block
if ((count = sf_readf_float(sndfile, filebuf, blockSize)) < 0) {
cerr << "ERROR: sf_readf_float failed: " << sf_strerror(sndfile) << endl;
break;
}
if (count != blockSize) --finalStepsRemaining;
} else {
// otherwise shunt the existing data down and read the remainder.
memmove(filebuf, filebuf + (stepSize * channels), overlapSize * channels * sizeof(float));
if ((count = sf_readf_float(sndfile, filebuf + (overlapSize * channels), stepSize)) < 0) {
cerr << "ERROR: sf_readf_float failed: " << sf_strerror(sndfile) << endl;
break;
}
if (count != stepSize) --finalStepsRemaining;
count += overlapSize;
}
for (int c = 0; c < channels; ++c) {
int j = 0;
while (j < count) {
plugbuf[c][j] = filebuf[j * sfinfo.channels + c];
++j;
}
while (j < blockSize) {
plugbuf[c][j] = 0.0f;
++j;
}
}
rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate);
features = plugin->process(plugbuf, rt);
printFeatures
(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
sfinfo.samplerate, od, outputNo, features, out, useFrames);
if (sfinfo.frames > 0){
int pp = progress;
progress = (int)((float(currentStep * stepSize) / sfinfo.frames) * 100.f + 0.5f);
if (progress != pp && out) {
cerr << "\r" << progress << "%";
}
}
++currentStep;
} while (finalStepsRemaining > 0);
if (out) cerr << "\rDone" << endl;
rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate);
features = plugin->getRemainingFeatures();
printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
sfinfo.samplerate, od, outputNo, features, out, useFrames);
returnValue = 0;
done:
delete plugin;
if (out) {
out->close();
delete out;
}
sf_close(sndfile);
return returnValue;
}
static double
toSeconds(const RealTime &time)
{
return time.sec + double(time.nsec + 1) / 1000000000.0;
}
void
printFeatures(int frame, int sr,
const Plugin::OutputDescriptor &output, int outputNo,
const Plugin::FeatureSet &features, ofstream *out, bool useFrames)
{
static int featureCount = -1;
if (features.find(outputNo) == features.end()) return;
for (size_t i = 0; i < features.at(outputNo).size(); ++i) {
const Plugin::Feature &f = features.at(outputNo).at(i);
bool haveRt = false;
RealTime rt;
if (output.sampleType == Plugin::OutputDescriptor::VariableSampleRate) {
rt = f.timestamp;
haveRt = true;
} else if (output.sampleType == Plugin::OutputDescriptor::FixedSampleRate) {
int n = featureCount + 1;
if (f.hasTimestamp) {
n = int(round(toSeconds(f.timestamp) * output.sampleRate));
}
rt = RealTime::fromSeconds(double(n) / output.sampleRate);
haveRt = true;
featureCount = n;
}
if (useFrames) {
int displayFrame = frame;
if (haveRt) {
displayFrame = RealTime::realTime2Frame(rt, sr);
}
(out ? *out : cout) << displayFrame;
if (f.hasDuration) {
displayFrame = RealTime::realTime2Frame(f.duration, sr);
(out ? *out : cout) << "," << displayFrame;
}
(out ? *out : cout) << ":";
} else {
if (!haveRt) {
rt = RealTime::frame2RealTime(frame, sr);
}
(out ? *out : cout) << rt.toString();
if (f.hasDuration) {
rt = f.duration;
(out ? *out : cout) << "," << rt.toString();
}
(out ? *out : cout) << ":";
}
for (unsigned int j = 0; j < f.values.size(); ++j) {
(out ? *out : cout) << " " << f.values[j];
}
(out ? *out : cout) << " " << f.label;
(out ? *out : cout) << endl;
}
}
void
printPluginPath(bool verbose)
{
if (verbose) {
cout << "\nVamp plugin search path: ";
}
vector<string> path = PluginHostAdapter::getPluginPath();
for (size_t i = 0; i < path.size(); ++i) {
if (verbose) {
cout << "[" << path[i] << "]";
} else {
cout << path[i] << endl;
}
}
if (verbose) cout << endl;
}
static
string
header(string text, int level)
{
string out = '\n' + text + '\n';
for (size_t i = 0; i < text.length(); ++i) {
out += (level == 1 ? '=' : level == 2 ? '-' : '~');
}
out += '\n';
return out;
}
void
enumeratePlugins(Verbosity verbosity)
{
PluginLoader *loader = PluginLoader::getInstance();
if (verbosity == PluginInformation) {
cout << "\nVamp plugin libraries found in search path:" << endl;
}
vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
typedef multimap<string, PluginLoader::PluginKey>
LibraryMap;
LibraryMap libraryMap;
for (size_t i = 0; i < plugins.size(); ++i) {
string path = loader->getLibraryPathForPlugin(plugins[i]);
libraryMap.insert(LibraryMap::value_type(path, plugins[i]));
}
string prevPath = "";
int index = 0;
for (LibraryMap::iterator i = libraryMap.begin();
i != libraryMap.end(); ++i) {
string path = i->first;
PluginLoader::PluginKey key = i->second;
if (path != prevPath) {
prevPath = path;
index = 0;
if (verbosity == PluginInformation) {
cout << "\n " << path << ":" << endl;
} else if (verbosity == PluginInformationDetailed) {
string::size_type ki = i->second.find(':');
string text = "Library \"" + i->second.substr(0, ki) + "\"";
cout << "\n" << header(text, 1);
}
}
Plugin *plugin = loader->loadPlugin(key, 48000);
if (plugin) {
char c = char('A' + index);
if (c > 'Z') c = char('a' + (index - 26));
PluginLoader::PluginCategoryHierarchy category =
loader->getPluginCategory(key);
string catstr;
if (!category.empty()) {
for (size_t ci = 0; ci < category.size(); ++ci) {
if (ci > 0) catstr += " > ";
catstr += category[ci];
}
}
if (verbosity == PluginInformation) {
cout << " [" << c << "] [v"
<< plugin->getVampApiVersion() << "] "
<< plugin->getName() << ", \""
<< plugin->getIdentifier() << "\"" << " ["
<< plugin->getMaker() << "]" << endl;
if (catstr != "") {
cout << " > " << catstr << endl;
}
if (plugin->getDescription() != "") {
cout << " - " << plugin->getDescription() << endl;
}
} else if (verbosity == PluginInformationDetailed) {
cout << header(plugin->getName(), 2);
cout << " - Identifier: "
<< key << endl;
cout << " - Plugin Version: "
<< plugin->getPluginVersion() << endl;
cout << " - Vamp API Version: "
<< plugin->getVampApiVersion() << endl;
cout << " - Maker: \""
<< plugin->getMaker() << "\"" << endl;
cout << " - Copyright: \""
<< plugin->getCopyright() << "\"" << endl;
cout << " - Description: \""
<< plugin->getDescription() << "\"" << endl;
cout << " - Input Domain: "
<< (plugin->getInputDomain() == Vamp::Plugin::TimeDomain ?
"Time Domain" : "Frequency Domain") << endl;
cout << " - Default Step Size: "
<< plugin->getPreferredStepSize() << endl;
cout << " - Default Block Size: "
<< plugin->getPreferredBlockSize() << endl;
cout << " - Minimum Channels: "
<< plugin->getMinChannelCount() << endl;
cout << " - Maximum Channels: "
<< plugin->getMaxChannelCount() << endl;
} else if (verbosity == PluginIds) {
cout << "vamp:" << key << endl;
}
Plugin::OutputList outputs =
plugin->getOutputDescriptors();
if (verbosity == PluginInformationDetailed) {
Plugin::ParameterList params = plugin->getParameterDescriptors();
for (size_t j = 0; j < params.size(); ++j) {
Plugin::ParameterDescriptor &pd(params[j]);
cout << "\nParameter " << j+1 << ": \"" << pd.name << "\"" << endl;
cout << " - Identifier: " << pd.identifier << endl;
cout << " - Description: \"" << pd.description << "\"" << endl;
if (pd.unit != "") {
cout << " - Unit: " << pd.unit << endl;
}
cout << " - Range: ";
cout << pd.minValue << " -> " << pd.maxValue << endl;
cout << " - Default: ";
cout << pd.defaultValue << endl;
if (pd.isQuantized) {
cout << " - Quantize Step: "
<< pd.quantizeStep << endl;
}
if (!pd.valueNames.empty()) {
cout << " - Value Names: ";
for (size_t k = 0; k < pd.valueNames.size(); ++k) {
if (k > 0) cout << ", ";
cout << "\"" << pd.valueNames[k] << "\"";
}
cout << endl;
}
}
if (outputs.empty()) {
cout << "\n** Note: This plugin reports no outputs!" << endl;
}
for (size_t j = 0; j < outputs.size(); ++j) {
Plugin::OutputDescriptor &od(outputs[j]);
cout << "\nOutput " << j+1 << ": \"" << od.name << "\"" << endl;
cout << " - Identifier: " << od.identifier << endl;
cout << " - Description: \"" << od.description << "\"" << endl;
if (od.unit != "") {
cout << " - Unit: " << od.unit << endl;
}
if (od.hasFixedBinCount) {
cout << " - Default Bin Count: " << od.binCount << endl;
}
if (!od.binNames.empty()) {
bool have = false;
for (size_t k = 0; k < od.binNames.size(); ++k) {
if (od.binNames[k] != "") {
have = true; break;
}
}
if (have) {
cout << " - Bin Names: ";
for (size_t k = 0; k < od.binNames.size(); ++k) {
if (k > 0) cout << ", ";
cout << "\"" << od.binNames[k] << "\"";
}
cout << endl;
}
}
if (od.hasKnownExtents) {
cout << " - Default Extents: ";
cout << od.minValue << " -> " << od.maxValue << endl;
}
if (od.isQuantized) {
cout << " - Quantize Step: "
<< od.quantizeStep << endl;
}
cout << " - Sample Type: "
<< (od.sampleType ==
Plugin::OutputDescriptor::OneSamplePerStep ?
"One Sample Per Step" :
od.sampleType ==
Plugin::OutputDescriptor::FixedSampleRate ?
"Fixed Sample Rate" :
"Variable Sample Rate") << endl;
if (od.sampleType !=
Plugin::OutputDescriptor::OneSamplePerStep) {
cout << " - Default Rate: "
<< od.sampleRate << endl;
}
cout << " - Has Duration: "
<< (od.hasDuration ? "Yes" : "No") << endl;
}
}
if (outputs.size() > 1 || verbosity == PluginOutputIds) {
for (size_t j = 0; j < outputs.size(); ++j) {
if (verbosity == PluginInformation) {
cout << " (" << j << ") "
<< outputs[j].name << ", \""
<< outputs[j].identifier << "\"" << endl;
if (outputs[j].description != "") {
cout << " - "
<< outputs[j].description << endl;
}
} else if (verbosity == PluginOutputIds) {
cout << "vamp:" << key << ":" << outputs[j].identifier << endl;
}
}
}
++index;
delete plugin;
}
}
if (verbosity == PluginInformation ||
verbosity == PluginInformationDetailed) {
cout << endl;
}
}
void
printPluginCategoryList()
{
PluginLoader *loader = PluginLoader::getInstance();
vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
set<string> printedcats;
for (size_t i = 0; i < plugins.size(); ++i) {
PluginLoader::PluginKey key = plugins[i];
PluginLoader::PluginCategoryHierarchy category =
loader->getPluginCategory(key);
Plugin *plugin = loader->loadPlugin(key, 48000);
if (!plugin) continue;
string catstr = "";
if (category.empty()) catstr = '|';
else {
for (size_t j = 0; j < category.size(); ++j) {
catstr += category[j];
catstr += '|';
if (printedcats.find(catstr) == printedcats.end()) {
std::cout << catstr << std::endl;
printedcats.insert(catstr);
}
}
}
std::cout << catstr << key << ":::" << plugin->getName() << ":::" << plugin->getMaker() << ":::" << plugin->getDescription() << std::endl;
}
}

View File

@ -1,6 +1,8 @@
inc += include_directories('.')
headers = [
'vamp-sdk/real_time/real_time.hpp',
'vamp.h',
'vamp-hostsdk/Files.h',
'vamp-hostsdk/host-c.h',
@ -17,17 +19,15 @@ headers = [
'vamp-sdk/ext/vamp_kiss_fft.h',
'vamp-sdk/ext/vamp_kiss_fft_guts.h',
'vamp-sdk/ext/vamp_kiss_fftr.h',
'vamp-sdk/FFT.h',
'vamp-sdk/Plugin.h',
'vamp-sdk/PluginAdapter.h',
'vamp-sdk/PluginBase.h',
'vamp-sdk/RealTime.h',
'vamp-sdk/vamp-sdk.h'
]
sources = [
'vamp-hostsdk/acsymbols.cpp',
'vamp-sdk/real_time/real_time.cpp',
'vamp-hostsdk/Files.cpp',
'vamp-hostsdk/host-c.cpp',
'vamp-hostsdk/PluginBufferingAdapter.cpp',
@ -38,10 +38,8 @@ sources = [
'vamp-hostsdk/PluginSummarisingAdapter.cpp',
'vamp-hostsdk/PluginWrapper.cpp',
'vamp-sdk/acsymbols.cpp',
'vamp-sdk/FFT.cpp',
'vamp-sdk/PluginAdapter.cpp',
'vamp-sdk/RealTime.cpp'
]
lib = library(

View File

@ -18,7 +18,7 @@ std::vector<std::string> Files::listLibraryFiles()
std::vector<std::string> Files::listLibraryFilesMatching(Filter filter)
{
std::vector<std::string> path = Vamp::PluginHostAdapter::getPluginPath();
std::vector<std::string> path = vamp::PluginHostAdapter::getPluginPath();
std::vector<std::string> libraryFiles;
// we match case-insensitively, but only with ascii range

View File

@ -3,9 +3,6 @@
#include <vector>
#include <string>
/**
* This is a private implementation class for the Vamp Host SDK.
*/
class Files
{
public:

File diff suppressed because it is too large Load Diff

View File

@ -2,148 +2,35 @@
#include "vamp-hostsdk/PluginWrapper.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
namespace vamp::host
{
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();
class PluginBufferingAdapter : public PluginWrapper
{
public:
PluginBufferingAdapter(plugin* p);
virtual ~PluginBufferingAdapter();
size_t getPreferredStepSize() const;
size_t getPreferredBlockSize() const;
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
size_t getPluginPreferredStepSize() const;
size_t getPluginPreferredBlockSize() const;
void setPluginStepSize(size_t stepSize);
void setPluginBlockSize(size_t blockSize);
void getActualStepAndBlockSizes(size_t &stepSize, size_t &blockSize);
/**
* 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;
void setParameter(std::string, float);
void selectProgram(std::string);
/**
* 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;
OutputList getOutputDescriptors() 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;
};
}
void reset();
FeatureSet process(const float *const *inputBuffers, real_time timestamp);
FeatureSet getRemainingFeatures();
protected:
class Impl;
Impl *m_impl;
};
}

View File

@ -1,105 +1,102 @@
#include "vamp-hostsdk/PluginChannelAdapter.h"
namespace Vamp {
namespace HostExt {
class PluginChannelAdapter::Impl
namespace vamp::host
{
public:
Impl(Plugin *plugin);
~Impl();
class PluginChannelAdapter::Impl
{
public:
Impl(plugin* p);
~Impl();
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 processInterleaved(const float *inputBuffers, RealTime timestamp);
FeatureSet process(const float *const *inputBuffers, real_time timestamp);
FeatureSet processInterleaved(const float *inputBuffers, real_time timestamp);
protected:
Plugin *m_plugin;
size_t m_blockSize;
size_t m_inputChannels;
size_t m_pluginChannels;
float **m_buffer;
float **m_deinterleave;
const float **m_forwardPtrs;
};
protected:
plugin *m_plugin;
size_t m_blockSize;
size_t m_inputChannels;
size_t m_pluginChannels;
float **m_buffer;
float **m_deinterleave;
const float **m_forwardPtrs;
};
PluginChannelAdapter::PluginChannelAdapter(Plugin *plugin) :
PluginWrapper(plugin)
{
m_impl = new Impl(plugin);
}
PluginChannelAdapter::PluginChannelAdapter(plugin* p) : PluginWrapper(p)
{
m_impl = new Impl(p);
}
PluginChannelAdapter::~PluginChannelAdapter()
{
PluginChannelAdapter::~PluginChannelAdapter()
{
delete m_impl;
}
}
bool
PluginChannelAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
bool PluginChannelAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
return m_impl->initialise(channels, stepSize, blockSize);
}
}
PluginChannelAdapter::FeatureSet
PluginChannelAdapter::process(const float *const *inputBuffers,
RealTime timestamp)
{
PluginChannelAdapter::FeatureSet PluginChannelAdapter::process(const float *const *inputBuffers, real_time timestamp)
{
return m_impl->process(inputBuffers, timestamp);
}
}
PluginChannelAdapter::FeatureSet
PluginChannelAdapter::processInterleaved(const float *inputBuffers,
RealTime timestamp)
{
PluginChannelAdapter::FeatureSet PluginChannelAdapter::processInterleaved(const float *inputBuffers, real_time timestamp)
{
return m_impl->processInterleaved(inputBuffers, timestamp);
}
}
PluginChannelAdapter::Impl::Impl(Plugin *plugin) :
m_plugin(plugin),
m_blockSize(0),
m_inputChannels(0),
m_pluginChannels(0),
m_buffer(0),
m_deinterleave(0),
m_forwardPtrs(0)
{
}
PluginChannelAdapter::Impl::Impl(plugin* p) :
m_plugin(p),
m_blockSize(0),
m_inputChannels(0),
m_pluginChannels(0),
m_buffer(0),
m_deinterleave(0),
m_forwardPtrs(0)
{
}
PluginChannelAdapter::Impl::~Impl()
{
// the adapter will delete the plugin
if (m_buffer) {
if (m_inputChannels > m_pluginChannels) {
delete[] m_buffer[0];
} else {
for (size_t i = 0; i < m_pluginChannels - m_inputChannels; ++i) {
delete[] m_buffer[i];
}
PluginChannelAdapter::Impl::~Impl()
{
if (m_buffer)
{
if (m_inputChannels > m_pluginChannels)
{
delete[] m_buffer[0];
}
else
{
for (size_t i = 0; i < m_pluginChannels - m_inputChannels; ++i)
{
delete[] m_buffer[i];
}
delete[] m_buffer;
m_buffer = 0;
}
delete[] m_buffer;
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_deinterleave)
{
for (size_t i = 0; i < m_inputChannels; ++i)
{
delete[] m_deinterleave[i];
}
delete[] m_deinterleave;
m_deinterleave = 0;
}
if (m_forwardPtrs) {
delete[] m_forwardPtrs;
m_forwardPtrs = 0;
if (m_forwardPtrs)
{
delete[] m_forwardPtrs;
m_forwardPtrs = 0;
}
}
}
bool
PluginChannelAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
bool PluginChannelAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
m_blockSize = blockSize;
size_t minch = m_plugin->getMinChannelCount();
@ -107,122 +104,126 @@ PluginChannelAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t
m_inputChannels = channels;
if (m_inputChannels < minch) {
if (m_inputChannels < minch)
{
m_forwardPtrs = new const float *[minch];
m_forwardPtrs = new const float *[minch];
if (m_inputChannels > 1) {
// We need a set of zero-valued buffers to add to the
// forwarded pointers
m_buffer = new float*[minch - channels];
for (size_t i = 0; i < minch; ++i) {
m_buffer[i] = new float[blockSize];
for (size_t j = 0; j < blockSize; ++j) {
m_buffer[i][j] = 0.f;
}
}
if (m_inputChannels > 1)
{
// We need a set of zero-valued buffers to add to the
// forwarded pointers
m_buffer = new float*[minch - channels];
for (size_t i = 0; i < minch; ++i)
{
m_buffer[i] = new float[blockSize];
for (size_t j = 0; j < blockSize; ++j)
{
m_buffer[i][j] = 0.f;
}
}
}
m_pluginChannels = minch;
m_pluginChannels = minch;
// std::cerr << "PluginChannelAdapter::initialise: expanding " << m_inputChannels << " to " << m_pluginChannels << " for plugin" << std::endl;
}
else if (m_inputChannels > maxch)
{
if (maxch == 1)
{
m_buffer = new float *[1];
m_buffer[0] = new float[blockSize];
}
} else if (m_inputChannels > maxch) {
m_pluginChannels = maxch;
// We only need m_buffer if we are mixing down to a single
// channel -- otherwise we can just forward the same float* as
// passed in to process(), expecting the excess to be ignored
if (maxch == 1) {
m_buffer = new float *[1];
m_buffer[0] = new float[blockSize];
// std::cerr << "PluginChannelAdapter::initialise: mixing " << m_inputChannels << " to mono for plugin" << std::endl;
} else {
// std::cerr << "PluginChannelAdapter::initialise: reducing " << m_inputChannels << " to " << m_pluginChannels << " for plugin" << std::endl;
}
m_pluginChannels = maxch;
} else {
// std::cerr << "PluginChannelAdapter::initialise: accepting given number of channels (" << m_inputChannels << ")" << std::endl;
m_pluginChannels = m_inputChannels;
}
else
{
m_pluginChannels = m_inputChannels;
}
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];
}
PluginChannelAdapter::FeatureSet PluginChannelAdapter::Impl::processInterleaved(const float *inputBuffers, real_time 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];
}
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::Impl::process(const float *const *inputBuffers,
RealTime timestamp)
{
// std::cerr << "PluginChannelAdapter::process: " << m_inputChannels << " -> " << m_pluginChannels << " channels" << std::endl;
PluginChannelAdapter::FeatureSet PluginChannelAdapter::Impl::process(const float *const *inputBuffers, real_time timestamp)
{
if (m_inputChannels < m_pluginChannels)
{
if (m_inputChannels == 1)
{
for (size_t i = 0; i < m_pluginChannels; ++i)
{
m_forwardPtrs[i] = inputBuffers[0];
}
}
else
{
for (size_t i = 0; i < m_inputChannels; ++i)
{
m_forwardPtrs[i] = inputBuffers[i];
}
for (size_t i = m_inputChannels; i < m_pluginChannels; ++i)
{
m_forwardPtrs[i] = m_buffer[i - m_inputChannels];
}
}
if (m_inputChannels < m_pluginChannels) {
if (m_inputChannels == 1) {
for (size_t i = 0; i < m_pluginChannels; ++i) {
m_forwardPtrs[i] = inputBuffers[0];
}
} else {
for (size_t i = 0; i < m_inputChannels; ++i) {
m_forwardPtrs[i] = inputBuffers[i];
}
for (size_t i = m_inputChannels; i < m_pluginChannels; ++i) {
m_forwardPtrs[i] = m_buffer[i - m_inputChannels];
}
return m_plugin->process(m_forwardPtrs, timestamp);
}
else if (m_inputChannels > m_pluginChannels)
{
if (m_pluginChannels == 1)
{
for (size_t j = 0; j < m_blockSize; ++j)
{
m_buffer[0][j] = inputBuffers[0][j];
}
return m_plugin->process(m_forwardPtrs, timestamp);
} else if (m_inputChannels > m_pluginChannels) {
if (m_pluginChannels == 1) {
for (size_t j = 0; j < m_blockSize; ++j) {
m_buffer[0][j] = inputBuffers[0][j];
}
for (size_t i = 1; i < m_inputChannels; ++i) {
for (size_t j = 0; j < m_blockSize; ++j) {
m_buffer[0][j] += inputBuffers[i][j];
}
}
for (size_t j = 0; j < m_blockSize; ++j) {
m_buffer[0][j] /= float(m_inputChannels);
}
return m_plugin->process(m_buffer, timestamp);
} else {
return m_plugin->process(inputBuffers, timestamp);
for (size_t i = 1; i < m_inputChannels; ++i)
{
for (size_t j = 0; j < m_blockSize; ++j)
{
m_buffer[0][j] += inputBuffers[i][j];
}
}
} else {
for (size_t j = 0; j < m_blockSize; ++j)
{
m_buffer[0][j] /= float(m_inputChannels);
}
return m_plugin->process(m_buffer, timestamp);
}
else
{
return m_plugin->process(inputBuffers, timestamp);
}
}
else
{
return m_plugin->process(inputBuffers, timestamp);
}
}
}
}
}

View File

@ -2,104 +2,21 @@
#include "vamp-hostsdk/PluginWrapper.h"
namespace Vamp {
namespace HostExt {
/**
* \class PluginChannelAdapter PluginChannelAdapter.h <vamp-hostsdk/PluginChannelAdapter.h>
*
* PluginChannelAdapter is a Vamp plugin adapter that implements a
* policy for management of plugins that expect a different number of
* input channels from the number actually available in the source
* audio data.
*
* A host using PluginChannelAdapter may ignore the getMinChannelCount
* and getMaxChannelCount reported by the plugin, and still expect the
* plugin to run.
*
* PluginChannelAdapter implements the following policy:
*
* - If the plugin supports the provided number of channels directly,
* PluginChannelAdapter will just run the plugin as normal.
*
* - If the plugin only supports exactly one channel but more than
* one channel is provided, PluginChannelAdapter will use the mean of
* the channels. This ensures that the resulting values remain
* within the same magnitude range as expected for mono data.
*
* - If the plugin requires more than one channel but exactly one is
* provided, the provided channel will be duplicated across all the
* plugin input channels.
*
* If none of the above apply:
*
* - If the plugin requires more channels than are provided, the
* minimum acceptable number of channels will be produced by adding
* empty (zero valued) channels to those provided.
*
* - If the plugin requires fewer channels than are provided, the
* maximum acceptable number of channels will be produced by
* discarding the excess channels.
*
* Hosts requiring a different channel policy from the above will need
* to implement it themselves, instead of using PluginChannelAdapter.
*
* Note that PluginChannelAdapter does not override the minimum and
* maximum channel counts returned by the wrapped plugin. The host
* will need to be aware that it is using a PluginChannelAdapter, and
* be prepared to ignore these counts as necessary. (This contrasts
* with the approach used in PluginInputDomainAdapter, which aims to
* make the host completely unaware of which underlying input domain
* is in fact in use.)
*
* (The rationale for this is that a host may wish to use the
* PluginChannelAdapter but still discriminate in some way on the
* basis of the number of channels actually supported. For example, a
* simple stereo audio host may prefer to reject plugins that require
* more than two channels on the grounds that doesn't actually
* understand what they are for, rather than allow the channel adapter
* to make a potentially meaningless channel conversion for them.)
*
* In every respect other than its management of channels, the
* PluginChannelAdapter behaves identically to the plugin that it
* wraps. The wrapped plugin will be deleted when the wrapper is
* deleted.
*
* \note This class was introduced in version 1.1 of the Vamp plugin SDK.
*/
class PluginChannelAdapter : public PluginWrapper
namespace vamp::host
{
public:
/**
* 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();
class PluginChannelAdapter : public PluginWrapper
{
public:
PluginChannelAdapter(plugin* p);
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);
/**
* 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:
class Impl;
Impl *m_impl;
};
}
FeatureSet process(const float *const *inputBuffers, real_time timestamp);
FeatureSet processInterleaved(const float *inputBuffer, real_time timestamp);
protected:
class Impl;
Impl* m_impl;
};
}

View File

@ -3,91 +3,60 @@
#include "vamp-hostsdk/Files.h"
namespace Vamp
namespace vamp
{
PluginHostAdapter::PluginHostAdapter(const VampPluginDescriptor *descriptor,
float inputSampleRate) :
Plugin(inputSampleRate),
m_descriptor(descriptor)
{
// std::cerr << "PluginHostAdapter::PluginHostAdapter (plugin = " << descriptor->name << ")" << std::endl;
PluginHostAdapter::PluginHostAdapter(const VampPluginDescriptor *descriptor, float inputSampleRate) : plugin(inputSampleRate), m_descriptor(descriptor)
{
m_handle = m_descriptor->instantiate(m_descriptor, inputSampleRate);
if (!m_handle) {
// std::cerr << "WARNING: PluginHostAdapter: Plugin instantiation failed for plugin " << m_descriptor->name << std::endl;
}
}
}
PluginHostAdapter::~PluginHostAdapter()
{
// std::cerr << "PluginHostAdapter::~PluginHostAdapter (plugin = " << m_descriptor->name << ")" << std::endl;
PluginHostAdapter::~PluginHostAdapter()
{
if (m_handle) m_descriptor->cleanup(m_handle);
}
}
std::vector<std::string>
PluginHostAdapter::getPluginPath()
{
std::vector<std::string> PluginHostAdapter::getPluginPath()
{
std::vector<std::string> path;
std::string envPath;
if (Files::isNonNative32Bit()) {
(void)Files::getEnvUtf8("VAMP_PATH_32", envPath);
(void)Files::getEnvUtf8("VAMP_PATH_32", envPath);
} else {
(void)Files::getEnvUtf8("VAMP_PATH", envPath);
(void)Files::getEnvUtf8("VAMP_PATH", envPath);
}
#ifdef _WIN32
#define PATH_SEPARATOR ';'
#define DEFAULT_VAMP_PATH "%ProgramFiles%\\Vamp Plugins"
#else
#define PATH_SEPARATOR ':'
#ifdef __APPLE__
#define DEFAULT_VAMP_PATH "$HOME/Library/Audio/Plug-Ins/Vamp:/Library/Audio/Plug-Ins/Vamp"
#else
#define DEFAULT_VAMP_PATH "$HOME/vamp:$HOME/.vamp:/usr/local/lib/vamp:/usr/lib/vamp"
#endif
#endif
if (envPath == "") {
envPath = DEFAULT_VAMP_PATH;
std::string home;
if (Files::getEnvUtf8("HOME", home)) {
std::string::size_type f;
while ((f = envPath.find("$HOME")) != std::string::npos &&
f < envPath.length()) {
envPath.replace(f, 5, home);
}
}
#ifdef _WIN32
std::string pfiles;
if (!Files::getEnvUtf8("ProgramFiles", pfiles)) {
pfiles = "C:\\Program Files";
}
#define PATH_SEPARATOR ':'
if (envPath == "")
{
envPath = DEFAULT_VAMP_PATH;
std::string home;
if (Files::getEnvUtf8("HOME", home))
{
std::string::size_type f;
while ((f = envPath.find("%ProgramFiles%")) != std::string::npos &&
f < envPath.length()) {
envPath.replace(f, 14, pfiles);
while ((f = envPath.find("$HOME")) != std::string::npos && f < envPath.length())
{
envPath.replace(f, 5, home);
}
#endif
}
}
std::string::size_type index = 0, newindex = 0;
while ((newindex = envPath.find(PATH_SEPARATOR, index)) < envPath.size()) {
path.push_back(envPath.substr(index, newindex - index));
index = newindex + 1;
while ((newindex = envPath.find(PATH_SEPARATOR, index)) < envPath.size())
{
path.push_back(envPath.substr(index, newindex - index));
index = newindex + 1;
}
path.push_back(envPath.substr(index));
return path;
}
}
bool
PluginHostAdapter::initialise(size_t channels,
size_t stepSize,
size_t blockSize)
{
bool PluginHostAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
if (!m_handle) return false;
return m_descriptor->initialise
(m_handle,
@ -95,100 +64,72 @@ PluginHostAdapter::initialise(size_t channels,
(unsigned int)stepSize,
(unsigned int)blockSize) ?
true : false;
}
}
void
PluginHostAdapter::reset()
{
if (!m_handle) {
// std::cerr << "PluginHostAdapter::reset: no handle" << std::endl;
return;
}
// std::cerr << "PluginHostAdapter::reset(" << m_handle << ")" << std::endl;
void PluginHostAdapter::reset()
{
m_descriptor->reset(m_handle);
}
}
PluginHostAdapter::InputDomain
PluginHostAdapter::getInputDomain() const
{
if (m_descriptor->inputDomain == vampFrequencyDomain) {
return FrequencyDomain;
} else {
return TimeDomain;
PluginHostAdapter::InputDomain PluginHostAdapter::getInputDomain() const
{
if (m_descriptor->inputDomain == vampFrequencyDomain)
{
return FrequencyDomain;
}
else
{
return TimeDomain;
}
}
}
unsigned int
PluginHostAdapter::getVampApiVersion() const
{
return m_descriptor->vampApiVersion;
}
std::string
PluginHostAdapter::getIdentifier() const
{
std::string PluginHostAdapter::get_identifier() const
{
return m_descriptor->identifier;
}
}
std::string
PluginHostAdapter::getName() const
{
std::string PluginHostAdapter::get_name() const
{
return m_descriptor->name;
}
}
std::string
PluginHostAdapter::getDescription() const
{
std::string PluginHostAdapter::get_description() const
{
return m_descriptor->description;
}
}
std::string
PluginHostAdapter::getMaker() const
{
std::string PluginHostAdapter::get_maker() const
{
return m_descriptor->maker;
}
}
int
PluginHostAdapter::getPluginVersion() const
{
return m_descriptor->pluginVersion;
}
PluginHostAdapter::parameter_descriptors PluginHostAdapter::get_parameter_descriptors() const
{
parameter_descriptors list;
for (unsigned int i = 0; i < m_descriptor->parameterCount; ++i) {
const VampParameterDescriptor *spd = m_descriptor->parameters[i];
parameter_descriptor pd;
pd.identifier = spd->identifier;
pd.name = spd->name;
pd.description = spd->description;
pd.unit = spd->unit;
pd.min_value = spd->minValue;
pd.max_value = spd->maxValue;
pd.default_value = spd->defaultValue;
pd.is_quantized = spd->isQuantized;
pd.quantize_step = spd->quantizeStep;
if (pd.is_quantized && spd->valueNames) {
for (unsigned int j = 0; spd->valueNames[j]; ++j) {
pd.value_names.push_back(spd->valueNames[j]);
}
}
list.push_back(pd);
}
return list;
}
std::string
PluginHostAdapter::getCopyright() const
{
return m_descriptor->copyright;
}
PluginHostAdapter::ParameterList
PluginHostAdapter::getParameterDescriptors() const
{
ParameterList list;
for (unsigned int i = 0; i < m_descriptor->parameterCount; ++i) {
const VampParameterDescriptor *spd = m_descriptor->parameters[i];
ParameterDescriptor pd;
pd.identifier = spd->identifier;
pd.name = spd->name;
pd.description = spd->description;
pd.unit = spd->unit;
pd.minValue = spd->minValue;
pd.maxValue = spd->maxValue;
pd.defaultValue = spd->defaultValue;
pd.isQuantized = spd->isQuantized;
pd.quantizeStep = spd->quantizeStep;
if (pd.isQuantized && spd->valueNames) {
for (unsigned int j = 0; spd->valueNames[j]; ++j) {
pd.valueNames.push_back(spd->valueNames[j]);
}
}
list.push_back(pd);
}
return list;
}
float
PluginHostAdapter::getParameter(std::string param) const
{
float PluginHostAdapter::get_parameter(std::string param) const
{
if (!m_handle) return 0.0;
for (unsigned int i = 0; i < m_descriptor->parameterCount; ++i) {
@ -198,12 +139,10 @@ PluginHostAdapter::getParameter(std::string param) const
}
return 0.0;
}
}
void
PluginHostAdapter::setParameter(std::string param,
float value)
{
void PluginHostAdapter::set_parameter(std::string param, float value)
{
if (!m_handle) return;
for (unsigned int i = 0; i < m_descriptor->parameterCount; ++i) {
@ -212,213 +151,206 @@ PluginHostAdapter::setParameter(std::string param,
return;
}
}
}
PluginHostAdapter::ProgramList
PluginHostAdapter::getPrograms() const
{
ProgramList list;
for (unsigned int i = 0; i < m_descriptor->programCount; ++i) {
list.push_back(m_descriptor->programs[i]);
}
return list;
}
std::string
PluginHostAdapter::getCurrentProgram() const
{
if (!m_handle) return "";
int pn = m_descriptor->getCurrentProgram(m_handle);
if (pn < (int)m_descriptor->programCount) {
return m_descriptor->programs[pn];
} else {
return "";
}
}
void
PluginHostAdapter::selectProgram(std::string program)
{
if (!m_handle) return;
for (unsigned int i = 0; i < m_descriptor->programCount; ++i) {
if (program == m_descriptor->programs[i]) {
m_descriptor->selectProgram(m_handle, i);
return;
}
}
}
size_t
PluginHostAdapter::getPreferredStepSize() const
{
if (!m_handle) return 0;
return m_descriptor->getPreferredStepSize(m_handle);
}
size_t
PluginHostAdapter::getPreferredBlockSize() const
{
if (!m_handle) return 0;
return m_descriptor->getPreferredBlockSize(m_handle);
}
size_t
PluginHostAdapter::getMinChannelCount() const
{
if (!m_handle) return 0;
return m_descriptor->getMinChannelCount(m_handle);
}
size_t
PluginHostAdapter::getMaxChannelCount() const
{
if (!m_handle) return 0;
return m_descriptor->getMaxChannelCount(m_handle);
}
PluginHostAdapter::OutputList
PluginHostAdapter::getOutputDescriptors() const
{
OutputList list;
if (!m_handle) {
// std::cerr << "PluginHostAdapter::getOutputDescriptors: no handle " << std::endl;
return list;
}
unsigned int count = m_descriptor->getOutputCount(m_handle);
for (unsigned int i = 0; i < count; ++i) {
VampOutputDescriptor *sd = m_descriptor->getOutputDescriptor(m_handle, i);
OutputDescriptor d;
d.identifier = sd->identifier;
d.name = sd->name;
d.description = sd->description;
d.unit = sd->unit;
d.hasFixedBinCount = sd->hasFixedBinCount;
d.binCount = sd->binCount;
if (d.hasFixedBinCount && sd->binNames) {
for (unsigned int j = 0; j < sd->binCount; ++j) {
d.binNames.push_back(sd->binNames[j] ? sd->binNames[j] : "");
}
}
d.hasKnownExtents = sd->hasKnownExtents;
d.minValue = sd->minValue;
d.maxValue = sd->maxValue;
d.isQuantized = sd->isQuantized;
d.quantizeStep = sd->quantizeStep;
switch (sd->sampleType) {
case vampOneSamplePerStep:
d.sampleType = OutputDescriptor::OneSamplePerStep; break;
case vampFixedSampleRate:
d.sampleType = OutputDescriptor::FixedSampleRate; break;
case vampVariableSampleRate:
d.sampleType = OutputDescriptor::VariableSampleRate; break;
}
d.sampleRate = sd->sampleRate;
if (m_descriptor->vampApiVersion >= 2) {
d.hasDuration = sd->hasDuration;
} else {
d.hasDuration = false;
}
list.push_back(d);
m_descriptor->releaseOutputDescriptor(sd);
}
return list;
}
PluginHostAdapter::FeatureSet
PluginHostAdapter::process(const float *const *inputBuffers,
RealTime timestamp)
{
FeatureSet fs;
if (!m_handle) return fs;
int sec = timestamp.sec;
int nsec = timestamp.nsec;
VampFeatureList *features = m_descriptor->process(m_handle,
inputBuffers,
sec, nsec);
convertFeatures(features, fs);
m_descriptor->releaseFeatureSet(features);
return fs;
}
PluginHostAdapter::FeatureSet
PluginHostAdapter::getRemainingFeatures()
{
FeatureSet fs;
if (!m_handle) return fs;
VampFeatureList *features = m_descriptor->getRemainingFeatures(m_handle);
convertFeatures(features, fs);
m_descriptor->releaseFeatureSet(features);
return fs;
}
void
PluginHostAdapter::convertFeatures(VampFeatureList *features,
FeatureSet &fs)
{
if (!features) return;
unsigned int outputs = m_descriptor->getOutputCount(m_handle);
for (unsigned int i = 0; i < outputs; ++i) {
VampFeatureList &list = features[i];
if (list.featureCount > 0) {
Feature feature;
feature.values.reserve(list.features[0].v1.valueCount);
for (unsigned int j = 0; j < list.featureCount; ++j) {
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);
}
for (unsigned int k = 0; k < list.features[j].v1.valueCount; ++k) {
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);
if (list.features[j].v1.valueCount > 0) {
feature.values.clear();
}
if (list.features[j].v1.label) {
feature.label = "";
}
}
}
}
}
}
PluginHostAdapter::programs PluginHostAdapter::get_programs() const
{
programs list;
for (unsigned int i = 0; i < m_descriptor->programCount; ++i) {
list.push_back(m_descriptor->programs[i]);
}
return list;
}
std::string PluginHostAdapter::get_current_program() const
{
if (!m_handle) return "";
int pn = m_descriptor->getCurrentProgram(m_handle);
if (pn < (int)m_descriptor->programCount) {
return m_descriptor->programs[pn];
} else {
return "";
}
}
void PluginHostAdapter::select_program(std::string program)
{
if (!m_handle) return;
for (unsigned int i = 0; i < m_descriptor->programCount; ++i) {
if (program == m_descriptor->programs[i]) {
m_descriptor->selectProgram(m_handle, i);
return;
}
}
}
size_t PluginHostAdapter::getPreferredStepSize() const
{
if (!m_handle) return 0;
return m_descriptor->getPreferredStepSize(m_handle);
}
size_t PluginHostAdapter::getPreferredBlockSize() const
{
if (!m_handle) return 0;
return m_descriptor->getPreferredBlockSize(m_handle);
}
size_t PluginHostAdapter::getMinChannelCount() const
{
if (!m_handle) return 0;
return m_descriptor->getMinChannelCount(m_handle);
}
size_t
PluginHostAdapter::getMaxChannelCount() const
{
if (!m_handle) return 0;
return m_descriptor->getMaxChannelCount(m_handle);
}
PluginHostAdapter::OutputList
PluginHostAdapter::getOutputDescriptors() const
{
OutputList list;
if (!m_handle) {
// std::cerr << "PluginHostAdapter::getOutputDescriptors: no handle " << std::endl;
return list;
}
unsigned int count = m_descriptor->getOutputCount(m_handle);
for (unsigned int i = 0; i < count; ++i) {
VampOutputDescriptor *sd = m_descriptor->getOutputDescriptor(m_handle, i);
OutputDescriptor d;
d.identifier = sd->identifier;
d.name = sd->name;
d.description = sd->description;
d.unit = sd->unit;
d.hasFixedBinCount = sd->hasFixedBinCount;
d.binCount = sd->binCount;
if (d.hasFixedBinCount && sd->binNames) {
for (unsigned int j = 0; j < sd->binCount; ++j) {
d.binNames.push_back(sd->binNames[j] ? sd->binNames[j] : "");
}
}
d.hasKnownExtents = sd->hasKnownExtents;
d.minValue = sd->minValue;
d.maxValue = sd->maxValue;
d.isQuantized = sd->isQuantized;
d.quantizeStep = sd->quantizeStep;
switch (sd->sampleType) {
case vampOneSamplePerStep:
d.sampleType = OutputDescriptor::OneSamplePerStep; break;
case vampFixedSampleRate:
d.sampleType = OutputDescriptor::FixedSampleRate; break;
case vampVariableSampleRate:
d.sampleType = OutputDescriptor::VariableSampleRate; break;
}
d.sampleRate = sd->sampleRate;
if (m_descriptor->vampApiVersion >= 2) {
d.hasDuration = sd->hasDuration;
} else {
d.hasDuration = false;
}
list.push_back(d);
m_descriptor->releaseOutputDescriptor(sd);
}
return list;
}
PluginHostAdapter::FeatureSet
PluginHostAdapter::process(const float *const *inputBuffers,
real_time timestamp)
{
FeatureSet fs;
if (!m_handle) return fs;
int sec = timestamp.sec;
int nsec = timestamp.nsec;
VampFeatureList *features = m_descriptor->process(m_handle,
inputBuffers,
sec, nsec);
convertFeatures(features, fs);
m_descriptor->releaseFeatureSet(features);
return fs;
}
PluginHostAdapter::FeatureSet
PluginHostAdapter::getRemainingFeatures()
{
FeatureSet fs;
if (!m_handle) return fs;
VampFeatureList *features = m_descriptor->getRemainingFeatures(m_handle);
convertFeatures(features, fs);
m_descriptor->releaseFeatureSet(features);
return fs;
}
void
PluginHostAdapter::convertFeatures(VampFeatureList *features,
FeatureSet &fs)
{
if (!features) return;
unsigned int outputs = m_descriptor->getOutputCount(m_handle);
for (unsigned int i = 0; i < outputs; ++i) {
VampFeatureList &list = features[i];
if (list.featureCount > 0) {
Feature feature;
feature.values.reserve(list.features[0].v1.valueCount);
for (unsigned int j = 0; j < list.featureCount; ++j) {
feature.hasTimestamp = list.features[j].v1.hasTimestamp;
feature.timestamp = real_time(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 = real_time(list.features[j2].v2.durationSec,
list.features[j2].v2.durationNsec);
}
for (unsigned int k = 0; k < list.features[j].v1.valueCount; ++k) {
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);
if (list.features[j].v1.valueCount > 0) {
feature.values.clear();
}
if (list.features[j].v1.label) {
feature.label = "";
}
}
}
}
}
}

View File

@ -4,72 +4,50 @@
#include "vamp.h"
#include <vector>
namespace Vamp {
/**
* \class PluginHostAdapter PluginHostAdapter.h <vamp-hostsdk/PluginHostAdapter.h>
*
* PluginHostAdapter is a wrapper class that a Vamp host can use to
* make the C-language VampPluginDescriptor object appear as a C++
* Vamp::Plugin object.
*
* The Vamp API is defined in vamp/vamp.h as a C API. The C++ objects
* used for convenience by plugins and hosts actually communicate
* using the C low-level API, but the details of this communication
* are handled seamlessly by the Vamp SDK implementation provided the
* plugin and host use the proper C++ wrapper objects.
*
* See also PluginAdapter, the plugin-side wrapper that makes a C++
* plugin object available using the C query API.
*/
class PluginHostAdapter : public Plugin
namespace vamp
{
public:
PluginHostAdapter(const VampPluginDescriptor *descriptor,
float inputSampleRate);
virtual ~PluginHostAdapter();
static std::vector<std::string> getPluginPath();
class PluginHostAdapter : public plugin
{
public:
PluginHostAdapter(const VampPluginDescriptor* descriptor, float inputSampleRate);
virtual ~PluginHostAdapter();
static std::vector<std::string> getPluginPath();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
bool initialise(size_t channels, size_t stepSize, size_t blockSize) override;
void reset() override;
InputDomain getInputDomain() const;
InputDomain getInputDomain() const override;
unsigned int getVampApiVersion() const;
std::string getIdentifier() const;
std::string getName() const;
std::string getDescription() const;
std::string getMaker() const;
int getPluginVersion() const;
std::string getCopyright() const;
std::string get_identifier() const override;
std::string get_name() const override;
std::string get_description() const override;
std::string get_maker() const override;
ParameterList getParameterDescriptors() const;
float getParameter(std::string) const;
void setParameter(std::string, float);
parameter_descriptors get_parameter_descriptors() const override;
float get_parameter(std::string) const override;
void set_parameter(std::string, float) override;
ProgramList getPrograms() const;
std::string getCurrentProgram() const;
void selectProgram(std::string);
programs get_programs() const override;
std::string get_current_program() const override;
void select_program(std::string) override;
size_t getPreferredStepSize() const;
size_t getPreferredBlockSize() const;
size_t getPreferredStepSize() const override;
size_t getPreferredBlockSize() const override;
size_t getMinChannelCount() const;
size_t getMaxChannelCount() const;
size_t getMinChannelCount() const override;
size_t getMaxChannelCount() const override;
OutputList getOutputDescriptors() const;
OutputList getOutputDescriptors() const override;
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet process(const float *const *inputBuffers, real_time timestamp) override;
FeatureSet getRemainingFeatures();
FeatureSet getRemainingFeatures() override;
protected:
void convertFeatures(VampFeatureList *, FeatureSet &);
const VampPluginDescriptor *m_descriptor;
VampPluginHandle m_handle;
};
protected:
void convertFeatures(VampFeatureList *, FeatureSet &);
const VampPluginDescriptor *m_descriptor;
VampPluginHandle m_handle;
};
}

View File

@ -1,482 +1,472 @@
#include "vamp-hostsdk/PluginInputDomainAdapter.h"
#include "vamp-hostsdk/Window.h"
#include "vamp-sdk/ext/vamp_kiss_fft.h"
#include "vamp-sdk/ext/vamp_kiss_fftr.h"
#include <cmath>
#include "Window.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
namespace Vamp {
namespace HostExt {
class PluginInputDomainAdapter::Impl
namespace vamp::host
{
public:
Impl(Plugin *plugin, float inputSampleRate);
~Impl();
class PluginInputDomainAdapter::Impl
{
public:
Impl(plugin* p, float inputSampleRate);
~Impl();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
size_t getPreferredStepSize() const;
size_t getPreferredBlockSize() const;
FeatureSet process(const float *const *inputBuffers, real_time timestamp);
void setProcessTimestampMethod(ProcessTimestampMethod m);
ProcessTimestampMethod getProcessTimestampMethod() const;
real_time getTimestampAdjustment() const;
WindowType getWindowType() const;
void setWindowType(WindowType type);
protected:
plugin* m_plugin;
float m_inputSampleRate;
int m_channels;
int m_stepSize;
int m_blockSize;
float **m_freqbuf;
vamp_kiss_fft_scalar *m_ri;
WindowType m_windowType;
typedef Window<vamp_kiss_fft_scalar> W;
W *m_window;
ProcessTimestampMethod m_method;
int m_processCount;
float **m_shiftBuffers;
vamp_kiss_fftr_cfg m_cfg;
vamp_kiss_fft_cpx *m_cbuf;
FeatureSet processShiftingTimestamp(const float *const *inputBuffers, real_time timestamp);
FeatureSet processShiftingData(const float *const *inputBuffers, real_time timestamp);
size_t makeBlockSizeAcceptable(size_t) const;
W::WindowType convertType(WindowType t) const;
};
PluginInputDomainAdapter::PluginInputDomainAdapter(plugin* p) :
PluginWrapper(p)
{
m_impl = new Impl(p, m_inputSampleRate);
}
PluginInputDomainAdapter::~PluginInputDomainAdapter()
{
delete m_impl;
}
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
bool
PluginInputDomainAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
return m_impl->initialise(channels, stepSize, blockSize);
}
size_t getPreferredStepSize() const;
size_t getPreferredBlockSize() const;
void
PluginInputDomainAdapter::reset()
{
m_impl->reset();
}
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
plugin::InputDomain PluginInputDomainAdapter::getInputDomain() const
{
return TimeDomain;
}
void setProcessTimestampMethod(ProcessTimestampMethod m);
ProcessTimestampMethod getProcessTimestampMethod() const;
RealTime getTimestampAdjustment() const;
size_t
PluginInputDomainAdapter::getPreferredStepSize() const
{
return m_impl->getPreferredStepSize();
}
WindowType getWindowType() const;
void setWindowType(WindowType type);
size_t
PluginInputDomainAdapter::getPreferredBlockSize() const
{
return m_impl->getPreferredBlockSize();
}
protected:
Plugin *m_plugin;
float m_inputSampleRate;
int m_channels;
int m_stepSize;
int m_blockSize;
float **m_freqbuf;
vamp_kiss_fft_scalar *m_ri;
plugin::FeatureSet
PluginInputDomainAdapter::process(const float *const *inputBuffers, real_time timestamp)
{
return m_impl->process(inputBuffers, timestamp);
}
WindowType m_windowType;
typedef Window<vamp_kiss_fft_scalar> W;
W *m_window;
void
PluginInputDomainAdapter::setProcessTimestampMethod(ProcessTimestampMethod m)
{
m_impl->setProcessTimestampMethod(m);
}
ProcessTimestampMethod m_method;
int m_processCount;
float **m_shiftBuffers;
PluginInputDomainAdapter::ProcessTimestampMethod
PluginInputDomainAdapter::getProcessTimestampMethod() const
{
return m_impl->getProcessTimestampMethod();
}
vamp_kiss_fftr_cfg m_cfg;
vamp_kiss_fft_cpx *m_cbuf;
real_time
PluginInputDomainAdapter::getTimestampAdjustment() const
{
return m_impl->getTimestampAdjustment();
}
FeatureSet processShiftingTimestamp(const float *const *inputBuffers, RealTime timestamp);
FeatureSet processShiftingData(const float *const *inputBuffers, RealTime timestamp);
PluginInputDomainAdapter::WindowType
PluginInputDomainAdapter::getWindowType() const
{
return m_impl->getWindowType();
}
size_t makeBlockSizeAcceptable(size_t) const;
W::WindowType convertType(WindowType t) const;
};
PluginInputDomainAdapter::PluginInputDomainAdapter(Plugin *plugin) :
PluginWrapper(plugin)
{
m_impl = new Impl(plugin, m_inputSampleRate);
}
PluginInputDomainAdapter::~PluginInputDomainAdapter()
{
delete m_impl;
}
bool
PluginInputDomainAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
return m_impl->initialise(channels, stepSize, blockSize);
}
void
PluginInputDomainAdapter::reset()
{
m_impl->reset();
}
Plugin::InputDomain
PluginInputDomainAdapter::getInputDomain() const
{
return TimeDomain;
}
size_t
PluginInputDomainAdapter::getPreferredStepSize() const
{
return m_impl->getPreferredStepSize();
}
size_t
PluginInputDomainAdapter::getPreferredBlockSize() const
{
return m_impl->getPreferredBlockSize();
}
Plugin::FeatureSet
PluginInputDomainAdapter::process(const float *const *inputBuffers, RealTime timestamp)
{
return m_impl->process(inputBuffers, timestamp);
}
void
PluginInputDomainAdapter::setProcessTimestampMethod(ProcessTimestampMethod m)
{
m_impl->setProcessTimestampMethod(m);
}
PluginInputDomainAdapter::ProcessTimestampMethod
PluginInputDomainAdapter::getProcessTimestampMethod() const
{
return m_impl->getProcessTimestampMethod();
}
RealTime
PluginInputDomainAdapter::getTimestampAdjustment() const
{
return m_impl->getTimestampAdjustment();
}
PluginInputDomainAdapter::WindowType
PluginInputDomainAdapter::getWindowType() const
{
return m_impl->getWindowType();
}
void
PluginInputDomainAdapter::setWindowType(WindowType w)
{
m_impl->setWindowType(w);
}
void
PluginInputDomainAdapter::setWindowType(WindowType w)
{
m_impl->setWindowType(w);
}
PluginInputDomainAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) :
m_plugin(plugin),
m_inputSampleRate(inputSampleRate),
m_channels(0),
m_stepSize(0),
m_blockSize(0),
m_freqbuf(0),
m_ri(0),
m_windowType(HanningWindow),
m_window(0),
m_method(ShiftTimestamp),
m_processCount(0),
m_shiftBuffers(0),
m_cfg(0),
m_cbuf(0)
{
}
PluginInputDomainAdapter::Impl::Impl(plugin* p, float inputSampleRate) :
m_plugin(p),
m_inputSampleRate(inputSampleRate),
m_channels(0),
m_stepSize(0),
m_blockSize(0),
m_freqbuf(0),
m_ri(0),
m_windowType(HanningWindow),
m_window(0),
m_method(ShiftTimestamp),
m_processCount(0),
m_shiftBuffers(0),
m_cfg(0),
m_cbuf(0)
{
}
PluginInputDomainAdapter::Impl::~Impl()
{
// the adapter will delete the plugin
PluginInputDomainAdapter::Impl::~Impl()
{
// the adapter will delete the plugin
if (m_shiftBuffers) {
for (int c = 0; c < m_channels; ++c) {
delete[] m_shiftBuffers[c];
}
delete[] m_shiftBuffers;
}
if (m_shiftBuffers) {
for (int c = 0; c < m_channels; ++c) {
delete[] m_shiftBuffers[c];
}
delete[] m_shiftBuffers;
}
if (m_channels > 0) {
for (int c = 0; c < m_channels; ++c) {
delete[] m_freqbuf[c];
}
delete[] m_freqbuf;
delete[] m_ri;
if (m_cfg) {
vamp_kiss_fftr_free(m_cfg);
m_cfg = 0;
delete[] m_cbuf;
m_cbuf = 0;
}
delete m_window;
}
}
if (m_channels > 0) {
for (int c = 0; c < m_channels; ++c) {
delete[] m_freqbuf[c];
}
delete[] m_freqbuf;
delete[] m_ri;
if (m_cfg) {
vamp_kiss_fftr_free(m_cfg);
m_cfg = 0;
delete[] m_cbuf;
m_cbuf = 0;
}
delete m_window;
}
}
// for some visual studii apparently
// for some visual studii apparently
#ifndef M_PI
#define M_PI 3.14159265358979232846
#endif
bool
PluginInputDomainAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
if (m_plugin->getInputDomain() == TimeDomain) {
bool
PluginInputDomainAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
if (m_plugin->getInputDomain() == TimeDomain) {
m_stepSize = int(stepSize);
m_blockSize = int(blockSize);
m_channels = int(channels);
m_stepSize = int(stepSize);
m_blockSize = int(blockSize);
m_channels = int(channels);
return m_plugin->initialise(channels, stepSize, blockSize);
}
return m_plugin->initialise(channels, stepSize, blockSize);
}
if (blockSize < 2) {
std::cerr << "ERROR: PluginInputDomainAdapter::initialise: blocksize < 2 not supported" << std::endl;
return false;
}
if (blockSize % 2) {
std::cerr << "ERROR: PluginInputDomainAdapter::initialise: odd blocksize " << blockSize << " not supported" << std::endl;
return false;
}
if (blockSize < 2) {
std::cerr << "ERROR: PluginInputDomainAdapter::initialise: blocksize < 2 not supported" << std::endl;
return false;
}
if (blockSize % 2) {
std::cerr << "ERROR: PluginInputDomainAdapter::initialise: odd blocksize " << blockSize << " not supported" << std::endl;
return false;
}
if (m_channels > 0) {
for (int c = 0; c < m_channels; ++c) {
delete[] m_freqbuf[c];
}
delete[] m_freqbuf;
delete[] m_ri;
if (m_cfg) {
vamp_kiss_fftr_free(m_cfg);
m_cfg = 0;
delete[] m_cbuf;
m_cbuf = 0;
}
delete m_window;
}
if (m_channels > 0) {
for (int c = 0; c < m_channels; ++c) {
delete[] m_freqbuf[c];
}
delete[] m_freqbuf;
delete[] m_ri;
if (m_cfg) {
vamp_kiss_fftr_free(m_cfg);
m_cfg = 0;
delete[] m_cbuf;
m_cbuf = 0;
}
delete m_window;
}
m_stepSize = int(stepSize);
m_blockSize = int(blockSize);
m_channels = int(channels);
m_stepSize = int(stepSize);
m_blockSize = int(blockSize);
m_channels = int(channels);
m_freqbuf = new float *[m_channels];
for (int c = 0; c < m_channels; ++c) {
m_freqbuf[c] = new float[m_blockSize + 2];
}
m_ri = new vamp_kiss_fft_scalar[m_blockSize];
m_freqbuf = new float *[m_channels];
for (int c = 0; c < m_channels; ++c) {
m_freqbuf[c] = new float[m_blockSize + 2];
}
m_ri = new vamp_kiss_fft_scalar[m_blockSize];
m_window = new W(convertType(m_windowType), m_blockSize);
m_window = new W(convertType(m_windowType), m_blockSize);
m_cfg = vamp_kiss_fftr_alloc(m_blockSize, false, 0, 0);
m_cbuf = new vamp_kiss_fft_cpx[m_blockSize/2+1];
m_cfg = vamp_kiss_fftr_alloc(m_blockSize, false, 0, 0);
m_cbuf = new vamp_kiss_fft_cpx[m_blockSize/2+1];
m_processCount = 0;
m_processCount = 0;
return m_plugin->initialise(channels, stepSize, m_blockSize);
}
void
PluginInputDomainAdapter::Impl::reset()
{
m_processCount = 0;
m_plugin->reset();
}
size_t
PluginInputDomainAdapter::Impl::getPreferredStepSize() const
{
size_t step = m_plugin->getPreferredStepSize();
if (step == 0 && (m_plugin->getInputDomain() == FrequencyDomain)) {
step = getPreferredBlockSize() / 2;
}
return step;
}
size_t
PluginInputDomainAdapter::Impl::getPreferredBlockSize() const
{
size_t block = m_plugin->getPreferredBlockSize();
if (m_plugin->getInputDomain() == FrequencyDomain) {
if (block == 0) {
block = 1024;
} else {
block = makeBlockSizeAcceptable(block);
}
}
return block;
}
size_t
PluginInputDomainAdapter::Impl::makeBlockSizeAcceptable(size_t blockSize) const
{
if (blockSize < 2) {
std::cerr << "WARNING: PluginInputDomainAdapter::initialise: blocksize < 2 not" << std::endl
<< "supported, increasing from " << blockSize << " to 2" << std::endl;
blockSize = 2;
} else if (blockSize % 2) {
std::cerr << "WARNING: PluginInputDomainAdapter::initialise: odd blocksize not" << std::endl
<< "supported, increasing from " << blockSize << " to " << (blockSize+1) << std::endl;
blockSize = blockSize+1;
}
return blockSize;
}
RealTime
PluginInputDomainAdapter::Impl::getTimestampAdjustment() const
{
if (m_plugin->getInputDomain() == TimeDomain) {
return RealTime::zeroTime;
} else if (m_method == ShiftData || m_method == NoShift) {
return RealTime::zeroTime;
} else {
return RealTime::frame2RealTime
(m_blockSize/2, int(m_inputSampleRate + 0.5));
}
}
void
PluginInputDomainAdapter::Impl::setProcessTimestampMethod(ProcessTimestampMethod m)
{
m_method = m;
}
PluginInputDomainAdapter::ProcessTimestampMethod
PluginInputDomainAdapter::Impl::getProcessTimestampMethod() const
{
return m_method;
}
void
PluginInputDomainAdapter::Impl::setWindowType(WindowType t)
{
if (m_windowType == t) return;
m_windowType = t;
if (m_window) {
delete m_window;
m_window = new W(convertType(m_windowType), m_blockSize);
}
}
PluginInputDomainAdapter::WindowType
PluginInputDomainAdapter::Impl::getWindowType() const
{
return m_windowType;
}
PluginInputDomainAdapter::Impl::W::WindowType
PluginInputDomainAdapter::Impl::convertType(WindowType t) const
{
switch (t) {
case RectangularWindow:
return W::RectangularWindow;
case BartlettWindow:
return W::BartlettWindow;
case HammingWindow:
return W::HammingWindow;
case HanningWindow:
return W::HanningWindow;
case BlackmanWindow:
return W::BlackmanWindow;
case NuttallWindow:
return W::NuttallWindow;
case BlackmanHarrisWindow:
return W::BlackmanHarrisWindow;
default:
return W::HanningWindow;
}
}
Plugin::FeatureSet
PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers,
RealTime timestamp)
{
if (m_plugin->getInputDomain() == TimeDomain) {
return m_plugin->process(inputBuffers, timestamp);
}
if (m_method == ShiftTimestamp || m_method == NoShift) {
return processShiftingTimestamp(inputBuffers, timestamp);
} else {
return processShiftingData(inputBuffers, timestamp);
}
}
Plugin::FeatureSet
PluginInputDomainAdapter::Impl::processShiftingTimestamp(const float *const *inputBuffers,
RealTime timestamp)
{
unsigned int roundedRate = 1;
if (m_inputSampleRate > 0.f) {
roundedRate = (unsigned int)round(m_inputSampleRate);
}
if (m_method == ShiftTimestamp) {
// we may need to add one nsec if timestamp +
// getTimestampAdjustment() rounds down
timestamp = timestamp + getTimestampAdjustment();
RealTime nsec(0, 1);
if (RealTime::realTime2Frame(timestamp, roundedRate) <
RealTime::realTime2Frame(timestamp + nsec, roundedRate)) {
timestamp = timestamp + nsec;
}
}
for (int c = 0; c < m_channels; ++c) {
m_window->cut(inputBuffers[c], m_ri);
for (int i = 0; i < m_blockSize/2; ++i) {
// FFT shift
vamp_kiss_fft_scalar value = m_ri[i];
m_ri[i] = m_ri[i + m_blockSize/2];
m_ri[i + m_blockSize/2] = value;
}
vamp_kiss_fftr(m_cfg, m_ri, m_cbuf);
for (int i = 0; i <= m_blockSize/2; ++i) {
m_freqbuf[c][i * 2] = float(m_cbuf[i].r);
m_freqbuf[c][i * 2 + 1] = float(m_cbuf[i].i);
}
}
return m_plugin->process(m_freqbuf, timestamp);
}
Plugin::FeatureSet
PluginInputDomainAdapter::Impl::processShiftingData(const float *const *inputBuffers,
RealTime timestamp)
{
if (m_processCount == 0) {
if (!m_shiftBuffers) {
m_shiftBuffers = new float *[m_channels];
for (int c = 0; c < m_channels; ++c) {
m_shiftBuffers[c] = new float[m_blockSize + m_blockSize/2];
}
}
for (int c = 0; c < m_channels; ++c) {
for (int i = 0; i < m_blockSize + m_blockSize/2; ++i) {
m_shiftBuffers[c][i] = 0.f;
}
}
}
for (int c = 0; c < m_channels; ++c) {
for (int i = m_stepSize; i < m_blockSize + m_blockSize/2; ++i) {
m_shiftBuffers[c][i - m_stepSize] = m_shiftBuffers[c][i];
}
for (int i = 0; i < m_blockSize; ++i) {
m_shiftBuffers[c][i + m_blockSize/2] = inputBuffers[c][i];
}
}
for (int c = 0; c < m_channels; ++c) {
m_window->cut(m_shiftBuffers[c], m_ri);
for (int i = 0; i < m_blockSize/2; ++i) {
// FFT shift
vamp_kiss_fft_scalar value = m_ri[i];
m_ri[i] = m_ri[i + m_blockSize/2];
m_ri[i + m_blockSize/2] = value;
}
vamp_kiss_fftr(m_cfg, m_ri, m_cbuf);
for (int i = 0; i <= m_blockSize/2; ++i) {
m_freqbuf[c][i * 2] = float(m_cbuf[i].r);
m_freqbuf[c][i * 2 + 1] = float(m_cbuf[i].i);
}
}
++m_processCount;
return m_plugin->process(m_freqbuf, timestamp);
}
}
return m_plugin->initialise(channels, stepSize, m_blockSize);
}
void
PluginInputDomainAdapter::Impl::reset()
{
m_processCount = 0;
m_plugin->reset();
}
size_t
PluginInputDomainAdapter::Impl::getPreferredStepSize() const
{
size_t step = m_plugin->getPreferredStepSize();
if (step == 0 && (m_plugin->getInputDomain() == FrequencyDomain)) {
step = getPreferredBlockSize() / 2;
}
return step;
}
size_t
PluginInputDomainAdapter::Impl::getPreferredBlockSize() const
{
size_t block = m_plugin->getPreferredBlockSize();
if (m_plugin->getInputDomain() == FrequencyDomain) {
if (block == 0) {
block = 1024;
} else {
block = makeBlockSizeAcceptable(block);
}
}
return block;
}
size_t
PluginInputDomainAdapter::Impl::makeBlockSizeAcceptable(size_t blockSize) const
{
if (blockSize < 2) {
std::cerr << "WARNING: PluginInputDomainAdapter::initialise: blocksize < 2 not" << std::endl
<< "supported, increasing from " << blockSize << " to 2" << std::endl;
blockSize = 2;
} else if (blockSize % 2) {
std::cerr << "WARNING: PluginInputDomainAdapter::initialise: odd blocksize not" << std::endl
<< "supported, increasing from " << blockSize << " to " << (blockSize+1) << std::endl;
blockSize = blockSize+1;
}
return blockSize;
}
real_time PluginInputDomainAdapter::Impl::getTimestampAdjustment() const
{
if (m_plugin->getInputDomain() == TimeDomain) {
return real_time::zero_time;
} else if (m_method == ShiftData || m_method == NoShift) {
return real_time::zero_time;
} else {
return real_time::f2rt(m_blockSize/2, int(m_inputSampleRate + 0.5));
}
}
void
PluginInputDomainAdapter::Impl::setProcessTimestampMethod(ProcessTimestampMethod m)
{
m_method = m;
}
PluginInputDomainAdapter::ProcessTimestampMethod
PluginInputDomainAdapter::Impl::getProcessTimestampMethod() const
{
return m_method;
}
void
PluginInputDomainAdapter::Impl::setWindowType(WindowType t)
{
if (m_windowType == t) return;
m_windowType = t;
if (m_window) {
delete m_window;
m_window = new W(convertType(m_windowType), m_blockSize);
}
}
PluginInputDomainAdapter::WindowType
PluginInputDomainAdapter::Impl::getWindowType() const
{
return m_windowType;
}
PluginInputDomainAdapter::Impl::W::WindowType
PluginInputDomainAdapter::Impl::convertType(WindowType t) const
{
switch (t) {
case RectangularWindow:
return W::RectangularWindow;
case BartlettWindow:
return W::BartlettWindow;
case HammingWindow:
return W::HammingWindow;
case HanningWindow:
return W::HanningWindow;
case BlackmanWindow:
return W::BlackmanWindow;
case NuttallWindow:
return W::NuttallWindow;
case BlackmanHarrisWindow:
return W::BlackmanHarrisWindow;
default:
return W::HanningWindow;
}
}
plugin::FeatureSet
PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers,
real_time timestamp)
{
if (m_plugin->getInputDomain() == TimeDomain) {
return m_plugin->process(inputBuffers, timestamp);
}
if (m_method == ShiftTimestamp || m_method == NoShift) {
return processShiftingTimestamp(inputBuffers, timestamp);
} else {
return processShiftingData(inputBuffers, timestamp);
}
}
plugin::FeatureSet
PluginInputDomainAdapter::Impl::processShiftingTimestamp(const float *const *inputBuffers,
real_time timestamp)
{
unsigned int roundedRate = 1;
if (m_inputSampleRate > 0.f) {
roundedRate = (unsigned int)round(m_inputSampleRate);
}
if (m_method == ShiftTimestamp) {
// we may need to add one nsec if timestamp +
// getTimestampAdjustment() rounds down
timestamp = timestamp + getTimestampAdjustment();
real_time nsec(0, 1);
if (real_time::rt2f(timestamp, roundedRate) <
real_time::rt2f(timestamp + nsec, roundedRate)) {
timestamp = timestamp + nsec;
}
}
for (int c = 0; c < m_channels; ++c) {
m_window->cut(inputBuffers[c], m_ri);
for (int i = 0; i < m_blockSize/2; ++i) {
// FFT shift
vamp_kiss_fft_scalar value = m_ri[i];
m_ri[i] = m_ri[i + m_blockSize/2];
m_ri[i + m_blockSize/2] = value;
}
vamp_kiss_fftr(m_cfg, m_ri, m_cbuf);
for (int i = 0; i <= m_blockSize/2; ++i) {
m_freqbuf[c][i * 2] = float(m_cbuf[i].r);
m_freqbuf[c][i * 2 + 1] = float(m_cbuf[i].i);
}
}
return m_plugin->process(m_freqbuf, timestamp);
}
plugin::FeatureSet
PluginInputDomainAdapter::Impl::processShiftingData(const float *const *inputBuffers,
real_time timestamp)
{
if (m_processCount == 0) {
if (!m_shiftBuffers) {
m_shiftBuffers = new float *[m_channels];
for (int c = 0; c < m_channels; ++c) {
m_shiftBuffers[c] = new float[m_blockSize + m_blockSize/2];
}
}
for (int c = 0; c < m_channels; ++c) {
for (int i = 0; i < m_blockSize + m_blockSize/2; ++i) {
m_shiftBuffers[c][i] = 0.f;
}
}
}
for (int c = 0; c < m_channels; ++c) {
for (int i = m_stepSize; i < m_blockSize + m_blockSize/2; ++i) {
m_shiftBuffers[c][i - m_stepSize] = m_shiftBuffers[c][i];
}
for (int i = 0; i < m_blockSize; ++i) {
m_shiftBuffers[c][i + m_blockSize/2] = inputBuffers[c][i];
}
}
for (int c = 0; c < m_channels; ++c) {
m_window->cut(m_shiftBuffers[c], m_ri);
for (int i = 0; i < m_blockSize/2; ++i) {
// FFT shift
vamp_kiss_fft_scalar value = m_ri[i];
m_ri[i] = m_ri[i + m_blockSize/2];
m_ri[i + m_blockSize/2] = value;
}
vamp_kiss_fftr(m_cfg, m_ri, m_cbuf);
for (int i = 0; i <= m_blockSize/2; ++i) {
m_freqbuf[c][i * 2] = float(m_cbuf[i].r);
m_freqbuf[c][i * 2 + 1] = float(m_cbuf[i].i);
}
}
++m_processCount;
return m_plugin->process(m_freqbuf, timestamp);
}
}

View File

@ -2,190 +2,58 @@
#include "vamp-hostsdk/PluginWrapper.h"
namespace Vamp {
namespace HostExt {
/**
* \class PluginInputDomainAdapter PluginInputDomainAdapter.h <vamp-hostsdk/PluginInputDomainAdapter.h>
*
* PluginInputDomainAdapter is a Vamp plugin adapter that converts
* time-domain input into frequency-domain input for plugins that need
* it. This permits a host to use time- and frequency-domain plugins
* interchangeably without needing to handle the conversion itself.
*
* This adapter uses a basic windowed FFT (using Hann window by
* default) that supports power-of-two block sizes only. If a
* frequency domain plugin requests a non-power-of-two blocksize, the
* adapter will adjust it to a nearby power of two instead. Thus,
* getPreferredBlockSize() will always return a power of two if the
* wrapped plugin is a frequency domain one. If the plugin doesn't
* accept the adjusted power of two block size, initialise() will
* fail.
*
* The adapter provides no way for the host to discover whether the
* underlying plugin is actually a time or frequency domain plugin
* (except that if the preferred block size is not a power of two, it
* must be a time domain plugin).
*
* The FFT implementation is simple and self-contained, but unlikely
* to be the fastest available: a host can usually do better if it
* cares enough.
*
* The window shape for the FFT frame can be set using setWindowType
* and the current shape retrieved using getWindowType. (This was
* added in v2.3 of the SDK.)
*
* In every respect other than its input domain handling, the
* PluginInputDomainAdapter behaves identically to the plugin that it
* wraps. The wrapped plugin will be deleted when the wrapper is
* deleted.
*
* \note This class was introduced in version 1.1 of the Vamp plugin SDK.
*/
class PluginInputDomainAdapter : public PluginWrapper
namespace vamp::host
{
public:
/**
* 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();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
class PluginInputDomainAdapter : public PluginWrapper
{
public:
PluginInputDomainAdapter(plugin* p);
virtual ~PluginInputDomainAdapter();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
InputDomain getInputDomain() const;
InputDomain getInputDomain() const;
size_t getPreferredStepSize() const;
size_t getPreferredBlockSize() const;
size_t getPreferredStepSize() const;
size_t getPreferredBlockSize() const;
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet process(const float *const *inputBuffers, real_time timestamp);
/**
* ProcessTimestampMethod determines how the
* PluginInputDomainAdapter handles timestamps for the data passed
* to the process() function of the plugin it wraps, in the case
* where the plugin is expecting frequency-domain data.
*
* The Vamp specification requires that the timestamp passed to
* the plugin for frequency-domain input should be that of the
* centre of the processing block, rather than the start as is the
* case for time-domain input.
*
* Since PluginInputDomainAdapter aims to be transparent in use,
* it needs to handle this timestamp adjustment itself. However,
* some control is available over the method used for adjustment,
* by means of the ProcessTimestampMethod setting.
*
* If ProcessTimestampMethod is set to ShiftTimestamp (the
* default), then the data passed to the wrapped plugin will be
* calculated from the same input data block as passed to the
* wrapper, but the timestamp passed to the plugin will be
* advanced by half of the window size.
*
* If ProcessTimestampMethod is set to ShiftData, then the
* timestamp passed to the wrapped plugin will be the same as that
* passed to the process call of the wrapper, but the data block
* used to calculate the input will be shifted back (earlier) by
* half of the window size, with half a block of zero padding at
* the start of the first process call. This has the advantage of
* preserving the first half block of audio without any
* deterioration from window shaping.
*
* If ProcessTimestampMethod is set to NoShift, then no adjustment
* will be made and the timestamps will be incorrect.
*/
enum ProcessTimestampMethod {
ShiftTimestamp,
ShiftData,
NoShift
};
enum ProcessTimestampMethod {
ShiftTimestamp,
ShiftData,
NoShift
};
/**
* Set the method used for timestamp adjustment in plugins taking
* frequency-domain input. See the ProcessTimestampMethod
* documentation for details.
*
* This function must be called before the first call to
* process().
*/
void setProcessTimestampMethod(ProcessTimestampMethod);
void setProcessTimestampMethod(ProcessTimestampMethod);
ProcessTimestampMethod getProcessTimestampMethod() const;
real_time getTimestampAdjustment() const;
/**
* Retrieve the method used for timestamp adjustment in plugins
* taking frequency-domain input. See the ProcessTimestampMethod
* documentation for details.
*/
ProcessTimestampMethod getProcessTimestampMethod() const;
enum WindowType {
/**
* 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 or the
* PluginInputDomainAdapter is configured with its
* ProcessTimestampMethod set to ShiftData instead of
* ShiftTimestamp, then this function will return zero.
*
* The result of calling this function before initialise() has
* been called is undefined.
*/
RealTime getTimestampAdjustment() const;
RectangularWindow = 0,
/**
* The set of supported window shapes.
*/
enum WindowType {
BartlettWindow = 1, /// synonym for RectangularWindow
TriangularWindow = 1, /// synonym for BartlettWindow
RectangularWindow = 0,
HammingWindow = 2,
BartlettWindow = 1, /// synonym for RectangularWindow
TriangularWindow = 1, /// synonym for BartlettWindow
HanningWindow = 3, /// synonym for HannWindow
HannWindow = 3, /// synonym for HanningWindow
HammingWindow = 2,
BlackmanWindow = 4,
HanningWindow = 3, /// synonym for HannWindow
HannWindow = 3, /// synonym for HanningWindow
NuttallWindow = 7,
BlackmanWindow = 4,
BlackmanHarrisWindow = 8
};
NuttallWindow = 7,
BlackmanHarrisWindow = 8
};
/**
* Return the current window shape. The default is HanningWindow.
*/
WindowType getWindowType() const;
/**
* Set the current window shape.
*/
void setWindowType(WindowType type);
protected:
class Impl;
Impl *m_impl;
};
WindowType getWindowType() const;
void setWindowType(WindowType type);
}
protected:
class Impl;
Impl *m_impl;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,235 +1,52 @@
#pragma once
#include "vamp-sdk/Plugin.h"
#include <vector>
#include <string>
#include <map>
#include "vamp-hostsdk/PluginWrapper.h"
namespace Vamp {
class Plugin;
namespace HostExt {
/**
* \class PluginLoader PluginLoader.h <vamp-hostsdk/PluginLoader.h>
*
* Vamp::HostExt::PluginLoader is a convenience class for discovering
* and loading Vamp plugins using the typical plugin-path, library
* naming, and categorisation conventions described in the Vamp SDK
* documentation. This class is intended to greatly simplify the task
* of becoming a Vamp plugin host for any C++ application.
*
* Hosts are not required by the Vamp specification to use the same
* plugin search path and naming conventions as implemented by this
* class, and are certainly not required to use this actual class.
* But we do strongly recommend it.
*
* This class is not thread-safe; use it from a single application
* thread, or guard access to it with a mutex.
*
* \note This class was introduced in version 1.1 of the Vamp plugin SDK.
*/
class PluginLoader
namespace vamp::host
{
public:
/**
* Obtain a pointer to the singleton instance of PluginLoader.
* Use this to obtain your loader object.
*/
static PluginLoader *getInstance();
/**
* PluginKey is a string type that is used to identify a plugin
* uniquely within the scope of "the current system". It consists
* of the lower-cased base name of the plugin library, a colon
* separator, and the identifier string for the plugin. It is
* only meaningful in the context of a given plugin path (the one
* returned by PluginHostAdapter::getPluginPath()).
*
* Use composePluginKey() to construct a plugin key from a known
* plugin library name and identifier.
*
* Note: the fact that the library component of the key is
* lower-cased implies that library names are matched
* case-insensitively by the PluginLoader class, regardless of the
* case sensitivity of the underlying filesystem. (Plugin
* identifiers _are_ case sensitive, however.) Also, it is not
* possible to portably extract a working library name from a
* plugin key, as the result may fail on case-sensitive
* filesystems. Use getLibraryPathForPlugin() instead.
*/
typedef std::string PluginKey;
class PluginLoader
{
public:
static PluginLoader *getInstance();
typedef std::string PluginKey;
typedef std::vector<PluginKey> PluginKeyList;
typedef std::vector<std::string> PluginCategoryHierarchy;
PluginKeyList listPlugins();
/**
* PluginKeyList is a sequence of plugin keys, such as returned by
* listPlugins().
*/
typedef std::vector<PluginKey> PluginKeyList;
PluginKeyList listPluginsIn(std::vector<std::string> libraryNames);
PluginKeyList listPluginsNotIn(std::vector<std::string> libraryNames);
enum AdapterFlags {
/**
* PluginCategoryHierarchy is a sequence of general->specific
* category names, as may be associated with a single plugin.
* This sequence describes the location of a plugin within a
* category forest, containing the human-readable names of the
* plugin's category tree root, followed by each of the nodes down
* to the leaf containing the plugin.
*
* \see getPluginCategory()
*/
typedef std::vector<std::string> PluginCategoryHierarchy;
ADAPT_INPUT_DOMAIN = 0x01,
ADAPT_CHANNEL_COUNT = 0x02,
ADAPT_BUFFER_SIZE = 0x04,
/**
* Search for all available Vamp plugins, and return a list of
* them in the order in which they were found.
*/
PluginKeyList listPlugins();
ADAPT_ALL_SAFE = 0x03,
/**
* Search for available Vamp plugins in libraries with the given
* library names, and return a list of them in the order in which
* they were found. Do not attempt to load any plugin libraries
* other than those named.
*
* The library names should be supplied without path or
* suffix. For example, use "vamp-example-plugins" to find plugins
* in /install/path/of/vamp-example-plugins.dll (or .so etc). This
* is the same concept of "library name" as appears in the plugin
* key: \see composePluginKey().
*/
PluginKeyList listPluginsIn(std::vector<std::string> libraryNames);
ADAPT_ALL = 0xff
};
/**
* Search for available Vamp plugins in libraries other than those
* with the given library names, and return a list of them in the
* order in which they were found. Do not attempt to load any of
* the libraries named.
*
* The library names should be supplied without path or
* suffix. For example, use "vamp-example-plugins" to find plugins
* not appearing in /install/path/of/vamp-example-plugins.dll (or
* .so etc). This is the same concept of "library name" as appears
* in the plugin key: \see composePluginKey().
*/
PluginKeyList listPluginsNotIn(std::vector<std::string> libraryNames);
plugin *loadPlugin(PluginKey key,
float inputSampleRate,
int adapterFlags = 0);
PluginKey composePluginKey(std::string libraryName,
std::string identifier);
/**
* AdapterFlags contains a set of values that may be OR'd together
* to indicate in which circumstances PluginLoader should use a
* plugin adapter to make a plugin easier to use for a host that
* does not want to cater for complex features.
*
* The available flags are:
*
* ADAPT_INPUT_DOMAIN - If the plugin expects frequency domain
* input, wrap it in a PluginInputDomainAdapter that automatically
* converts the plugin to one that expects time-domain input.
* This enables a host to accommodate time- and frequency-domain
* plugins without needing to do any conversion itself.
*
* ADAPT_CHANNEL_COUNT - Wrap the plugin in a PluginChannelAdapter
* to handle any mismatch between the number of channels of audio
* the plugin can handle and the number available in the host.
* This enables a host to use plugins that may require the input
* to be mixed down to mono, etc., without having to worry about
* doing that itself.
*
* ADAPT_BUFFER_SIZE - Wrap the plugin in a PluginBufferingAdapter
* permitting the host to provide audio input using any block
* size, with no overlap, regardless of the plugin's preferred
* block size (suitable for hosts that read from non-seekable
* streaming media, for example). This adapter introduces some
* run-time overhead and also changes the semantics of the plugin
* slightly (see the PluginBufferingAdapter header documentation
* for details).
*
* ADAPT_ALL_SAFE - Perform all available adaptations that are
* meaningful for the plugin and "safe". Currently this means to
* ADAPT_INPUT_DOMAIN if the plugin wants FrequencyDomain input;
* ADAPT_CHANNEL_COUNT always; and ADAPT_BUFFER_SIZE never.
*
* ADAPT_ALL - Perform all available adaptations that are
* meaningful for the plugin.
*
* See PluginInputDomainAdapter, PluginChannelAdapter and
* PluginBufferingAdapter for more details of the classes that the
* loader may use if these flags are set.
*/
enum AdapterFlags {
PluginCategoryHierarchy getPluginCategory(PluginKey plugin);
std::string getLibraryPathForPlugin(PluginKey plugin);
ADAPT_INPUT_DOMAIN = 0x01,
ADAPT_CHANNEL_COUNT = 0x02,
ADAPT_BUFFER_SIZE = 0x04,
protected:
PluginLoader();
virtual ~PluginLoader();
ADAPT_ALL_SAFE = 0x03,
ADAPT_ALL = 0xff
};
/**
* Load a Vamp plugin, given its identifying key. If the plugin
* could not be loaded, returns 0.
*
* The returned plugin should be deleted (using the standard C++
* delete keyword) after use.
*
* \param adapterFlags a bitwise OR of the values in the AdapterFlags
* enumeration, indicating under which circumstances an adapter should be
* used to wrap the original plugin. If adapterFlags is 0, no
* optional adapters will be used. Otherwise, the returned plugin
* may be of an adapter class type which will behave identically
* to the original plugin, apart from any particular features
* implemented by the adapter itself.
*
* \see AdapterFlags, PluginInputDomainAdapter, PluginChannelAdapter
*/
Plugin *loadPlugin(PluginKey key,
float inputSampleRate,
int adapterFlags = 0);
/**
* Given a Vamp plugin library name and plugin identifier, return
* the corresponding plugin key in a form suitable for passing in to
* loadPlugin().
*
* (Note that the reverse of this is not well-defined and is not
* offered in this API - consider using getLibraryPathForPlugin
* instead. See documentation for the PluginKey type for details.)
*
* \see PluginKey, getLibraryPathForPlugin, loadPlugin
*/
PluginKey composePluginKey(std::string libraryName,
std::string identifier);
/**
* Return the category hierarchy for a Vamp plugin, given its
* identifying key.
*
* If the plugin has no category information, return an empty
* hierarchy.
*
* \see PluginCategoryHierarchy
*/
PluginCategoryHierarchy getPluginCategory(PluginKey plugin);
/**
* Return the file path of the dynamic library from which the
* given plugin will be loaded (if available).
*/
std::string getLibraryPathForPlugin(PluginKey plugin);
protected:
PluginLoader();
virtual ~PluginLoader();
class Impl;
Impl *m_impl;
static PluginLoader *m_instance;
};
}
class Impl;
Impl *m_impl;
static PluginLoader *m_instance;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -4,80 +4,26 @@
#include <set>
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
namespace vamp::host
{
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();
class PluginSummarisingAdapter : public PluginWrapper
{
public:
PluginSummarisingAdapter(plugin* p);
virtual ~PluginSummarisingAdapter();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
void reset();
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet getRemainingFeatures();
FeatureSet process(const float *const *inputBuffers, real_time timestamp);
FeatureSet getRemainingFeatures();
typedef std::set<RealTime> SegmentBoundaries;
typedef std::set<real_time> 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 &);
void setSummarySegmentBoundaries(const SegmentBoundaries &);
enum SummaryType {
enum SummaryType {
Minimum = 0,
Maximum = 1,
Mean = 2,
@ -89,64 +35,19 @@ public:
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 {
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;
};
}
FeatureList getSummaryForOutput(int output, SummaryType type, AveragingMethod method = SampleAverage);
FeatureSet getSummaryForAllOutputs(SummaryType type, AveragingMethod method = SampleAverage);
protected:
class Impl;
Impl *m_impl;
};
}

View File

@ -1,157 +1,113 @@
#include "vamp-hostsdk/PluginWrapper.h"
namespace Vamp {
namespace HostExt {
PluginWrapper::PluginWrapper(Plugin *plugin) :
Plugin(plugin->getInputSampleRate()),
m_plugin(plugin)
namespace vamp::host
{
}
PluginWrapper::PluginWrapper(plugin* p) : plugin(p->getInputSampleRate()), m_plugin(p)
{
}
PluginWrapper::~PluginWrapper()
{
PluginWrapper::~PluginWrapper()
{
delete m_plugin;
}
}
bool
PluginWrapper::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
bool PluginWrapper::initialise(size_t channels, size_t stepSize, size_t blockSize)
{
return m_plugin->initialise(channels, stepSize, blockSize);
}
}
void
PluginWrapper::reset()
{
void PluginWrapper::reset()
{
m_plugin->reset();
}
}
Plugin::InputDomain
PluginWrapper::getInputDomain() const
{
plugin::InputDomain PluginWrapper::getInputDomain() const
{
return m_plugin->getInputDomain();
}
}
unsigned int
PluginWrapper::getVampApiVersion() const
{
return m_plugin->getVampApiVersion();
}
std::string PluginWrapper::get_identifier() const
{
return m_plugin->get_identifier();
}
std::string
PluginWrapper::getIdentifier() const
{
return m_plugin->getIdentifier();
}
std::string PluginWrapper::get_name() const
{
return m_plugin->get_name();
}
std::string
PluginWrapper::getName() const
{
return m_plugin->getName();
}
std::string PluginWrapper::get_description() const
{
return m_plugin->get_description();
}
std::string
PluginWrapper::getDescription() const
{
return m_plugin->getDescription();
}
std::string PluginWrapper::get_maker() const
{
return m_plugin->get_maker();
}
std::string
PluginWrapper::getMaker() const
{
return m_plugin->getMaker();
}
plugin::parameter_descriptors PluginWrapper::get_parameter_descriptors() const
{
return m_plugin->get_parameter_descriptors();
}
int
PluginWrapper::getPluginVersion() const
{
return m_plugin->getPluginVersion();
}
float PluginWrapper::get_parameter(std::string parameter) const
{
return m_plugin->get_parameter(parameter);
}
std::string
PluginWrapper::getCopyright() const
{
return m_plugin->getCopyright();
}
void PluginWrapper::set_parameter(std::string parameter, float value)
{
m_plugin->set_parameter(parameter, value);
}
PluginBase::ParameterList
PluginWrapper::getParameterDescriptors() const
{
return m_plugin->getParameterDescriptors();
}
plugin::programs PluginWrapper::get_programs() const
{
return m_plugin->get_programs();
}
float
PluginWrapper::getParameter(std::string parameter) const
{
return m_plugin->getParameter(parameter);
}
std::string PluginWrapper::get_current_program() const
{
return m_plugin->get_current_program();
}
void
PluginWrapper::setParameter(std::string parameter, float value)
{
m_plugin->setParameter(parameter, value);
}
void PluginWrapper::select_program(std::string program)
{
m_plugin->select_program(program);
}
PluginBase::ProgramList
PluginWrapper::getPrograms() const
{
return m_plugin->getPrograms();
}
std::string
PluginWrapper::getCurrentProgram() const
{
return m_plugin->getCurrentProgram();
}
void
PluginWrapper::selectProgram(std::string program)
{
m_plugin->selectProgram(program);
}
size_t
PluginWrapper::getPreferredStepSize() const
{
size_t PluginWrapper::getPreferredStepSize() const
{
return m_plugin->getPreferredStepSize();
}
}
size_t
PluginWrapper::getPreferredBlockSize() const
{
size_t PluginWrapper::getPreferredBlockSize() const
{
return m_plugin->getPreferredBlockSize();
}
}
size_t
PluginWrapper::getMinChannelCount() const
{
size_t PluginWrapper::getMinChannelCount() const
{
return m_plugin->getMinChannelCount();
}
}
size_t PluginWrapper::getMaxChannelCount() const
{
size_t PluginWrapper::getMaxChannelCount() const
{
return m_plugin->getMaxChannelCount();
}
}
Plugin::OutputList
PluginWrapper::getOutputDescriptors() const
{
plugin::OutputList PluginWrapper::getOutputDescriptors() const
{
return m_plugin->getOutputDescriptors();
}
}
Plugin::FeatureSet
PluginWrapper::process(const float *const *inputBuffers, RealTime timestamp)
{
plugin::FeatureSet PluginWrapper::process(const float *const *inputBuffers, real_time timestamp)
{
return m_plugin->process(inputBuffers, timestamp);
}
}
Plugin::FeatureSet
PluginWrapper::getRemainingFeatures()
{
plugin::FeatureSet PluginWrapper::getRemainingFeatures()
{
return m_plugin->getRemainingFeatures();
}
}
}
}

View File

@ -2,87 +2,57 @@
#include "vamp-sdk/Plugin.h"
namespace Vamp::HostExt {
/**
* \class PluginWrapper PluginWrapper.h <vamp-hostsdk/PluginWrapper.h>
*
* PluginWrapper is a simple base class for adapter plugins. It takes
* a pointer to a "to be wrapped" Vamp plugin on construction, and
* provides implementations of all the Vamp plugin methods that simply
* delegate through to the wrapped plugin. A subclass can therefore
* override only the methods that are meaningful for the particular
* adapter.
*
* \note This class was introduced in version 1.1 of the Vamp plugin SDK.
*/
class PluginWrapper : public Plugin
namespace vamp::host
{
public:
virtual ~PluginWrapper();
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
class PluginWrapper : public plugin
{
public:
virtual ~PluginWrapper();
bool initialise(size_t channels, size_t stepSize, size_t blockSize) override;
void reset() override;
InputDomain getInputDomain() const;
InputDomain getInputDomain() const override;
unsigned int getVampApiVersion() const;
std::string getIdentifier() const;
std::string getName() const;
std::string getDescription() const;
std::string getMaker() const;
int getPluginVersion() const;
std::string getCopyright() const;
std::string get_identifier() const override;
std::string get_name() const override;
std::string get_description() const override;
std::string get_maker() const override;
ParameterList getParameterDescriptors() const;
float getParameter(std::string) const;
void setParameter(std::string, float);
parameter_descriptors get_parameter_descriptors() const override;
float get_parameter(std::string) const override;
void set_parameter(std::string, float) override;
ProgramList getPrograms() const;
std::string getCurrentProgram() const;
void selectProgram(std::string);
programs get_programs() const override;
std::string get_current_program() const override;
void select_program(std::string) override;
size_t getPreferredStepSize() const;
size_t getPreferredBlockSize() const;
size_t getPreferredStepSize() const override;
size_t getPreferredBlockSize() const override;
size_t getMinChannelCount() const;
size_t getMaxChannelCount() const;
size_t getMinChannelCount() const override;
size_t getMaxChannelCount() const override;
OutputList getOutputDescriptors() const;
OutputList getOutputDescriptors() const override;
FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
FeatureSet process(const float *const *inputBuffers, real_time timestamp) override;
FeatureSet getRemainingFeatures();
FeatureSet getRemainingFeatures() override;
/**
* 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() {
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:
PluginWrapper(Plugin *plugin); // I take ownership of plugin
Plugin *m_plugin;
};
protected:
PluginWrapper(plugin* p);
plugin* m_plugin;
};
}

View File

@ -6,7 +6,7 @@
template <typename T>
class Window
{
public:
public:
enum WindowType {
RectangularWindow,
BartlettWindow,
@ -46,7 +46,7 @@ public:
WindowType getType() const { return m_type; }
size_t getSize() const { return m_size; }
protected:
protected:
WindowType m_type;
size_t m_size;
T *m_cache;

View File

@ -1,16 +0,0 @@
/* These stubs are provided so that autoconf can check library
* versions using C symbols only */
extern void libvamphostsdk_v_2_9_present(void) { }
extern void libvamphostsdk_v_2_8_present(void) { }
extern void libvamphostsdk_v_2_7_1_present(void) { }
extern void libvamphostsdk_v_2_7_present(void) { }
extern void libvamphostsdk_v_2_6_present(void) { }
extern void libvamphostsdk_v_2_5_present(void) { }
extern void libvamphostsdk_v_2_4_present(void) { }
extern void libvamphostsdk_v_2_3_1_present(void) { }
extern void libvamphostsdk_v_2_3_present(void) { }
extern void libvamphostsdk_v_2_2_1_present(void) { }
extern void libvamphostsdk_v_2_2_present(void) { }
extern void libvamphostsdk_v_2_1_present(void) { }
extern void libvamphostsdk_v_2_0_present(void) { }

View File

@ -6,10 +6,8 @@
#include <cstring>
using namespace std;
static vector<string> files;
static map<string, const char *> cnames;
static std::vector<std::string> files;
static std::map<std::string, const char *> cnames;
static bool haveFiles = false;
struct vhLibrary_t {
@ -63,7 +61,7 @@ vhLibrary vhLoadLibrary(int index)
return 0;
}
string fullPath = files[index];
std::string fullPath = files[index];
void *lib = Files::loadLibrary(fullPath);
if (!lib) return 0;
@ -72,8 +70,8 @@ vhLibrary vhLoadLibrary(int index)
(VampGetPluginDescriptorFunction)Files::lookupInLibrary
(lib, "vampGetPluginDescriptor");
if (!func) {
cerr << "vhLoadLibrary: No vampGetPluginDescriptor function found in library \""
<< fullPath << "\"" << endl;
std::cerr << "vhLoadLibrary: No vampGetPluginDescriptor function found in library \""
<< fullPath << "\"" << std::endl;
Files::unloadLibrary(lib);
return 0;
}

View File

@ -1,53 +1,9 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
#pragma once
/*
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

@ -6,7 +6,8 @@
#include "vamp-sdk/ext/vamp_kiss_fft.h"
#include "vamp-sdk/ext/vamp_kiss_fftr.h"
namespace Vamp {
namespace vamp
{
void FFT::forward(unsigned int un, const double* ri, const double* ii, double* ro, double* io)
{

View File

@ -1,6 +1,7 @@
#pragma once
namespace Vamp {
namespace vamp
{
/**
* A simple FFT implementation provided for convenience of plugin

View File

@ -4,409 +4,120 @@
#include <vector>
#include <map>
#include "PluginBase.h"
#include "RealTime.h"
#include "real_time/real_time.hpp"
namespace Vamp {
/**
* \class Plugin Plugin.h <vamp-sdk/Plugin.h>
*
* Vamp::Plugin is a base class for plugin instance classes
* that provide feature extraction from audio or related data.
*
* In most cases, the input will be audio and the output will be a
* stream of derived data at a lower sampling resolution than the
* input.
*
* Note that this class inherits several abstract methods from
* PluginBase. These must be implemented by the subclass.
*
*
* PLUGIN LIFECYCLE
*
* Feature extraction plugins are managed differently from real-time
* plugins (such as VST effects). The main difference is that the
* parameters for a feature extraction plugin are configured before
* the plugin is used, and do not change during use.
*
* 1. Host constructs the plugin, passing it the input sample rate.
* The plugin may do basic initialisation, but should not do anything
* computationally expensive at this point. You must make sure your
* plugin is cheap to construct, otherwise you'll seriously affect the
* startup performance of almost all hosts. If you have serious
* initialisation to do, the proper place is in initialise() (step 5).
*
* 2. Host may query the plugin's available outputs.
*
* 3. Host queries programs and parameter descriptors, and may set
* some or all of them. Parameters that are not explicitly set should
* take their default values as specified in the parameter descriptor.
* When a program is set, the parameter values may change and the host
* will re-query them to check.
*
* 4. Host queries the preferred step size, block size and number of
* channels. These may all vary depending on the parameter values.
* (Note however that you cannot make the number of distinct outputs
* dependent on parameter values.)
*
* 5. Plugin is properly initialised with a call to initialise. This
* fixes the step size, block size, and number of channels, as well as
* all of the parameter and program settings. If the values passed in
* to initialise do not match the plugin's advertised preferred values
* from step 4, the plugin may refuse to initialise and return false
* (although if possible it should accept the new values). Any
* computationally expensive setup code should take place here.
*
* 6. Host finally checks the number of values, resolution, extents
* etc per output (which may vary depending on the number of channels,
* step size and block size as well as the parameter values).
*
* 7. Host will repeatedly call the process method to pass in blocks
* of input data. This method may return features extracted from that
* data (if the plugin is causal).
*
* 8. Host will call getRemainingFeatures exactly once, after all the
* input data has been processed. This may return any non-causal or
* leftover features.
*
* 9. At any point after initialise was called, the host may
* optionally call the reset method and restart processing. (This
* does not mean it can change the parameters, which are fixed from
* initialise until destruction.)
*
* A plugin does not need to handle the case where setParameter or
* selectProgram is called after initialise has been called. It's the
* host's responsibility not to do that. Similarly, the plugin may
* safely assume that initialise is called no more than once.
*/
class Plugin : public PluginBase
namespace vamp
{
public:
virtual ~Plugin() { }
class plugin
{
public:
virtual ~plugin() { }
/**
* Initialise a plugin to prepare it for use with the given number
* of input channels, step size (window increment, in sample
* frames) and block size (window size, in sample frames).
*
* The input sample rate should have been already specified at
* construction time.
*
* Return true for successful initialisation, false if the number
* of input channels, step size and/or block size cannot be
* supported.
*/
virtual bool initialise(size_t inputChannels,
size_t stepSize,
size_t blockSize) = 0;
enum InputDomain { TimeDomain, FrequencyDomain };
/**
* Reset the plugin after use, to prepare it for another clean
* run. Not called for the first initialisation (i.e. initialise
* must also do a reset).
*/
virtual void reset() = 0;
struct OutputDescriptor
{
std::string identifier;
std::string name;
std::string description;
std::string unit;
bool hasFixedBinCount;
size_t binCount;
std::vector<std::string> binNames;
bool hasKnownExtents;
float minValue;
float maxValue;
bool isQuantized;
float quantizeStep;
enum InputDomain { TimeDomain, FrequencyDomain };
/**
* Get the plugin's required input domain.
*
* If this is TimeDomain, the samples provided to the process()
* function (below) will be in the time domain, as for a
* traditional audio processing plugin.
*
* If this is FrequencyDomain, the host will carry out a windowed
* FFT of size equal to the negotiated block size on the data
* before passing the frequency bin data in to process(). The
* input data for the FFT will be rotated so as to place the
* origin in the centre of the block.
* The plugin does not get to choose the window type -- the host
* will either let the user do so, or will use a Hanning window.
*/
virtual InputDomain getInputDomain() const = 0;
enum SampleType
{
OneSamplePerStep,
FixedSampleRate,
VariableSampleRate
};
/**
* Get the preferred block size (window size -- the number of
* sample frames passed in each block to the process() function).
* This should be called before initialise().
*
* A plugin that can handle any block size may return 0. The
* final block size will be set in the initialise() call.
*/
virtual size_t getPreferredBlockSize() const { return 0; }
SampleType sampleType;
float sampleRate;
/**
* Get the preferred step size (window increment -- the distance
* in sample frames between the start frames of consecutive blocks
* passed to the process() function) for the plugin. This should
* be called before initialise().
*
* A plugin may return 0 if it has no particular interest in the
* step size. In this case, the host should make the step size
* equal to the block size if the plugin is accepting input in the
* time domain. If the plugin is accepting input in the frequency
* domain, the host may use any step size. The final step size
* will be set in the initialise() call.
*/
virtual size_t getPreferredStepSize() const { return 0; }
/**
* Get the minimum supported number of input channels.
*/
virtual size_t getMinChannelCount() const { return 1; }
/**
* Get the maximum supported number of input channels.
*/
virtual size_t getMaxChannelCount() const { return 1; }
struct OutputDescriptor
{
/**
* The name of the output, in computer-usable form. Should be
* reasonably short and without whitespace or punctuation, using
* the characters [a-zA-Z0-9_-] only.
* Example: "zero_crossing_count"
*/
std::string identifier;
/**
* The human-readable name of the output.
* Example: "Zero Crossing Counts"
*/
std::string name;
/**
* A human-readable short text describing the output. May be
* empty if the name has said it all already.
* Example: "The number of zero crossing points per processing block"
*/
std::string description;
/**
* The unit of the output, in human-readable form.
*/
std::string unit;
/**
* True if the output has the same number of values per sample
* for every output sample. Outputs for which this is false
* are unlikely to be very useful in a general-purpose host.
*/
bool hasFixedBinCount;
/**
* The number of values per result of the output. Undefined
* if hasFixedBinCount is false. If this is zero, the output
* is point data (i.e. only the time of each output is of
* interest, the value list will be empty).
*/
size_t binCount;
/**
* The (human-readable) names of each of the bins, if
* appropriate. This is always optional.
*/
std::vector<std::string> binNames;
/**
* True if the results in each output bin fall within a fixed
* numeric range (minimum and maximum values). Undefined if
* binCount is zero.
*/
bool hasKnownExtents;
/**
* Minimum value of the results in the output. Undefined if
* hasKnownExtents is false or binCount is zero.
*/
float minValue;
/**
* Maximum value of the results in the output. Undefined if
* hasKnownExtents is false or binCount is zero.
*/
float maxValue;
/**
* True if the output values are quantized to a particular
* resolution. Undefined if binCount is zero.
*/
bool isQuantized;
/**
* Quantization resolution of the output values (e.g. 1.0 if
* they are all integers). Undefined if isQuantized is false
* or binCount is zero.
*/
float quantizeStep;
enum SampleType {
/// Results from each process() align with that call's block start
OneSamplePerStep,
/// Results are evenly spaced in time (sampleRate specified below)
FixedSampleRate,
/// Results are unevenly spaced and have individual timestamps
VariableSampleRate
};
/**
* Positioning in time of the output results.
*/
SampleType sampleType;
/**
* Sample rate of the output results, as samples per second.
* Undefined if sampleType is OneSamplePerStep.
*
* If sampleType is VariableSampleRate and this value is
* non-zero, then it may be used to calculate a resolution for
* the output (i.e. the "duration" of each sample, in time,
* will be 1/sampleRate seconds). It's recommended to set
* this to zero if that behaviour is not desired.
*/
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),
binCount(0),
hasKnownExtents(false),
minValue(0),
maxValue(0),
isQuantized(false),
quantizeStep(0),
sampleType(OneSamplePerStep),
sampleRate(0),
hasDuration(false) { }
};
OutputDescriptor() :
hasFixedBinCount(false),
binCount(0),
hasKnownExtents(false),
minValue(0),
maxValue(0),
isQuantized(false),
quantizeStep(0),
sampleType(OneSamplePerStep),
sampleRate(0),
hasDuration(false) { }
};
typedef std::vector<OutputDescriptor> OutputList;
using OutputList = std::vector<OutputDescriptor>;
/**
* Get the outputs of this plugin. An output's index in this list
* is used as its numeric index when looking it up in the
* FeatureSet returned from the process() call.
*/
virtual OutputList getOutputDescriptors() const = 0;
struct Feature
{
/**
* True if an output feature has its own timestamp. This is
* mandatory if the output has VariableSampleRate, optional if
* the output has FixedSampleRate, and unused if the output
* has OneSamplePerStep.
*/
bool hasTimestamp;
/**
* Timestamp of the output feature. This is mandatory if the
* output has VariableSampleRate or if the output has
* FixedSampleRate and hasTimestamp is true, and unused
* otherwise.
*/
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.
*/
struct Feature
{
bool hasTimestamp;
real_time timestamp;
bool hasDuration;
real_time duration;
std::vector<float> values;
std::string label;
Feature() : hasTimestamp(false), hasDuration(false) { }
};
/**
* 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
* hasFixedBinCount, there must be the same number of values
* as the output's binCount count.
*/
std::vector<float> values;
using FeatureList = std::vector<Feature>;
using FeatureSet = std::map<int, FeatureList>;
/**
* Label for the sample of this feature.
*/
std::string label;
virtual OutputList getOutputDescriptors() const = 0;
virtual bool initialise(size_t inputChannels, size_t stepSize, size_t blockSize) = 0;
virtual void reset() = 0;
virtual InputDomain getInputDomain() const = 0;
virtual size_t getPreferredBlockSize() const { return 0; }
virtual size_t getPreferredStepSize() const { return 0; }
virtual size_t getMinChannelCount() const { return 1; }
virtual size_t getMaxChannelCount() const { return 1; }
virtual FeatureSet process(const float *const *inputBuffers, real_time timestamp) = 0;
virtual FeatureSet getRemainingFeatures() = 0;
virtual std::string get_type() const { return "Feature Extraction Plugin"; }
Feature() : // defaults for mandatory non-class-type members
hasTimestamp(false), hasDuration(false) { }
};
float getInputSampleRate() const { return m_inputSampleRate; }
typedef std::vector<Feature> FeatureList;
typedef std::map<int, FeatureList> FeatureSet; // key is output no
struct parameter_descriptor
{
std::string identifier;
std::string name;
std::string description;
std::string unit;
float min_value { 0.f };
float max_value { 0.f };
float default_value { 0.f };
bool is_quantized { false };
float quantize_step { 0.f };
std::vector<std::string> value_names;
};
/**
* Process a single block of input data.
*
* If the plugin's inputDomain is TimeDomain, inputBuffers will
* point to one array of floats per input channel, and each of
* these arrays will contain blockSize consecutive audio samples
* (the host will zero-pad as necessary). The timestamp in this
* case will be the real time in seconds of the start of the
* supplied block of samples.
*
* If the plugin's inputDomain is FrequencyDomain, inputBuffers
* will point to one array of floats per input channel, and each
* of these arrays will contain blockSize/2+1 consecutive pairs of
* real and imaginary component floats corresponding to bins
* 0..(blockSize/2) of the FFT output. That is, bin 0 (the first
* pair of floats) contains the DC output, up to bin blockSize/2
* which contains the Nyquist-frequency output. There will
* therefore be blockSize+2 floats per channel in total. The
* timestamp will be the real time in seconds of the centre of the
* FFT input window (i.e. the very first block passed to process
* might contain the FFT of half a block of zero samples and the
* first half-block of the actual data, with a timestamp of zero).
*
* Return any features that have become available after this
* process call. (These do not necessarily have to fall within
* the process block, except for OneSamplePerStep outputs.)
*/
virtual FeatureSet process(const float *const *inputBuffers,
RealTime timestamp) = 0;
using parameter_descriptors = std::vector<parameter_descriptor>;
using programs = std::vector<std::string>;
/**
* After all blocks have been processed, calculate and return any
* remaining features derived from the complete input.
*/
virtual FeatureSet getRemainingFeatures() = 0;
/**
* Used to distinguish between Vamp::Plugin and other potential
* sibling subclasses of PluginBase. Do not reimplement this
* function in your subclass.
*/
virtual std::string getType() const { return "Feature Extraction Plugin"; }
/**
* Retrieve the input sample rate set on construction.
*/
float getInputSampleRate() const { return m_inputSampleRate; }
protected:
Plugin(float inputSampleRate) :
m_inputSampleRate(inputSampleRate) { }
float m_inputSampleRate;
};
public:
virtual std::string get_identifier() const = 0;
virtual std::string get_name() const = 0;
virtual std::string get_description() const = 0;
virtual std::string get_maker() const = 0;
virtual float get_parameter(std::string) const { return 0.f; }
virtual std::string get_current_program() const { return ""; }
virtual parameter_descriptors get_parameter_descriptors() const { return parameter_descriptors(); }
virtual programs get_programs() const { return programs(); }
virtual void set_parameter(std::string, float) { }
virtual void select_program(std::string) { }
protected:
plugin(float inputSampleRate) : m_inputSampleRate(inputSampleRate) { }
float m_inputSampleRate;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,76 +1,44 @@
#pragma once
#include <map>
#include "vamp.h"
#include "vamp-sdk/Plugin.h"
namespace Vamp {
/**
* \class PluginAdapterBase PluginAdapter.h <vamp-sdk/PluginAdapter.h>
*
* PluginAdapter and PluginAdapterBase provide a wrapper class that a
* plugin library can use to make its C++ Vamp::Plugin objects
* available through the Vamp C API.
*
* Almost all Vamp plugin libraries will want to make use of this. To
* do so, all they need to do is declare a PluginAdapter<T> for each
* plugin class T in their library. It's very simple, and you need to
* know absolutely nothing about how it works in order to use it.
* Just cut and paste from an existing plugin's discovery function.
* \see vampGetPluginDescriptor
*/
class PluginAdapterBase
namespace vamp
{
public:
virtual ~PluginAdapterBase();
class PluginAdapterBase
{
public:
virtual ~PluginAdapterBase();
const VampPluginDescriptor *getDescriptor();
/**
* Return a VampPluginDescriptor describing the plugin that is
* wrapped by this adapter.
*/
const VampPluginDescriptor *getDescriptor();
protected:
PluginAdapterBase();
protected:
PluginAdapterBase();
virtual plugin* createPlugin(float inputSampleRate) = 0;
virtual Plugin *createPlugin(float inputSampleRate) = 0;
class Impl;
Impl* m_impl;
};
class Impl;
Impl *m_impl;
};
template <typename Plugin>
class PluginAdapter : public PluginAdapterBase
{
public:
PluginAdapter() : PluginAdapterBase() { }
virtual ~PluginAdapter() { }
/**
* \class PluginAdapter PluginAdapter.h <vamp-sdk/PluginAdapter.h>
*
* PluginAdapter turns a PluginAdapterBase into a specific wrapper for
* a particular plugin implementation.
*
* See PluginAdapterBase.
*/
template <typename P>
class PluginAdapter : public PluginAdapterBase
{
public:
PluginAdapter() : PluginAdapterBase() { }
virtual ~PluginAdapter() { }
protected:
Plugin *createPlugin(float inputSampleRate) {
P *p = new P(inputSampleRate);
Plugin *plugin = dynamic_cast<Plugin *>(p);
if (!plugin) {
std::cerr << "ERROR: PluginAdapter::createPlugin: "
<< "Template type is not a plugin!"
<< std::endl;
delete p;
return 0;
}
return plugin;
}
};
protected:
plugin* createPlugin(float inputSampleRate) {
Plugin* pl = new Plugin(inputSampleRate);
plugin* p = dynamic_cast<plugin*>(pl);
if (!p) {
std::cerr << "ERROR: PluginAdapter::createPlugin: "
<< "Template type is not a plugin!"
<< std::endl;
delete pl;
return 0;
}
return p;
}
};
}

View File

@ -1,218 +0,0 @@
#pragma once
#include <string>
#include <vector>
namespace Vamp {
/**
* A base class for plugins with optional configurable parameters,
* programs, etc. The Vamp::Plugin is derived from this, and
* individual Vamp plugins should derive from that.
*
* This class does not provide the necessary interfaces to instantiate
* or run a plugin. It only specifies an interface for retrieving
* those controls that the host may wish to show to the user for
* editing. It could meaningfully be subclassed by real-time plugins
* or other sorts of plugin as well as Vamp plugins.
*/
class PluginBase
{
public:
virtual ~PluginBase() { }
/**
* Get the Vamp API compatibility level of the plugin.
*/
virtual unsigned int getVampApiVersion() const { return 2; }
/**
* Get the computer-usable name of the plugin. This should be
* reasonably short and contain no whitespace or punctuation
* characters. It may only contain the characters [a-zA-Z0-9_-].
* This is the authoritative way for a program to identify a
* plugin within a given library.
*
* This text may be visible to the user, but it should not be the
* main text used to identify a plugin to the user (that will be
* the name, below).
*
* Example: "zero_crossings"
*/
virtual std::string getIdentifier() const = 0;
/**
* Get a human-readable name or title of the plugin. This
* should be brief and self-contained, as it may be used to
* identify the plugin to the user in isolation (i.e. without also
* showing the plugin's "identifier").
*
* Example: "Zero Crossings"
*/
virtual std::string getName() const = 0;
/**
* Get a human-readable description for the plugin, typically
* a line of text that may optionally be displayed in addition
* to the plugin's "name". May be empty if the name has said
* it all already.
*
* Example: "Detect and count zero crossing points"
*/
virtual std::string getDescription() const = 0;
/**
* Get the name of the author or vendor of the plugin in
* human-readable form. This should be a short identifying text,
* as it may be used to label plugins from the same source in a
* menu or similar.
*/
virtual std::string getMaker() const = 0;
/**
* Get the copyright statement or licensing summary for the
* plugin. This can be an informative text, without the same
* presentation constraints as mentioned for getMaker above.
*/
virtual std::string getCopyright() const = 0;
/**
* Get the version number of the plugin.
*/
virtual int getPluginVersion() const = 0;
struct ParameterDescriptor
{
/**
* The name of the parameter, in computer-usable form. Should
* be reasonably short, and may only contain the characters
* [a-zA-Z0-9_-].
*/
std::string identifier;
/**
* The human-readable name of the parameter.
*/
std::string name;
/**
* A human-readable short text describing the parameter. May be
* empty if the name has said it all already.
*/
std::string description;
/**
* The unit of the parameter, in human-readable form.
*/
std::string unit;
/**
* The minimum value of the parameter.
*/
float minValue;
/**
* The maximum value of the parameter.
*/
float maxValue;
/**
* The default value of the parameter. The plugin should
* ensure that parameters have this value on initialisation
* (i.e. the host is not required to explicitly set parameters
* if it wants to use their default values).
*/
float defaultValue;
/**
* True if the parameter values are quantized to a particular
* resolution.
*/
bool isQuantized;
/**
* Quantization resolution of the parameter values (e.g. 1.0
* if they are all integers). Undefined if isQuantized is
* false.
*/
float quantizeStep;
/**
* Names for the quantized values. If isQuantized is true,
* this may either be empty or contain one string for each of
* the quantize steps from minValue up to maxValue inclusive.
* Undefined if isQuantized is false.
*
* If these names are provided, they should be shown to the
* user in preference to the values themselves. The user may
* never see the actual numeric values unless they are also
* encoded in the names.
*/
std::vector<std::string> valueNames;
ParameterDescriptor() : // the defaults are invalid: you must set them
minValue(0),
maxValue(0),
defaultValue(0),
isQuantized(false),
quantizeStep(0) { }
};
typedef std::vector<ParameterDescriptor> ParameterList;
/**
* Get the controllable parameters of this plugin.
*/
virtual ParameterList getParameterDescriptors() const {
return ParameterList();
}
/**
* Get the value of a named parameter. The argument is the identifier
* field from that parameter's descriptor.
*/
virtual float getParameter(std::string) const { return 0.0; }
/**
* Set a named parameter. The first argument is the identifier field
* from that parameter's descriptor.
*/
virtual void setParameter(std::string, float) { }
typedef std::vector<std::string> ProgramList;
/**
* Get the program settings available in this plugin. A program
* is a named shorthand for a set of parameter values; changing
* the program may cause the plugin to alter the values of its
* published parameters (and/or non-public internal processing
* parameters). The host should re-read the plugin's parameter
* values after setting a new program.
*
* The programs must have unique names.
*/
virtual ProgramList getPrograms() const { return ProgramList(); }
/**
* Get the current program.
*/
virtual std::string getCurrentProgram() const { return ""; }
/**
* Select a program. (If the given program name is not one of the
* available programs, do nothing.)
*/
virtual void selectProgram(std::string) { }
/**
* Get the type of plugin. This is to be implemented by the
* immediate subclass, not by actual plugins. Do not attempt to
* implement this in plugin code.
*/
virtual std::string getType() const = 0;
};
}

View File

@ -1,199 +0,0 @@
#include <iostream>
#include <limits.h>
#if (defined(__GNUC__)) && (__GNUC__ < 3)
#include <strstream>
#define stringstream strstream
#else
#include <sstream>
#endif
using std::cerr;
using std::endl;
#ifndef _WIN32
#include <sys/time.h>
#endif
#include "vamp-sdk/RealTime.h"
namespace Vamp {
// A RealTime consists of two ints that must be at least 32 bits each.
// A signed 32-bit int can store values exceeding +/- 2 billion. This
// means we can safely use our lower int for nanoseconds, as there are
// 1 billion nanoseconds in a second and we need to handle double that
// because of the implementations of addition etc that we use.
//
// The maximum valid RealTime on a 32-bit system is somewhere around
// 68 years: 999999999 nanoseconds longer than the classic Unix epoch.
#define ONE_BILLION 1000000000
RealTime::RealTime(int s, int n) :
sec(s), nsec(n)
{
while (nsec <= -ONE_BILLION && sec > INT_MIN) { nsec += ONE_BILLION; --sec; }
while (nsec >= ONE_BILLION && sec < INT_MAX) { nsec -= ONE_BILLION; ++sec; }
while (nsec > 0 && sec < 0) { nsec -= ONE_BILLION; ++sec; }
while (nsec < 0 && sec > 0) { nsec += ONE_BILLION; --sec; }
}
RealTime
RealTime::fromSeconds(double sec)
{
if (sec != sec) { // NaN
cerr << "ERROR: NaN/Inf passed to Vamp::RealTime::fromSeconds" << endl;
return RealTime::zeroTime;
} else if (sec >= 0) {
return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5));
} else {
return -fromSeconds(-sec);
}
}
RealTime
RealTime::fromMilliseconds(int msec)
{
return RealTime(msec / 1000, (msec % 1000) * 1000000);
}
#ifndef _WIN32
RealTime
RealTime::fromTimeval(const struct timeval &tv)
{
return RealTime(int(tv.tv_sec), int(tv.tv_usec * 1000));
}
#endif
std::ostream &operator<<(std::ostream &out, const RealTime &rt)
{
if (rt < RealTime::zeroTime) {
out << "-";
} else {
out << " ";
}
int s = (rt.sec < 0 ? -rt.sec : rt.sec);
int n = (rt.nsec < 0 ? -rt.nsec : rt.nsec);
out << s << ".";
int nn(n);
if (nn == 0) out << "00000000";
else while (nn < (ONE_BILLION / 10)) {
out << "0";
nn *= 10;
}
out << n << "R";
return out;
}
std::string
RealTime::toString() const
{
std::stringstream out;
out << *this;
std::string s = out.str();
// remove trailing R
return s.substr(0, s.length() - 1);
}
std::string
RealTime::toText(bool fixedDp) const
{
if (*this < RealTime::zeroTime) return "-" + (-*this).toText(fixedDp);
std::stringstream out;
if (sec >= 3600) {
out << (sec / 3600) << ":";
}
if (sec >= 60) {
int minutes = (sec % 3600) / 60;
if (sec >= 3600 && minutes < 10) out << "0";
out << minutes << ":";
}
if (sec >= 10) {
out << ((sec % 60) / 10);
}
out << (sec % 10);
int ms = msec();
if (ms != 0) {
out << ".";
out << (ms / 100);
ms = ms % 100;
if (ms != 0) {
out << (ms / 10);
ms = ms % 10;
} else if (fixedDp) {
out << "0";
}
if (ms != 0) {
out << ms;
} else if (fixedDp) {
out << "0";
}
} else if (fixedDp) {
out << ".000";
}
std::string s = out.str();
return s;
}
RealTime
RealTime::operator/(int d) const
{
int secdiv = sec / d;
int secrem = sec % d;
double nsecdiv = (double(nsec) + ONE_BILLION * double(secrem)) / d;
return RealTime(secdiv, int(nsecdiv + 0.5));
}
double
RealTime::operator/(const RealTime &r) const
{
double lTotal = double(sec) * ONE_BILLION + double(nsec);
double rTotal = double(r.sec) * ONE_BILLION + double(r.nsec);
if (rTotal == 0) return 0.0;
else return lTotal/rTotal;
}
long
RealTime::realTime2Frame(const RealTime &time, unsigned int sampleRate)
{
if (time < zeroTime) return -realTime2Frame(-time, sampleRate);
double s = time.sec + double(time.nsec) / ONE_BILLION;
return long(s * sampleRate + 0.5);
}
RealTime
RealTime::frame2RealTime(long frame, unsigned int sampleRate)
{
if (frame < 0) return -frame2RealTime(-frame, sampleRate);
int sec = int(frame / long(sampleRate));
frame -= sec * long(sampleRate);
int nsec = (int)((double(frame) / double(sampleRate)) * ONE_BILLION + 0.5);
// Use ctor here instead of setting data members directly to
// ensure nsec > ONE_BILLION is handled properly. It's extremely
// unlikely, but not impossible.
return RealTime(sec, nsec);
}
const RealTime RealTime::zeroTime(0,0);
}

View File

@ -1,114 +0,0 @@
#pragma once
#include <iostream>
#include <string>
struct timeval;
namespace Vamp {
/**
* \class RealTime RealTime.h <vamp-sdk/RealTime.h>
*
* RealTime represents time values to nanosecond precision
* with accurate arithmetic and frame-rate conversion functions.
*/
struct RealTime
{
int sec;
int nsec;
int usec() const { return nsec / 1000; }
int msec() const { return nsec / 1000000; }
RealTime(): sec(0), nsec(0) {}
RealTime(int s, int n);
RealTime(const RealTime &r) :
sec(r.sec), nsec(r.nsec) { }
static RealTime fromSeconds(double sec);
static RealTime fromMilliseconds(int msec);
#ifndef _WIN32
static RealTime fromTimeval(const struct timeval &);
#endif
RealTime &operator=(const RealTime &r) {
sec = r.sec; nsec = r.nsec; return *this;
}
RealTime operator+(const RealTime &r) const {
return RealTime(sec + r.sec, nsec + r.nsec);
}
RealTime operator-(const RealTime &r) const {
return RealTime(sec - r.sec, nsec - r.nsec);
}
RealTime operator-() const {
return RealTime(-sec, -nsec);
}
bool operator <(const RealTime &r) const {
if (sec == r.sec) return nsec < r.nsec;
else return sec < r.sec;
}
bool operator >(const RealTime &r) const {
if (sec == r.sec) return nsec > r.nsec;
else return sec > r.sec;
}
bool operator==(const RealTime &r) const {
return (sec == r.sec && nsec == r.nsec);
}
bool operator!=(const RealTime &r) const {
return !(r == *this);
}
bool operator>=(const RealTime &r) const {
if (sec == r.sec) return nsec >= r.nsec;
else return sec >= r.sec;
}
bool operator<=(const RealTime &r) const {
if (sec == r.sec) return nsec <= r.nsec;
else return sec <= r.sec;
}
RealTime operator/(int d) const;
/**
* Return the ratio of two times.
*/
double operator/(const RealTime &r) const;
/**
* Return a human-readable debug-type string to full precision
* (probably not a format to show to a user directly)
*/
std::string toString() const;
/**
* Return a user-readable string to the nearest millisecond
* in a form like HH:MM:SS.mmm
*/
std::string toText(bool fixedDp = false) const;
/**
* Convert a RealTime into a sample frame at the given sample rate.
*/
static long realTime2Frame(const RealTime &r, unsigned int sampleRate);
/**
* Convert a sample frame at the given sample rate into a RealTime.
*/
static RealTime frame2RealTime(long frame, unsigned int sampleRate);
static const RealTime zeroTime;
};
std::ostream &operator<<(std::ostream &out, const RealTime &rt);
}

View File

@ -1,16 +0,0 @@
/* These stubs are provided so that autoconf can check library
* versions using C symbols only */
extern void libvampsdk_v_2_9_present(void) { }
extern void libvampsdk_v_2_8_present(void) { }
extern void libvampsdk_v_2_7_1_present(void) { }
extern void libvampsdk_v_2_7_present(void) { }
extern void libvampsdk_v_2_6_present(void) { }
extern void libvampsdk_v_2_5_present(void) { }
extern void libvampsdk_v_2_4_present(void) { }
extern void libvampsdk_v_2_3_1_present(void) { }
extern void libvampsdk_v_2_3_present(void) { }
extern void libvampsdk_v_2_2_1_present(void) { }
extern void libvampsdk_v_2_2_present(void) { }
extern void libvampsdk_v_2_1_present(void) { }
extern void libvampsdk_v_2_0_present(void) { }

View File

@ -0,0 +1,46 @@
#pragma once
#include <string>
#include <vector>
namespace vamp
{
class base_plugin
{
public:
base_plugin() = default;
virtual ~base_plugin();
public:
struct parameter_descriptor
{
std::string identifier;
std::string name;
std::string description;
std::string unit;
float min_value { 0.f };
float max_value { 0.f };
float default_value { 0.f };
bool is_quantized { false };
float quantize_step { 0.f };
std::vector<std::string> value_names;
};
using parameter_descriptors = std::vector<parameter_descriptor>;
using programs = std::vector<std::string>;
public:
virtual std::string get_identifier() const = 0;
virtual std::string get_name() const = 0;
virtual std::string get_description() const = 0;
virtual std::string get_maker() const = 0;
virtual float get_parameter(std::string) const { return 0.f; }
virtual std::string get_current_program() const { return ""; }
virtual std::string get_type() const = 0;
virtual parameter_descriptors get_parameter_descriptors() const { return parameter_descriptors(); }
virtual programs get_programs() const { return programs(); }
virtual void set_parameter(std::string, float) { }
virtual void select_program(std::string) { }
};
}

View File

@ -0,0 +1,160 @@
#include "real_time.hpp"
#include <iostream>
#include <limits>
#include <sstream>
#include <sys/time.h>
namespace vamp
{
const real_time real_time::zero_time{ 0, 0 };
real_time::real_time(int s, int n) : sec{ s }, nsec{ n }
{
while (nsec <= -ONE_BILLION && sec > std::numeric_limits<int>().max()) { nsec += ONE_BILLION; --sec; }
while (nsec >= ONE_BILLION && sec < std::numeric_limits<int>().max()) { nsec -= ONE_BILLION; ++sec; }
while (nsec > 0 && sec < 0) { nsec -= ONE_BILLION; ++sec; }
while (nsec < 0 && sec > 0) { nsec += ONE_BILLION; --sec; }
}
real_time real_time::from_seconds(double sec)
{
if (sec != sec)
return real_time::zero_time;
else if (sec >= 0)
return real_time{ static_cast<int>(sec), static_cast<int>((sec - int(sec)) * ONE_BILLION + 0.5) };
else
return -from_seconds(-sec);
}
real_time real_time::from_milliseconds(int msec)
{
return real_time{ msec / 1'000, (msec % 1'000) * 1'000'000 };
}
real_time real_time::from_timeval(const struct timeval& tv)
{
return real_time{ int(tv.tv_sec), int(tv.tv_usec * 1000) };
}
std::ostream& operator<<(std::ostream& out, const real_time& rt)
{
if (rt < real_time::zero_time)
out << "-";
else
out << " ";
int s = (rt.sec < 0 ? -rt.sec : rt.sec);
int n = (rt.nsec < 0 ? -rt.nsec : rt.nsec);
out << s << ".";
int nn{ n };
if (nn == 0) out << "00000000";
else while (nn < (ONE_BILLION / 10))
{
out << "0";
nn *= 10;
}
out << n << "R";
return out;
}
std::string real_time::to_string() const
{
std::stringstream out;
out << *this;
std::string s = out.str();
// remove trailing R
return s.substr(0, s.length() - 1);
}
std::string real_time::to_text(bool fixed_dp) const
{
if (*this < real_time::zero_time) return "-" + (-*this).to_text(fixed_dp);
std::stringstream out;
if (sec >= 3'600) out << (sec / 3'600) << ":";
if (sec >= 60)
{
int minutes = (sec % 3'600) / 60;
if (sec >= 3'600 && minutes < 10) out << "0";
out << minutes << ":";
}
if (sec >= 10) out << ((sec % 60) / 10);
out << (sec % 10);
int ms = msec();
if (ms != 0)
{
out << ".";
out << (ms / 100);
ms = ms % 100;
if (ms != 0)
{
out << (ms / 10);
ms = ms % 10;
}
else if (fixed_dp)
{
out << "0";
}
if (ms != 0)
{
out << ms;
}
else if (fixed_dp)
{
out << "0";
}
}
else if (fixed_dp)
{
out << ".000";
}
std::string s = out.str();
return s;
}
real_time real_time::operator/(int d) const
{
int secdiv = sec / d;
int secrem = sec % d;
double nsecdiv = (static_cast<double>(nsec) + ONE_BILLION * static_cast<double>(secrem)) / d;
return real_time{ secdiv, static_cast<int>(nsecdiv + 0.5) };
}
double real_time::operator/(const real_time& r) const
{
double l_total = static_cast<double>(sec) * ONE_BILLION + static_cast<double>(nsec);
double r_total = static_cast<double>(r.sec) * ONE_BILLION + static_cast<double>(r.nsec);
if (r_total == 0) return 0.0;
else return l_total / r_total;
}
long real_time::rt2f(const real_time& time, unsigned int sample_rate)
{
if (time < real_time::zero_time) return -rt2f(-time, sample_rate);
double s = time.sec + static_cast<double>(time.nsec) / ONE_BILLION;
return static_cast<long>(s * sample_rate + 0.5);
}
real_time real_time::f2rt(long frame, unsigned int sample_rate)
{
if (frame < 0) return -f2rt(-frame, sample_rate);
int sec = static_cast<int>(frame / static_cast<long>(sample_rate));
frame -= sec * static_cast<long>(sample_rate);
int nsec = static_cast<int>((static_cast<double>(frame) / static_cast<double>(sample_rate)) * ONE_BILLION + 0.5);
return real_time{ sec, nsec };
}
}

View File

@ -0,0 +1,99 @@
#pragma once
#include <iostream>
#include <string>
#define ONE_BILLION 1'000'000'000
struct timeval;
namespace vamp
{
struct real_time
{
public:
real_time() = default;
real_time(int s, int n);
real_time(const real_time& r) : sec{ r.sec }, nsec{ r.nsec } { }
public:
int sec { 0 };
int nsec { 0 };
public:
static real_time from_seconds(double sec);
static real_time from_milliseconds(int msec);
static real_time from_timeval(const struct timeval &);
// real_time to frame
static long rt2f(const real_time &r, unsigned int sample_rate);
// frame to real_time
static real_time f2rt(long frame, unsigned int sample_rate);
static const real_time zero_time;
public:
int usec() const { return nsec / 1000; }
int msec() const { return nsec / 1000000; }
std::string to_string() const;
std::string to_text(bool fixed_dp = false) const;
public:
real_time &operator=(const real_time &r)
{
sec = r.sec; nsec = r.nsec; return *this;
}
real_time operator+(const real_time &r) const
{
return real_time(sec + r.sec, nsec + r.nsec);
}
real_time operator-(const real_time &r) const
{
return real_time(sec - r.sec, nsec - r.nsec);
}
real_time operator-() const
{
return real_time(-sec, -nsec);
}
bool operator <(const real_time &r) const
{
if (sec == r.sec) return nsec < r.nsec;
else return sec < r.sec;
}
bool operator >(const real_time &r) const
{
if (sec == r.sec) return nsec > r.nsec;
else return sec > r.sec;
}
bool operator==(const real_time &r) const
{
return (sec == r.sec && nsec == r.nsec);
}
bool operator!=(const real_time &r) const
{
return !(r == *this);
}
bool operator>=(const real_time &r) const
{
if (sec == r.sec) return nsec >= r.nsec;
else return sec >= r.sec;
}
bool operator<=(const real_time &r) const
{
if (sec == r.sec) return nsec <= r.nsec;
else return sec <= r.sec;
}
real_time operator/(int d) const;
double operator/(const real_time &r) const;
friend std::ostream &operator<<(std::ostream &out, const real_time &rt);
};
}

View File

@ -1,49 +1,45 @@
#include "hack/logger/logger.hpp"
#include "vamp-sdk/Plugin.h"
#include "vamp-hostsdk/PluginInputDomainAdapter.h"
#include "vamp-hostsdk/PluginBufferingAdapter.h"
#include "vamp-sdk/Plugin.h"
class MyPlugin : public Vamp::Plugin
class MyPlugin : public vamp::plugin
{
public:
public:
MyPlugin(float inputSampleRate);
virtual ~MyPlugin();
std::string getIdentifier() const;
std::string getName() const;
std::string getDescription() const;
std::string getMaker() const;
int getPluginVersion() const;
std::string getCopyright() const;
std::string get_identifier() const override;
std::string get_name() const override;
std::string get_description() const override;
std::string get_maker() const override;
InputDomain getInputDomain() const;
size_t getPreferredBlockSize() const;
size_t getPreferredStepSize() const;
size_t getMinChannelCount() const;
size_t getMaxChannelCount() const;
InputDomain getInputDomain() const override;
size_t getPreferredBlockSize() const override;
size_t getPreferredStepSize() const override;
size_t getMinChannelCount() const override;
size_t getMaxChannelCount() const override;
ParameterList getParameterDescriptors() const;
float getParameter(std::string identifier) const;
void setParameter(std::string identifier, float value);
parameter_descriptors get_parameter_descriptors() const override;
float get_parameter(std::string identifier) const override;
void set_parameter(std::string identifier, float value) override;
ProgramList getPrograms() const;
std::string getCurrentProgram() const;
void selectProgram(std::string name);
programs get_programs() const override;
std::string get_current_program() const override;
void select_program(std::string name) override;
OutputList getOutputDescriptors() const;
OutputList getOutputDescriptors() const override;
bool initialise(size_t channels, size_t stepSize, size_t blockSize);
void reset();
bool initialise(size_t channels, size_t stepSize, size_t blockSize) override;
void reset() override;
FeatureSet process(const float *const *inputBuffers,
Vamp::RealTime timestamp);
FeatureSet getRemainingFeatures();
FeatureSet process(const float *const *inputBuffers, vamp::real_time timestamp) override;
FeatureSet getRemainingFeatures() override;
};
MyPlugin::MyPlugin(float inputSampleRate) : Plugin(inputSampleRate)
MyPlugin::MyPlugin(float inputSampleRate) : plugin(inputSampleRate)
{
}
@ -51,32 +47,22 @@ MyPlugin::~MyPlugin()
{
}
std::string MyPlugin::getIdentifier() const
std::string MyPlugin::get_identifier() const
{
return "myplugin";
}
std::string MyPlugin::getName() const
std::string MyPlugin::get_name() const
{
return "My Plugin";
}
std::string MyPlugin::getDescription() const
std::string MyPlugin::get_description() const
{
return "";
}
std::string MyPlugin::getMaker() const
{
return "";
}
int MyPlugin::getPluginVersion() const
{
return 1;
}
std::string MyPlugin::getCopyright() const
std::string MyPlugin::get_maker() const
{
return "";
}
@ -106,48 +92,48 @@ size_t MyPlugin::getMaxChannelCount() const
return 1;
}
MyPlugin::ParameterList MyPlugin::getParameterDescriptors() const
MyPlugin::parameter_descriptors MyPlugin::get_parameter_descriptors() const
{
ParameterList list;
ParameterDescriptor d;
parameter_descriptors list;
parameter_descriptor d;
d.identifier = "parameter";
d.name = "Some Parameter";
d.description = "";
d.unit = "";
d.minValue = 0;
d.maxValue = 10;
d.defaultValue = 5;
d.isQuantized = false;
d.min_value = 0;
d.max_value = 10;
d.default_value = 5;
d.is_quantized = false;
list.push_back(d);
return list;
}
float MyPlugin::getParameter(std::string identifier) const
float MyPlugin::get_parameter(std::string identifier) const
{
if (identifier == "parameter")
return 5;
return 0;
}
void MyPlugin::setParameter(std::string identifier, float value)
void MyPlugin::set_parameter(std::string identifier, float value)
{
if (identifier == "parameter") {
}
}
MyPlugin::ProgramList MyPlugin::getPrograms() const
MyPlugin::programs MyPlugin::get_programs() const
{
ProgramList list;
programs list;
return list;
}
std::string MyPlugin::getCurrentProgram() const
std::string MyPlugin::get_current_program() const
{
return "";
}
void MyPlugin::selectProgram(std::string name)
void MyPlugin::select_program(std::string name)
{
}
@ -181,7 +167,7 @@ void MyPlugin::reset()
{
}
MyPlugin::FeatureSet MyPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
MyPlugin::FeatureSet MyPlugin::process(const float *const *inputBuffers, vamp::real_time timestamp)
{
return FeatureSet();
}
@ -195,10 +181,10 @@ auto main() -> int
{
float samplerate = 10.f;
MyPlugin* ch = new MyPlugin(samplerate);
Vamp::HostExt::PluginInputDomainAdapter* ia = new Vamp::HostExt::PluginInputDomainAdapter(ch);
ia->setProcessTimestampMethod(Vamp::HostExt::PluginInputDomainAdapter::ShiftData);
vamp::host::PluginInputDomainAdapter* ia = new vamp::host::PluginInputDomainAdapter(ch);
ia->setProcessTimestampMethod(vamp::host::PluginInputDomainAdapter::ShiftData);
Vamp::HostExt::PluginBufferingAdapter* adapter = new Vamp::HostExt::PluginBufferingAdapter(ia);
vamp::host::PluginBufferingAdapter* adapter = new vamp::host::PluginBufferingAdapter(ia);
int blocksize = adapter->getPreferredBlockSize();
if (!adapter->initialise(1, blocksize, blocksize))