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 / TestMultipleRuns.cpp @ 67:fa66ee7dcf08

History | View | Annotate | Download (8.62 KB)

1 2:c9a4bd247497 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 2:c9a4bd247497 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 "TestMultipleRuns.h"
41
42
#include <vamp-hostsdk/Plugin.h>
43
using namespace Vamp;
44
45
#include <memory>
46
using namespace std;
47
48
#include <cmath>
49
50
Tester::TestRegistrar<TestDistinctRuns>
51 39:07144cdcbedf Chris
TestDistinctRuns::m_registrar("D1", "Consecutive runs with separate instances");
52 2:c9a4bd247497 cannam
53
Tester::TestRegistrar<TestReset>
54 39:07144cdcbedf Chris
TestReset::m_registrar("D2", "Consecutive runs with a single instance using reset");
55 2:c9a4bd247497 cannam
56
Tester::TestRegistrar<TestInterleavedRuns>
57 39:07144cdcbedf Chris
TestInterleavedRuns::m_registrar("D3", "Simultaneous interleaved runs in a single thread");
58 2:c9a4bd247497 cannam
59 5:6a279da6fdd7 cannam
Tester::TestRegistrar<TestDifferentStartTimes>
60 39:07144cdcbedf Chris
TestDifferentStartTimes::m_registrar("D4", "Consecutive runs with different start times");
61 5:6a279da6fdd7 cannam
62 3:0f65bb22172b cannam
static const size_t _step = 1000;
63
64 2:c9a4bd247497 cannam
Test::Results
65 8:3019cb6b538d cannam
TestDistinctRuns::test(string key, Options options)
66 2:c9a4bd247497 cannam
{
67
    Plugin::FeatureSet f[2];
68
    int rate = 44100;
69
    Results r;
70 3:0f65bb22172b cannam
    float **data = 0;
71
    size_t channels = 0;
72
    size_t count = 100;
73 2:c9a4bd247497 cannam
74
    for (int run = 0; run < 2; ++run) {
75
        auto_ptr<Plugin> p(load(key, rate));
76 3:0f65bb22172b cannam
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
77
        if (!data) data = createTestAudio(channels, _step, count);
78
        for (size_t i = 0; i < count; ++i) {
79 67:fa66ee7dcf08 Chris
            float **ptr = new float *[channels];
80 3:0f65bb22172b cannam
            size_t idx = i * _step;
81
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
82 2:c9a4bd247497 cannam
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
83 3:0f65bb22172b cannam
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
84 67:fa66ee7dcf08 Chris
            delete[] ptr;
85 2:c9a4bd247497 cannam
            appendFeatures(f[run], fs);
86
        }
87
        Plugin::FeatureSet fs = p->getRemainingFeatures();
88
        appendFeatures(f[run], fs);
89
    }
90 3:0f65bb22172b cannam
    if (data) destroyTestAudio(data, channels);
91 2:c9a4bd247497 cannam
92
    if (!(f[0] == f[1])) {
93 8:3019cb6b538d cannam
        Result res;
94
        string message = "Consecutive runs with separate instances produce different results";
95
        if (options & NonDeterministic) res = note(message);
96
        else res = error(message);
97 52:4bd0cd3c60f3 Chris
        if (options & Verbose) dumpDiff(res, f[0], f[1]);
98 7:43eb3a4b95c8 cannam
        r.push_back(res);
99 2:c9a4bd247497 cannam
    } else {
100
        r.push_back(success());
101
    }
102
103
    return r;
104
}
105
106
Test::Results
107 8:3019cb6b538d cannam
TestReset::test(string key, Options options)
108 2:c9a4bd247497 cannam
{
109
    Plugin::FeatureSet f[2];
110
    int rate = 44100;
111
    Results r;
112 3:0f65bb22172b cannam
    float **data = 0;
113
    size_t channels = 0;
114
    size_t count = 100;
115 2:c9a4bd247497 cannam
116
    auto_ptr<Plugin> p(load(key, rate));
117 3:0f65bb22172b cannam
118 2:c9a4bd247497 cannam
    for (int run = 0; run < 2; ++run) {
119
        if (run == 1) p->reset();
120 11:82ef943a1bd2 cannam
        else if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
121 3:0f65bb22172b cannam
        if (!data) data = createTestAudio(channels, _step, count);
122
        for (size_t i = 0; i < count; ++i) {
123 67:fa66ee7dcf08 Chris
            float **ptr = new float *[channels];
124 3:0f65bb22172b cannam
            size_t idx = i * _step;
125
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
126 2:c9a4bd247497 cannam
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
127 3:0f65bb22172b cannam
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
128 67:fa66ee7dcf08 Chris
            delete[] ptr;
129 2:c9a4bd247497 cannam
            appendFeatures(f[run], fs);
130
        }
131
        Plugin::FeatureSet fs = p->getRemainingFeatures();
132
        appendFeatures(f[run], fs);
133
    }
134 3:0f65bb22172b cannam
    if (data) destroyTestAudio(data, channels);
135 2:c9a4bd247497 cannam
136
    if (!(f[0] == f[1])) {
137 8:3019cb6b538d cannam
        string message = "Consecutive runs with the same instance (using reset) produce different results";
138
        Result res;
139
        if (options & NonDeterministic) res = note(message);
140
        else res = error(message);
141 52:4bd0cd3c60f3 Chris
        if (options & Verbose) dumpDiff(res, f[0], f[1]);
142 3:0f65bb22172b cannam
        r.push_back(res);
143 2:c9a4bd247497 cannam
    } else {
144
        r.push_back(success());
145
    }
146
147
    return r;
148
}
149
150
Test::Results
151 8:3019cb6b538d cannam
TestInterleavedRuns::test(string key, Options options)
152 2:c9a4bd247497 cannam
{
153
    Plugin::FeatureSet f[2];
154
    int rate = 44100;
155
    Results r;
156 3:0f65bb22172b cannam
    float **data = 0;
157
    size_t channels = 0;
158
    size_t count = 100;
159
160 2:c9a4bd247497 cannam
    Plugin *p[2];
161
    for (int run = 0; run < 2; ++run) {
162
        p[run] = load(key, rate);
163 3:0f65bb22172b cannam
        if (!initAdapted(p[run], channels, _step, _step, r)) {
164 2:c9a4bd247497 cannam
            delete p[run];
165
            if (run > 0) delete p[0];
166
            return r;
167
        }
168 3:0f65bb22172b cannam
        if (!data) data = createTestAudio(channels, _step, count);
169 2:c9a4bd247497 cannam
    }
170 3:0f65bb22172b cannam
    for (size_t i = 0; i < count; ++i) {
171 67:fa66ee7dcf08 Chris
        float **ptr = new float *[channels];
172 3:0f65bb22172b cannam
        size_t idx = i * _step;
173
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
174 2:c9a4bd247497 cannam
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
175
        for (int run = 0; run < 2; ++run) {
176 3:0f65bb22172b cannam
            Plugin::FeatureSet fs = p[run]->process(ptr, timestamp);
177 2:c9a4bd247497 cannam
            appendFeatures(f[run], fs);
178
        }
179 67:fa66ee7dcf08 Chris
        delete[] ptr;
180 2:c9a4bd247497 cannam
    }
181
    for (int run = 0; run < 2; ++run) {
182
        Plugin::FeatureSet fs = p[run]->getRemainingFeatures();
183
        appendFeatures(f[run], fs);
184
        delete p[run];
185
    }
186
187 3:0f65bb22172b cannam
    if (data) destroyTestAudio(data, channels);
188 2:c9a4bd247497 cannam
189
    if (!(f[0] == f[1])) {
190 8:3019cb6b538d cannam
        string message = "Simultaneous runs with separate instances produce different results";
191
        Result res;
192
        if (options & NonDeterministic) res = note(message);
193
        else res = error(message);
194 52:4bd0cd3c60f3 Chris
        if (options & Verbose) dumpDiff(res, f[0], f[1]);
195 7:43eb3a4b95c8 cannam
        r.push_back(res);
196 2:c9a4bd247497 cannam
    } else {
197
        r.push_back(success());
198
    }
199
200
    return r;
201
}
202 5:6a279da6fdd7 cannam
203
Test::Results
204 8:3019cb6b538d cannam
TestDifferentStartTimes::test(string key, Options options)
205 5:6a279da6fdd7 cannam
{
206
    Plugin::FeatureSet f[2];
207
    int rate = 44100;
208
    Results r;
209
    float **data = 0;
210
    size_t channels = 0;
211
    size_t count = 100;
212
213
    for (int run = 0; run < 2; ++run) {
214
        auto_ptr<Plugin> p(load(key, rate));
215
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
216
        if (!data) data = createTestAudio(channels, _step, count);
217
        for (size_t i = 0; i < count; ++i) {
218 67:fa66ee7dcf08 Chris
            float **ptr = new float *[channels];
219 5:6a279da6fdd7 cannam
            size_t idx = i * _step;
220
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
221
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
222
            if (run == 1) timestamp = timestamp + RealTime::fromSeconds(10);
223
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
224 67:fa66ee7dcf08 Chris
            delete[] ptr;
225 5:6a279da6fdd7 cannam
            appendFeatures(f[run], fs);
226
        }
227
        Plugin::FeatureSet fs = p->getRemainingFeatures();
228
        appendFeatures(f[run], fs);
229
    }
230
    if (data) destroyTestAudio(data, channels);
231
232
    if (f[0] == f[1]) {
233 8:3019cb6b538d cannam
        Result res;
234 53:86d8a699dfbe Chris
        if (containsTimestamps(f[0])) {
235
            string message = "Consecutive runs with different starting timestamps produce the same result";
236
            if (options & NonDeterministic) {
237
                res = note(message);
238
            } else {
239
                res = warning(message);
240
            }
241
            if (options & Verbose) {
242
                cout << res.message() << endl;
243
                dump(f[0], false);
244
            }
245
        } else {
246
            res = note("Consecutive runs with different starting timestamps produce the same result (but result features contain no timestamps, so this is probably all right)");
247 52:4bd0cd3c60f3 Chris
        }
248 7:43eb3a4b95c8 cannam
        r.push_back(res);
249 5:6a279da6fdd7 cannam
    } else {
250
        r.push_back(success());
251
    }
252
253
    return r;
254
}