annotate TestInitialise.cpp @ 58:843e31e6df21

Copyright date
author Chris Cannam
date Thu, 03 Sep 2015 14:38:26 +0100
parents 56eabc22ccbf
children fa66ee7dcf08
rev   line source
cannam@10 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@10 2
cannam@10 3 /*
cannam@10 4 Vamp Plugin Tester
cannam@10 5 Chris Cannam, cannam@all-day-breakfast.com
cannam@10 6 Centre for Digital Music, Queen Mary, University of London.
Chris@42 7 Copyright 2009-2014 QMUL.
cannam@10 8
cannam@10 9 This program loads a Vamp plugin and tests its susceptibility to a
cannam@10 10 number of common pitfalls, including handling of extremes of input
cannam@10 11 data. If you can think of any additional useful tests that are
cannam@10 12 easily added, please send them to me.
cannam@10 13
cannam@10 14 Permission is hereby granted, free of charge, to any person
cannam@10 15 obtaining a copy of this software and associated documentation
cannam@10 16 files (the "Software"), to deal in the Software without
cannam@10 17 restriction, including without limitation the rights to use, copy,
cannam@10 18 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@10 19 of the Software, and to permit persons to whom the Software is
cannam@10 20 furnished to do so, subject to the following conditions:
cannam@10 21
cannam@10 22 The above copyright notice and this permission notice shall be
cannam@10 23 included in all copies or substantial portions of the Software.
cannam@10 24
cannam@10 25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@10 26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@10 27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@10 28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@10 29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@10 30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@10 31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@10 32
cannam@10 33 Except as contained in this notice, the names of the Centre for
cannam@10 34 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@10 35 shall not be used in advertising or otherwise to promote the sale,
cannam@10 36 use or other dealings in this Software without prior written
cannam@10 37 authorization.
cannam@10 38 */
cannam@10 39
cannam@10 40 #include "TestInitialise.h"
cannam@10 41
cannam@10 42 #include <vamp-hostsdk/Plugin.h>
cannam@10 43 #include <vamp-hostsdk/PluginLoader.h>
cannam@10 44 using namespace Vamp;
cannam@10 45 using namespace Vamp::HostExt;
cannam@10 46
cannam@10 47 #include <set>
cannam@10 48 #include <memory>
cannam@10 49 using namespace std;
cannam@10 50
cannam@10 51 #include <cmath>
Chris@45 52 #include <ctime>
cannam@10 53
cannam@28 54 #ifndef __GNUC__
cannam@28 55 #include <alloca.h>
cannam@28 56 #endif
cannam@28 57
cannam@10 58 Tester::TestRegistrar<TestSampleRates>
Chris@39 59 TestSampleRates::m_registrar("F1", "Different sample rates");
cannam@10 60
cannam@10 61 Tester::TestRegistrar<TestLengthyConstructor>
Chris@39 62 TestLengthyConstructor::m_registrar("F2", "Lengthy constructor");
cannam@10 63
cannam@10 64 Test::Results
cannam@23 65 TestSampleRates::test(string key, Options options)
cannam@10 66 {
cannam@10 67 int rates[] =
Chris@43 68 { 111, 800, 10099, 11024, 44100, 48000, 96000, 192000, 201011, 1094091 };
cannam@10 69
cannam@10 70 Results r;
cannam@10 71
cannam@23 72 if (options & Verbose) {
cannam@23 73 cout << " ";
cannam@23 74 }
cannam@23 75
cannam@14 76 for (int i = 0; i < int(sizeof(rates)/sizeof(rates[0])); ++i) {
cannam@10 77
cannam@10 78 int rate = rates[i];
cannam@23 79
cannam@23 80 if (options & Verbose) {
cannam@23 81 cout << "[" << rate << "Hz] " << flush;
cannam@23 82 }
cannam@23 83
cannam@10 84 auto_ptr<Plugin> p(load(key, rate));
cannam@10 85 Plugin::FeatureSet f;
cannam@10 86 float **data = 0;
cannam@10 87 size_t channels = 0;
Chris@43 88
Chris@43 89 // Aim to feed the plugin a roughly fixed input duration in secs
Chris@43 90 const float seconds = 10.f;
Chris@43 91 size_t step = 1000;
Chris@43 92 size_t count = (seconds * rate) / step;
Chris@43 93 if (count < 1) count = 1;
cannam@10 94
cannam@23 95 Results subr;
Chris@43 96 if (!initAdapted(p.get(), channels, step, step, subr)) {
cannam@23 97 // This is not an error; the plugin can legitimately
cannam@23 98 // refuse to initialise at weird settings and that's often
cannam@23 99 // the most acceptable result
cannam@23 100 if (!subr.empty()) {
cannam@23 101 r.push_back(note(subr.begin()->message()));
cannam@23 102 }
cannam@23 103 continue;
cannam@23 104 }
cannam@10 105
Chris@43 106 data = createTestAudio(channels, step, count);
Chris@43 107 for (size_t j = 0; j < count; ++j) {
cannam@28 108 #ifdef __GNUC__
cannam@10 109 float *ptr[channels];
cannam@28 110 #else
cannam@28 111 float **ptr = (float **)alloca(channels * sizeof(float));
cannam@28 112 #endif
Chris@43 113 size_t idx = j * step;
cannam@10 114 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
cannam@10 115 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
cannam@10 116 Plugin::FeatureSet fs = p->process(ptr, timestamp);
cannam@10 117 appendFeatures(f, fs);
cannam@10 118 }
cannam@10 119 Plugin::FeatureSet fs = p->getRemainingFeatures();
cannam@10 120 appendFeatures(f, fs);
cannam@10 121 destroyTestAudio(data, channels);
cannam@10 122 }
cannam@10 123
cannam@23 124 if (options & Verbose) cout << endl;
cannam@23 125
cannam@10 126 // We can't actually do anything meaningful with our results.
cannam@10 127 // We're really just testing to see whether the plugin crashes. I
cannam@10 128 // wonder whether it's possible to do any better? If not, we
cannam@10 129 // should probably report our limitations
cannam@10 130
cannam@10 131 return r;
cannam@10 132 }
cannam@10 133
cannam@10 134 Test::Results
cannam@14 135 TestLengthyConstructor::test(string key, Options)
cannam@10 136 {
cannam@10 137 time_t t0 = time(0);
cannam@10 138 auto_ptr<Plugin> p(load(key));
cannam@10 139 time_t t1 = time(0);
cannam@10 140 Results r;
cannam@10 141 if (t1 - t0 > 1) r.push_back(warning("Constructor takes some time to run: work should be deferred to initialise?"));
cannam@10 142 return r;
cannam@10 143 }
cannam@10 144