Revision 52:4bd0cd3c60f3
| .hgsubstate | ||
|---|---|---|
| 1 |
e43186ff8854485f4985eddf55b77b589a563857 vamp-plugin-sdk |
|
| 1 |
654a7e9839f648b6eeb81533f8a696560c895501 vamp-plugin-sdk |
|
| Test.cpp | ||
|---|---|---|
| 54 | 54 |
Test::Test() { }
|
| 55 | 55 |
Test::~Test() { }
|
| 56 | 56 |
|
| 57 |
using std::cerr; |
|
| 58 |
using std::cout; |
|
| 59 |
using std::endl; |
|
| 60 |
using std::string; |
|
| 61 |
|
|
| 57 | 62 |
Plugin * |
| 58 |
Test::load(std::string key, float rate)
|
|
| 63 |
Test::load(string key, float rate) |
|
| 59 | 64 |
{
|
| 60 | 65 |
Plugin *p = PluginLoader::getInstance()->loadPlugin |
| 61 | 66 |
(key, rate, PluginLoader::ADAPT_ALL); |
| ... | ... | |
| 171 | 176 |
} |
| 172 | 177 |
|
| 173 | 178 |
void |
| 174 |
Test::dump(const Plugin::FeatureSet &fs) |
|
| 179 |
Test::dumpFeature(const Plugin::Feature &f, bool showValues) |
|
| 180 |
{
|
|
| 181 |
cout << " Timestamp: " << (!f.hasTimestamp ? "(none)" : f.timestamp.toText()) << endl; |
|
| 182 |
cout << " Duration: " << (!f.hasDuration ? "(none)" : f.duration.toText()) << endl; |
|
| 183 |
cout << " Label: " << (f.label == "" ? "(none)" : f.label) << endl; |
|
| 184 |
if (showValues) {
|
|
| 185 |
cout << " Values (" << f.values.size() << "): " << (f.values.empty() ? "(none)" : "");
|
|
| 186 |
for (int j = 0; j < (int)f.values.size(); ++j) {
|
|
| 187 |
cout << f.values[j] << " "; |
|
| 188 |
} |
|
| 189 |
cout << endl; |
|
| 190 |
} else {
|
|
| 191 |
cout << " Values (" << f.values.size() << "): (elided)" << endl;
|
|
| 192 |
} |
|
| 193 |
} |
|
| 194 |
|
|
| 195 |
void |
|
| 196 |
Test::dump(const Plugin::FeatureSet &fs, bool showValues) |
|
| 175 | 197 |
{
|
| 176 | 198 |
for (Plugin::FeatureSet::const_iterator fsi = fs.begin(); |
| 177 | 199 |
fsi != fs.end(); ++fsi) {
|
| 178 | 200 |
int output = fsi->first; |
| 179 |
std::cout << "Output " << output << ":" << std::endl;
|
|
| 201 |
cout << "Output " << output << ":" << endl;
|
|
| 180 | 202 |
const Plugin::FeatureList &fl = fsi->second; |
| 181 | 203 |
for (int i = 0; i < (int)fl.size(); ++i) {
|
| 182 |
std::cout << " Feature " << i << ":" << std::endl;
|
|
| 204 |
cout << " Feature " << i << ":" << endl;
|
|
| 183 | 205 |
const Plugin::Feature &f = fl[i]; |
| 184 |
std::cout << " Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl; |
|
| 185 |
std::cout << " Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl; |
|
| 186 |
std::cout << " Label: " << (f.label == "" ? "(none)" : f.label) << std::endl; |
|
| 187 |
std::cout << " Value: " << (f.values.empty() ? "(none)" : ""); |
|
| 188 |
for (int j = 0; j < (int)f.values.size(); ++j) {
|
|
| 189 |
std::cout << f.values[j] << " "; |
|
| 190 |
} |
|
| 191 |
std::cout << std::endl; |
|
| 206 |
dumpFeature(f, showValues); |
|
| 192 | 207 |
} |
| 193 | 208 |
} |
| 194 | 209 |
} |
| 195 | 210 |
|
| 196 | 211 |
void |
| 197 |
Test::dump(const Result &r, |
|
| 198 |
const Plugin::FeatureSet &a, |
|
| 199 |
const Plugin::FeatureSet &b) |
|
| 212 |
Test::dumpTwo(const Result &r,
|
|
| 213 |
const Plugin::FeatureSet &a,
|
|
| 214 |
const Plugin::FeatureSet &b)
|
|
| 200 | 215 |
{
|
| 201 | 216 |
std::cout << r.message() << std::endl; |
| 202 | 217 |
std::cout << "\nFirst result set:" << std::endl; |
| 203 |
dump(a); |
|
| 218 |
dump(a, false);
|
|
| 204 | 219 |
std::cout << "\nSecond result set:" << std::endl; |
| 205 |
dump(b); |
|
| 220 |
dump(b, false);
|
|
| 206 | 221 |
std::cout << std::endl; |
| 207 | 222 |
} |
| 208 | 223 |
|
| 224 |
void |
|
| 225 |
Test::dumpDiff(const Result &r, |
|
| 226 |
const Plugin::FeatureSet &a, |
|
| 227 |
const Plugin::FeatureSet &b) |
|
| 228 |
{
|
|
| 229 |
cout << r.message() << endl; |
|
| 230 |
cout << "\nDifferences follow:" << endl; |
|
| 231 |
if (a.size() != b.size()) {
|
|
| 232 |
cout << "*** First result set has features on " << a.size() |
|
| 233 |
<< " output(s), second has features on " << b.size() |
|
| 234 |
<< endl; |
|
| 235 |
return; |
|
| 236 |
} |
|
| 237 |
Plugin::FeatureSet::const_iterator ai = a.begin(); |
|
| 238 |
Plugin::FeatureSet::const_iterator bi = b.begin(); |
|
| 239 |
while (ai != a.end()) {
|
|
| 240 |
if (ai->first != bi->first) {
|
|
| 241 |
cout << "\n*** Output number mismatch: first result set says " |
|
| 242 |
<< ai->first << " where second says " << bi->first |
|
| 243 |
<< endl; |
|
| 244 |
} else {
|
|
| 245 |
cout << "\nOutput " << ai->first << ":" << endl; |
|
| 246 |
if (ai->second.size() != bi->second.size()) {
|
|
| 247 |
cout << "*** First result set has " << ai->second.size() |
|
| 248 |
<< " feature(s) on this output, second has " |
|
| 249 |
<< bi->second.size() << endl; |
|
| 250 |
} else {
|
|
| 251 |
int fno = 0; |
|
| 252 |
int diffcount = 0; |
|
| 253 |
Plugin::FeatureList::const_iterator afi = ai->second.begin(); |
|
| 254 |
Plugin::FeatureList::const_iterator bfi = bi->second.begin(); |
|
| 255 |
while (afi != ai->second.end()) {
|
|
| 256 |
if (!(*afi == *bfi)) {
|
|
| 257 |
if (diffcount == 0) {
|
|
| 258 |
bool differInValues = (afi->values != bfi->values); |
|
| 259 |
if (afi->hasTimestamp != bfi->hasTimestamp) {
|
|
| 260 |
cout << "*** Feature " << fno << " differs in presence of timestamp (" << afi->hasTimestamp << " vs " << bfi->hasTimestamp << ")" << endl;
|
|
| 261 |
} |
|
| 262 |
if (afi->hasTimestamp && (afi->timestamp != bfi->timestamp)) {
|
|
| 263 |
cout << "*** Feature " << fno << " differs in timestamp (" << afi->timestamp << " vs " << bfi->timestamp << " )" << endl;
|
|
| 264 |
} |
|
| 265 |
if (afi->hasDuration != bfi->hasDuration) {
|
|
| 266 |
cout << "*** Feature " << fno << " differs in presence of duration (" << afi->hasDuration << " vs " << bfi->hasDuration << ")" << endl;
|
|
| 267 |
} |
|
| 268 |
if (afi->hasDuration && (afi->duration != bfi->duration)) {
|
|
| 269 |
cout << "*** Feature " << fno << " differs in duration (" << afi->duration << " vs " << bfi->duration << " )" << endl;
|
|
| 270 |
} |
|
| 271 |
if (afi->label != bfi->label) {
|
|
| 272 |
cout << "*** Feature " << fno << " differs in label" << endl; |
|
| 273 |
} |
|
| 274 |
if (differInValues) {
|
|
| 275 |
cout << "*** Feature " << fno << " differs in values" << endl; |
|
| 276 |
} |
|
| 277 |
cout << " First output:" << endl; |
|
| 278 |
dumpFeature(*afi, differInValues); |
|
| 279 |
cout << " Second output:" << endl; |
|
| 280 |
dumpFeature(*bfi, differInValues); |
|
| 281 |
} |
|
| 282 |
++diffcount; |
|
| 283 |
} |
|
| 284 |
++fno; |
|
| 285 |
++afi; |
|
| 286 |
++bfi; |
|
| 287 |
} |
|
| 288 |
if (diffcount > 1) {
|
|
| 289 |
cout << diffcount-1 << " subsequent differing feature(s) elided" << endl; |
|
| 290 |
} |
|
| 291 |
} |
|
| 292 |
} |
|
| 293 |
++ai; |
|
| 294 |
++bi; |
|
| 295 |
} |
|
| 296 |
cout << endl; |
|
| 297 |
} |
|
| 298 |
|
|
| 209 | 299 |
bool |
| 210 | 300 |
operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b) |
| 211 | 301 |
{
|
| Test.h | ||
|---|---|---|
| 110 | 110 |
|
| 111 | 111 |
bool allFeaturesValid(const Vamp::Plugin::FeatureSet &); // i.e. no NaN/inf |
| 112 | 112 |
|
| 113 |
void dump(const Vamp::Plugin::FeatureSet &); |
|
| 114 |
void dump(const Result &r, |
|
| 115 |
const Vamp::Plugin::FeatureSet &, |
|
| 116 |
const Vamp::Plugin::FeatureSet &); |
|
| 113 |
void dumpFeature(const Vamp::Plugin::Feature &, bool showValues); |
|
| 114 |
void dump(const Vamp::Plugin::FeatureSet &, bool showValues = true); |
|
| 115 |
void dumpTwo(const Result &r, |
|
| 116 |
const Vamp::Plugin::FeatureSet &, |
|
| 117 |
const Vamp::Plugin::FeatureSet &); |
|
| 118 |
void dumpDiff(const Result &r, |
|
| 119 |
const Vamp::Plugin::FeatureSet &, |
|
| 120 |
const Vamp::Plugin::FeatureSet &); |
|
| 117 | 121 |
}; |
| 118 | 122 |
|
| 119 | 123 |
extern bool operator==(const Vamp::Plugin::FeatureSet &a, |
| TestDefaults.cpp | ||
|---|---|---|
| 103 | 103 |
Result res; |
| 104 | 104 |
if (options & NonDeterministic) res = note(message); |
| 105 | 105 |
else res = error(message); |
| 106 |
if (options & Verbose) dump(res, f[0], f[1]); |
|
| 106 |
if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
|
| 107 | 107 |
r.push_back(res); |
| 108 | 108 |
} else {
|
| 109 | 109 |
r.push_back(success()); |
| ... | ... | |
| 163 | 163 |
Result res; |
| 164 | 164 |
if (options & NonDeterministic) res = note(message); |
| 165 | 165 |
else res = error(message); |
| 166 |
if (options & Verbose) dump(res, f[0], f[1]); |
|
| 166 |
if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
|
| 167 | 167 |
r.push_back(res); |
| 168 | 168 |
} else {
|
| 169 | 169 |
r.push_back(success()); |
| ... | ... | |
| 224 | 224 |
p->setParameter(pl[i].identifier, value); |
| 225 | 225 |
} |
| 226 | 226 |
|
| 227 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
|
| 227 |
if (!initAdapted(p.get(), channels, _step, _step, r)) {
|
|
| 228 |
|
|
| 229 |
// OK, plugin didn't like that. Let's try a different tack |
|
| 230 |
// -- set everything to min except those parameters whose |
|
| 231 |
// default is min, and set those to half way instead |
|
| 232 |
|
|
| 233 |
for (int i = 0; i < (int)pl.size(); ++i) {
|
|
| 234 |
float value = pl[i].minValue; |
|
| 235 |
if (value == pl[i].defaultValue) {
|
|
| 236 |
value = (pl[i].maxValue + pl[i].minValue) / 2; |
|
| 237 |
value = ceil(value / pl[i].quantizeStep) * pl[i].quantizeStep; |
|
| 238 |
if (value > pl[i].maxValue) {
|
|
| 239 |
value = pl[i].maxValue; |
|
| 240 |
} |
|
| 241 |
} |
|
| 242 |
p->setParameter(pl[i].identifier, value); |
|
| 243 |
} |
|
| 244 |
|
|
| 245 |
r = Results(); |
|
| 246 |
if (!initAdapted(p.get(), channels, _step, _step, r)) {
|
|
| 247 |
// Still didn't work, give up |
|
| 248 |
return r; |
|
| 249 |
} |
|
| 250 |
} |
|
| 228 | 251 |
|
| 229 | 252 |
// First run: construct, set params, init, process |
| 230 | 253 |
// Second run: construct, set params, init, reset, process |
| ... | ... | |
| 254 | 277 |
Result res; |
| 255 | 278 |
if (options & NonDeterministic) res = note(message); |
| 256 | 279 |
else res = error(message); |
| 257 |
if (options & Verbose) dump(res, f[0], f[1]); |
|
| 280 |
if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
|
| 258 | 281 |
r.push_back(res); |
| 259 | 282 |
} else {
|
| 260 | 283 |
r.push_back(success()); |
| TestMultipleRuns.cpp | ||
|---|---|---|
| 101 | 101 |
string message = "Consecutive runs with separate instances produce different results"; |
| 102 | 102 |
if (options & NonDeterministic) res = note(message); |
| 103 | 103 |
else res = error(message); |
| 104 |
if (options & Verbose) dump(res, f[0], f[1]); |
|
| 104 |
if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
|
| 105 | 105 |
r.push_back(res); |
| 106 | 106 |
} else {
|
| 107 | 107 |
r.push_back(success()); |
| ... | ... | |
| 148 | 148 |
Result res; |
| 149 | 149 |
if (options & NonDeterministic) res = note(message); |
| 150 | 150 |
else res = error(message); |
| 151 |
if (options & Verbose) dump(res, f[0], f[1]); |
|
| 151 |
if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
|
| 152 | 152 |
r.push_back(res); |
| 153 | 153 |
} else {
|
| 154 | 154 |
r.push_back(success()); |
| ... | ... | |
| 204 | 204 |
Result res; |
| 205 | 205 |
if (options & NonDeterministic) res = note(message); |
| 206 | 206 |
else res = error(message); |
| 207 |
if (options & Verbose) dump(res, f[0], f[1]); |
|
| 207 |
if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
|
| 208 | 208 |
r.push_back(res); |
| 209 | 209 |
} else {
|
| 210 | 210 |
r.push_back(success()); |
| ... | ... | |
| 250 | 250 |
Result res; |
| 251 | 251 |
if (options & NonDeterministic) res = note(message); |
| 252 | 252 |
else res = warning(message); |
| 253 |
if (options & Verbose) dump(res, f[0], f[1]); |
|
| 253 |
if (options & Verbose) {
|
|
| 254 |
cout << message << endl; |
|
| 255 |
dump(f[0], false); |
|
| 256 |
} |
|
| 254 | 257 |
r.push_back(res); |
| 255 | 258 |
} else {
|
| 256 | 259 |
r.push_back(success()); |
Also available in: Unified diff