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 @ 8:3019cb6b538d

History | View | Annotate | Download (8.05 KB)

1
/* -*- 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
    Copyright 2009 QMUL.
8

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
TestDistinctRuns::m_registrar("D1 Consecutive runs with separate instances");
52

    
53
Tester::TestRegistrar<TestReset>
54
TestReset::m_registrar("D2 Consecutive runs with a single instance using reset");
55

    
56
Tester::TestRegistrar<TestInterleavedRuns>
57
TestInterleavedRuns::m_registrar("D3 Simultaneous interleaved runs in a single thread");
58

    
59
Tester::TestRegistrar<TestDifferentStartTimes>
60
TestDifferentStartTimes::m_registrar("D4 Consecutive runs with different start times");
61

    
62
static const size_t _step = 1000;
63

    
64
Test::Results
65
TestDistinctRuns::test(string key, Options options)
66
{
67
    Plugin::FeatureSet f[2];
68
    int rate = 44100;
69
    Results r;
70
    float **data = 0;
71
    size_t channels = 0;
72
    size_t count = 100;
73

    
74
    for (int run = 0; run < 2; ++run) {
75
        auto_ptr<Plugin> p(load(key, rate));
76
        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
            float *ptr[channels];
80
            size_t idx = i * _step;
81
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
82
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
83
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
84
            appendFeatures(f[run], fs);
85
        }
86
        Plugin::FeatureSet fs = p->getRemainingFeatures();
87
        appendFeatures(f[run], fs);
88
    }
89
    if (data) destroyTestAudio(data, channels);
90

    
91
    if (!(f[0] == f[1])) {
92
        Result res;
93
        string message = "Consecutive runs with separate instances produce different results";
94
        if (options & NonDeterministic) res = note(message);
95
        else res = error(message);
96
        if (options & Verbose) dump(res, f[0], f[1]);
97
        r.push_back(res);
98
    } else {
99
        r.push_back(success());
100
    }
101

    
102
    return r;
103
}
104

    
105
Test::Results
106
TestReset::test(string key, Options options)
107
{
108
    Plugin::FeatureSet f[2];
109
    int rate = 44100;
110
    Results r;
111
    float **data = 0;
112
    size_t channels = 0;
113
    size_t count = 100;
114

    
115
    auto_ptr<Plugin> p(load(key, rate));
116

    
117
    for (int run = 0; run < 2; ++run) {
118
        if (run == 1) p->reset();
119
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
120
        if (!data) data = createTestAudio(channels, _step, count);
121
        for (size_t i = 0; i < count; ++i) {
122
            float *ptr[channels];
123
            size_t idx = i * _step;
124
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
125
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
126
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
127
            appendFeatures(f[run], fs);
128
        }
129
        Plugin::FeatureSet fs = p->getRemainingFeatures();
130
        appendFeatures(f[run], fs);
131
    }
132
    if (data) destroyTestAudio(data, channels);
133

    
134
    if (!(f[0] == f[1])) {
135
        string message = "Consecutive runs with the same instance (using reset) produce different results";
136
        Result res;
137
        if (options & NonDeterministic) res = note(message);
138
        else res = error(message);
139
        if (options & Verbose) dump(res, f[0], f[1]);
140
        r.push_back(res);
141
    } else {
142
        r.push_back(success());
143
    }
144

    
145
    return r;
146
}
147

    
148
Test::Results
149
TestInterleavedRuns::test(string key, Options options)
150
{
151
    Plugin::FeatureSet f[2];
152
    int rate = 44100;
153
    Results r;
154
    float **data = 0;
155
    size_t channels = 0;
156
    size_t count = 100;
157

    
158
    Plugin *p[2];
159
    for (int run = 0; run < 2; ++run) {
160
        p[run] = load(key, rate);
161
        if (!initAdapted(p[run], channels, _step, _step, r)) {
162
            delete p[run];
163
            if (run > 0) delete p[0];
164
            return r;
165
        }
166
        if (!data) data = createTestAudio(channels, _step, count);
167
    }
168
    for (size_t i = 0; i < count; ++i) {
169
        float *ptr[channels];
170
        size_t idx = i * _step;
171
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
172
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
173
        for (int run = 0; run < 2; ++run) {
174
            Plugin::FeatureSet fs = p[run]->process(ptr, timestamp);
175
            appendFeatures(f[run], fs);
176
        }
177
    }
178
    for (int run = 0; run < 2; ++run) {
179
        Plugin::FeatureSet fs = p[run]->getRemainingFeatures();
180
        appendFeatures(f[run], fs);
181
        delete p[run];
182
    }
183

    
184
    if (data) destroyTestAudio(data, channels);
185

    
186
    if (!(f[0] == f[1])) {
187
        string message = "Simultaneous runs with separate instances produce different results";
188
        Result res;
189
        if (options & NonDeterministic) res = note(message);
190
        else res = error(message);
191
        if (options & Verbose) dump(res, f[0], f[1]);
192
        r.push_back(res);
193
    } else {
194
        r.push_back(success());
195
    }
196

    
197
    return r;
198
}
199

    
200
Test::Results
201
TestDifferentStartTimes::test(string key, Options options)
202
{
203
    Plugin::FeatureSet f[2];
204
    int rate = 44100;
205
    Results r;
206
    float **data = 0;
207
    size_t channels = 0;
208
    size_t count = 100;
209

    
210
    for (int run = 0; run < 2; ++run) {
211
        auto_ptr<Plugin> p(load(key, rate));
212
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
213
        if (!data) data = createTestAudio(channels, _step, count);
214
        for (size_t i = 0; i < count; ++i) {
215
            float *ptr[channels];
216
            size_t idx = i * _step;
217
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
218
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
219
            if (run == 1) timestamp = timestamp + RealTime::fromSeconds(10);
220
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
221
            appendFeatures(f[run], fs);
222
        }
223
        Plugin::FeatureSet fs = p->getRemainingFeatures();
224
        appendFeatures(f[run], fs);
225
    }
226
    if (data) destroyTestAudio(data, channels);
227

    
228
    if (f[0] == f[1]) {
229
        string message = "Consecutive runs with different starting timestamps produce the same result";
230
        Result res;
231
        if (options & NonDeterministic) res = note(message);
232
        else res = error(message);
233
        if (options & Verbose) dump(res, f[0], f[1]);
234
        r.push_back(res);
235
    } else {
236
        r.push_back(success());
237
    }
238

    
239
    return r;
240
}