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