diff Test.cpp @ 1:d7ef749300ed

* Add tests for extremes of input audio
author cannam
date Thu, 12 Mar 2009 17:09:53 +0000
parents f89128a316e7
children 0f65bb22172b
line wrap: on
line diff
--- a/Test.cpp	Thu Mar 12 16:23:55 2009 +0000
+++ b/Test.cpp	Thu Mar 12 17:09:53 2009 +0000
@@ -44,6 +44,8 @@
 using namespace Vamp;
 using namespace Vamp::HostExt;
 
+#include <cmath>
+
 Test::Test() { }
 Test::~Test() { }
 
@@ -54,6 +56,44 @@
         (key, rate, PluginLoader::ADAPT_ALL);
 }
 
+float **
+Test::createBlock(size_t channels, size_t blocksize)
+{
+    float **b = new float *[channels];
+    for (size_t c = 0; c < channels; ++c) {
+        b[c] = new float[blocksize];
+    }
+    return b;
+}
+
+void
+Test::destroyBlock(float **blocks, size_t channels)
+{
+    for (size_t c = 0; c < channels; ++c) {
+        delete[] blocks[c];
+    }
+    delete[] blocks;
+}
+
+bool
+Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block,
+                   Results &r)
+{
+    channels = p->getMinChannelCount();
+    block = p->getPreferredBlockSize();
+    step = p->getPreferredStepSize();
+    if (block == 0) block = 1024;
+    if (step == 0) {
+        if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2;
+        else step = block;
+    }
+    if (!p->initialise(channels, step, block)) {
+        r.push_back(error("initialisation with default values failed"));
+        return false;
+    }
+    return true;
+}
+
 void
 Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
 {
@@ -68,6 +108,23 @@
 }
 
 bool
+Test::allFeaturesValid(const Plugin::FeatureSet &b)
+{
+    for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
+        for (int j = 0; j < (int)i->second.size(); ++j) {
+            if (i->second[j].values.empty()) continue;
+            for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
+                if (isnan(i->second[j].values[k]) ||
+                    isinf(i->second[j].values[k])) {
+                    return false;
+                }
+            }
+        }
+    }
+    return true;
+}
+
+bool
 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
 {
     if (a.size() != b.size()) return false;