summaryrefslogtreecommitdiff
path: root/rotord/src/vampHost.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src/vampHost.cpp')
-rw-r--r--rotord/src/vampHost.cpp444
1 files changed, 1 insertions, 443 deletions
diff --git a/rotord/src/vampHost.cpp b/rotord/src/vampHost.cpp
index 3b16173..c1340f2 100644
--- a/rotord/src/vampHost.cpp
+++ b/rotord/src/vampHost.cpp
@@ -1,417 +1,5 @@
#include "vampHost.h"
-int vampHost::runPlugin(string myname, string soname, string id, string output,
- int outputNo, string inputFile, ostream& out, 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(inputFile.c_str(), SFM_READ, &sfinfo);
- if (!sndfile) {
- cerr << myname << ": ERROR: Failed to open input file \""
- << inputFile << "\": " << sf_strerror(sndfile) << endl;
- 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);
- 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;
-
- 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);
-
- vampHost::printFeatures
- (RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
- sfinfo.samplerate, outputNo, plugin->process(plugbuf, rt),
- out, useFrames);
-
- if (sfinfo.frames > 0){
- int pp = progress;
- progress = lrintf((float(currentStep * stepSize) / sfinfo.frames) * 100.f);
- if (progress != pp && out) {
- cerr << "\r" << progress << "%";
- }
- }
-
- ++currentStep;
-
- } while (finalStepsRemaining > 0);
-
- if (out) cerr << "\rDone" << endl;
-
- rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate);
-
- vampHost::printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
- sfinfo.samplerate, outputNo,
- plugin->getRemainingFeatures(), out, useFrames);
-
- returnValue = 0;
-
-done:
- delete plugin;
- sf_close(sndfile);
- return returnValue;
-}
-
-int vampHost::rotorRunPlugin(string soname, string id, string output,
- int outputNo, string inputFile, vector<float>& out, float& progress)
-{
- 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(inputFile.c_str(), SFM_READ, &sfinfo);
- if (!sndfile) {
- cerr << ": ERROR: Failed to open input file \""
- << inputFile << "\": " << sf_strerror(sndfile) << endl;
- return 1;
- }
-
- Plugin *plugin = loader->loadPlugin
- (key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE);
- if (!plugin) {
- cerr << ": ERROR: Failed to load plugin \"" << id
- << "\" from library \"" << soname << "\"" << endl;
- sf_close(sndfile);
- 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;
-
- int returnValue = 1;
- int prog = 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);
-
- vampHost::rotorGetFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),sfinfo.samplerate, outputNo,plugin->getRemainingFeatures(), out, progress);
-
- if (sfinfo.frames > 0){
- int pp = prog;
- prog = lrintf((float(currentStep * stepSize) / sfinfo.frames) * 100.f);
- if (prog != pp ) {
- cerr << "\r" << progress << "%";
- }
- }
-
- ++currentStep;
-
- } while (finalStepsRemaining > 0);
-
- cerr << "\rDone" << endl;
-
- rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate);
-
- vampHost::rotorGetFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),sfinfo.samplerate, outputNo,plugin->getRemainingFeatures(), out, progress);
-
- returnValue = 0;
-
-done:
- delete plugin;
- sf_close(sndfile);
- return returnValue;
-}
void vampHost::printFeatures(int frame, int sr, int output,
Plugin::FeatureSet features, ostream& out, bool useFrames)
@@ -495,30 +83,6 @@ void vampHost::rotorGetFeatures(int frame, int sr, int output,Plugin::FeatureSet
}
-int vampHost::QMAnalyser::process(const string inputFile){
- //vampHost::runPlugin("",settings.soname,settings.filtername, "",0, settings.inputFile, ostr,true);
- //would run the plugin, outputting progress to cerr and the data to ostr
- //
- //int runPlugin(string myname, string soname, string id, string output,int outputNo, string inputFile, ostream& out, bool frames);
-
-
- //we want to run a specific plugin, outputting progress to a mutex-protected passed variable
- //and ultimately passing the data back as a string?
- //or capture it as an array of floats?
- //get the progress as a float
- //how to handle errors?
-
- //debugger fucking up! program stalls after 1 request in debug!?
-
- string soname="qm-vamp-plugins";
- string id="qm-tempotracker";
- string myname="";
- string output="";
- int outputNo=0;
-
- vampHost::rotorRunPlugin(soname,id,output,outputNo,inputFile,beats,progress);
-
-}
void vampHost::getTimestamps(int output,Plugin::FeatureSet features, vector<float>& out){
@@ -581,13 +145,7 @@ void vampHost::getTimestamps(int output,Plugin::FeatureSet features, vector<floa
}
//}
}
-float vampHost::QMAnalyser::get_progress(){
- float p;
- mutex.lock();
- p=progress;
- mutex.unlock();
- return p;
-}
+
bool vampHost::Analyser::init(const string &soname,const string &id,const int &_channels,const int &_bits,const int &_samples,const int &_rate,int _outputNo,const map<string,float> &params){
//stuff that only happens once