To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / TestOutputs.cpp @ 67:fa66ee7dcf08

History | View | Annotate | Download (6.48 KB)

1 3:0f65bb22172b 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 3:0f65bb22172b 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 "TestOutputs.h"
41
42
#include <vamp-hostsdk/Plugin.h>
43 4:d8724c5a6d83 cannam
#include <vamp-hostsdk/PluginLoader.h>
44 3:0f65bb22172b cannam
using namespace Vamp;
45 4:d8724c5a6d83 cannam
using namespace Vamp::HostExt;
46 3:0f65bb22172b cannam
47
#include <set>
48
#include <memory>
49
using namespace std;
50
51
#include <cmath>
52
53
Tester::TestRegistrar<TestOutputNumbers>
54 39:07144cdcbedf Chris
TestOutputNumbers::m_registrar("B1", "Output number mismatching");
55 3:0f65bb22172b cannam
56
Tester::TestRegistrar<TestTimestamps>
57 39:07144cdcbedf Chris
TestTimestamps::m_registrar("B2", "Invalid or dubious timestamp usage");
58 3:0f65bb22172b cannam
59
static const size_t _step = 1000;
60
61
Test::Results
62 8:3019cb6b538d cannam
TestOutputNumbers::test(string key, Options options)
63 3:0f65bb22172b cannam
{
64
    int rate = 44100;
65
    auto_ptr<Plugin> p(load(key, rate));
66
    Plugin::FeatureSet f;
67
    Results r;
68
    float **data = 0;
69
    size_t channels = 0;
70
    size_t count = 100;
71
72
    if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
73
    if (!data) data = createTestAudio(channels, _step, count);
74
    for (size_t i = 0; i < count; ++i) {
75 67:fa66ee7dcf08 Chris
        float **ptr = new float *[channels];
76 3:0f65bb22172b cannam
        size_t idx = i * _step;
77
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
78
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
79
        Plugin::FeatureSet fs = p->process(ptr, timestamp);
80 67:fa66ee7dcf08 Chris
        delete[] ptr;
81 3:0f65bb22172b cannam
        appendFeatures(f, fs);
82
    }
83
    Plugin::FeatureSet fs = p->getRemainingFeatures();
84
    appendFeatures(f, fs);
85
    if (data) destroyTestAudio(data, channels);
86
87
    std::set<int> used;
88
    Plugin::OutputList outputs = p->getOutputDescriptors();
89 5:6a279da6fdd7 cannam
    for (Plugin::FeatureSet::const_iterator i = f.begin();
90
         i != f.end(); ++i) {
91 3:0f65bb22172b cannam
        int o = i->first;
92
        used.insert(o);
93 4:d8724c5a6d83 cannam
        if (o < 0 || o >= (int)outputs.size()) {
94 3:0f65bb22172b cannam
            r.push_back(error("Data returned on nonexistent output"));
95
        }
96
    }
97 4:d8724c5a6d83 cannam
    for (int o = 0; o < (int)outputs.size(); ++o) {
98 3:0f65bb22172b cannam
        if (used.find(o) == used.end()) {
99 12:7dd6a549b2f9 cannam
            r.push_back(note("No results returned for output \"" + outputs[o].identifier + "\""));
100 4:d8724c5a6d83 cannam
        }
101 3:0f65bb22172b cannam
    }
102
103 8:3019cb6b538d cannam
    if (!r.empty() && (options & Verbose)) dump(f);
104 3:0f65bb22172b cannam
    return r;
105
}
106
107
Test::Results
108 8:3019cb6b538d cannam
TestTimestamps::test(string key, Options options)
109 3:0f65bb22172b cannam
{
110
    int rate = 44100;
111 4:d8724c5a6d83 cannam
112
    // we want to be sure that a buffer size adapter is not used:
113
    auto_ptr<Plugin> p(PluginLoader::getInstance()->loadPlugin
114
                       (key, rate, PluginLoader::ADAPT_ALL_SAFE));
115
116 60:9f2a6d843639 Chris
    Results r;
117 3:0f65bb22172b cannam
    Plugin::FeatureSet f;
118
    float **data = 0;
119
    size_t channels = 0;
120
    size_t step = 0, block = 0;
121
    size_t count = 100;
122
123
    if (!initDefaults(p.get(), channels, step, block, r)) return r;
124 60:9f2a6d843639 Chris
125
    Plugin::OutputList outputs = p->getOutputDescriptors();
126
    for (int i = 0; i < (int)outputs.size(); ++i) {
127
        if (outputs[i].sampleType == Plugin::OutputDescriptor::FixedSampleRate &&
128
            outputs[i].sampleRate == 0.f) {
129
            r.push_back(error("Plugin output \"" + outputs[i].identifier +
130
                              "\" has FixedSampleRate but gives sample rate as 0"));
131
        }
132
    }
133
134 3:0f65bb22172b cannam
    if (!data) data = createTestAudio(channels, block, count);
135
    for (size_t i = 0; i < count; ++i) {
136 67:fa66ee7dcf08 Chris
        float **ptr = new float *[channels];
137 3:0f65bb22172b cannam
        size_t idx = i * step;
138
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
139
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
140
        Plugin::FeatureSet fs = p->process(ptr, timestamp);
141 67:fa66ee7dcf08 Chris
        delete[] ptr;
142 3:0f65bb22172b cannam
        appendFeatures(f, fs);
143
    }
144
    Plugin::FeatureSet fs = p->getRemainingFeatures();
145
    appendFeatures(f, fs);
146
    if (data) destroyTestAudio(data, channels);
147
148 5:6a279da6fdd7 cannam
    for (Plugin::FeatureSet::const_iterator i = f.begin();
149
         i != f.end(); ++i) {
150 3:0f65bb22172b cannam
        const Plugin::OutputDescriptor &o = outputs[i->first];
151
        const Plugin::FeatureList &fl = i->second;
152
        for (int j = 0; j < (int)fl.size(); ++j) {
153 5:6a279da6fdd7 cannam
            const Plugin::Feature &fe = fl[j];
154 3:0f65bb22172b cannam
            switch (o.sampleType) {
155
            case Plugin::OutputDescriptor::OneSamplePerStep:
156 5:6a279da6fdd7 cannam
                if (fe.hasTimestamp) {
157 31:ed9d3c27f687 Chris
                    r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output \"" + o.identifier + "\""));
158 3:0f65bb22172b cannam
                }
159 5:6a279da6fdd7 cannam
                if (fe.hasDuration) {
160 31:ed9d3c27f687 Chris
                    r.push_back(note("Plugin returns features with durations on OneSamplePerStep output \"" + o.identifier + "\""));
161 3:0f65bb22172b cannam
                }
162
                break;
163
            case Plugin::OutputDescriptor::FixedSampleRate:
164
                break;
165
            case Plugin::OutputDescriptor::VariableSampleRate:
166 5:6a279da6fdd7 cannam
                if (!fe.hasTimestamp) {
167 31:ed9d3c27f687 Chris
                    r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output \"" + o.identifier + "\""));
168 3:0f65bb22172b cannam
                }
169
                break;
170
            }
171
        }
172
    }
173
174 8:3019cb6b538d cannam
    if (!r.empty() && (options & Verbose)) dump(f);
175 3:0f65bb22172b cannam
    return r;
176
}