comparison 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
comparison
equal deleted inserted replaced
0:f89128a316e7 1:d7ef749300ed
42 #include <vamp-hostsdk/PluginLoader.h> 42 #include <vamp-hostsdk/PluginLoader.h>
43 43
44 using namespace Vamp; 44 using namespace Vamp;
45 using namespace Vamp::HostExt; 45 using namespace Vamp::HostExt;
46 46
47 #include <cmath>
48
47 Test::Test() { } 49 Test::Test() { }
48 Test::~Test() { } 50 Test::~Test() { }
49 51
50 Plugin * 52 Plugin *
51 Test::load(std::string key, float rate) 53 Test::load(std::string key, float rate)
52 { 54 {
53 return PluginLoader::getInstance()->loadPlugin 55 return PluginLoader::getInstance()->loadPlugin
54 (key, rate, PluginLoader::ADAPT_ALL); 56 (key, rate, PluginLoader::ADAPT_ALL);
57 }
58
59 float **
60 Test::createBlock(size_t channels, size_t blocksize)
61 {
62 float **b = new float *[channels];
63 for (size_t c = 0; c < channels; ++c) {
64 b[c] = new float[blocksize];
65 }
66 return b;
67 }
68
69 void
70 Test::destroyBlock(float **blocks, size_t channels)
71 {
72 for (size_t c = 0; c < channels; ++c) {
73 delete[] blocks[c];
74 }
75 delete[] blocks;
76 }
77
78 bool
79 Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block,
80 Results &r)
81 {
82 channels = p->getMinChannelCount();
83 block = p->getPreferredBlockSize();
84 step = p->getPreferredStepSize();
85 if (block == 0) block = 1024;
86 if (step == 0) {
87 if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2;
88 else step = block;
89 }
90 if (!p->initialise(channels, step, block)) {
91 r.push_back(error("initialisation with default values failed"));
92 return false;
93 }
94 return true;
55 } 95 }
56 96
57 void 97 void
58 Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b) 98 Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
59 { 99 {
63 Plugin::FeatureList &target = a[output]; 103 Plugin::FeatureList &target = a[output];
64 for (Plugin::FeatureList::const_iterator j = fl.begin(); j != fl.end(); ++j) { 104 for (Plugin::FeatureList::const_iterator j = fl.begin(); j != fl.end(); ++j) {
65 target.push_back(*j); 105 target.push_back(*j);
66 } 106 }
67 } 107 }
108 }
109
110 bool
111 Test::allFeaturesValid(const Plugin::FeatureSet &b)
112 {
113 for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
114 for (int j = 0; j < (int)i->second.size(); ++j) {
115 if (i->second[j].values.empty()) continue;
116 for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
117 if (isnan(i->second[j].values[k]) ||
118 isinf(i->second[j].values[k])) {
119 return false;
120 }
121 }
122 }
123 }
124 return true;
68 } 125 }
69 126
70 bool 127 bool
71 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b) 128 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
72 { 129 {