changeset 29:d97aafa99828

* Deal properly with the fact that the host doesn't support non-power-of-two blocksizes in frequency domain
author cannam
date Tue, 16 May 2006 11:33:50 +0000
parents ca1309b937b6
children 4412c619b373
files host/vamp-simple-host.cpp
diffstat 1 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/host/vamp-simple-host.cpp	Fri May 12 14:46:35 2006 +0000
+++ b/host/vamp-simple-host.cpp	Tue May 16 11:33:50 2006 +0000
@@ -169,11 +169,27 @@
     int stepSize = plugin->getPreferredStepSize();
 
     cerr << "Preferred block size = " << blockSize << ", step size = "
-              << stepSize << endl;
+         << stepSize << endl;
 
     if (blockSize == 0) blockSize = 1024;
     if (stepSize == 0) stepSize = blockSize;
 
+    bool rightBlockSize = true;
+    if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
+        int p = 1, b = blockSize;
+        while (b) {
+            p <<= 1;
+            b >>= 1;
+        }
+        if (p != blockSize * 2) {
+            cerr << "WARNING: Plugin requested non-power-of-two block size of "
+                 << blockSize << ",\nwhich is not supported by this host.  ";
+            blockSize = p;
+            cerr << "Rounding up to " << blockSize << "." << endl;
+            rightBlockSize = false;
+        }
+    }
+
     int channels = sfinfo.channels;
 
     float *filebuf = new float[blockSize * channels];
@@ -190,6 +206,8 @@
     Vamp::Plugin::OutputList outputs = plugin->getOutputDescriptors();
     Vamp::Plugin::OutputDescriptor od;
 
+    int returnValue = 1;
+
     int output = 0;
     if (argc == 4) output = atoi(argv[3]);
 
@@ -219,7 +237,15 @@
     od = outputs[output];
     cerr << "Output is " << od.name << endl;
 
-    plugin->initialise(channels, stepSize, blockSize);
+    if (!plugin->initialise(channels, stepSize, blockSize)) {
+        cerr << "ERROR: Plugin initialise (channels = " << channels
+             << ", stepSize = " << stepSize << ", blockSize = "
+             << blockSize << ") failed." << endl;
+        if (!rightBlockSize) {
+            cerr << "(Probably because I couldn't provide the plugin's preferred block size.)" << endl;
+        }
+        goto done;
+    }
 
     for (size_t i = 0; i < sfinfo.frames; i += stepSize) {
 
@@ -261,12 +287,14 @@
     printFeatures(sfinfo.frames, sfinfo.samplerate, output,
                   plugin->getRemainingFeatures());
 
+    returnValue = 0;
+
 done:
     delete plugin;
 
     DLCLOSE(libraryHandle);
     sf_close(sndfile);
-    return 0;
+    return returnValue;
 }
 
 void