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 @ 7:43eb3a4b95c8

History | View | Annotate | Download (7.46 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)
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 = warning("Consecutive runs with separate instances produce different results");
93
        dump(res, f[0], f[1]);
94
        r.push_back(res);
95
    } else {
96
        r.push_back(success());
97
    }
98

    
99
    return r;
100
}
101

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

    
112
    auto_ptr<Plugin> p(load(key, rate));
113

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

    
131
    if (!(f[0] == f[1])) {
132
        Result res = warning("Consecutive runs with the same instance (using reset) produce different results");
133
        dump(res, f[0], f[1]);
134
        r.push_back(res);
135
    } else {
136
        r.push_back(success());
137
    }
138

    
139
    return r;
140
}
141

    
142
Test::Results
143
TestInterleavedRuns::test(string key)
144
{
145
    Plugin::FeatureSet f[2];
146
    int rate = 44100;
147
    Results r;
148
    float **data = 0;
149
    size_t channels = 0;
150
    size_t count = 100;
151

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

    
178
    if (data) destroyTestAudio(data, channels);
179

    
180
    if (!(f[0] == f[1])) {
181
        Result res = warning("Simultaneous runs with separate instances produce different results");
182
        dump(res, f[0], f[1]);
183
        r.push_back(res);
184
    } else {
185
        r.push_back(success());
186
    }
187

    
188
    return r;
189
}
190

    
191
Test::Results
192
TestDifferentStartTimes::test(string key)
193
{
194
    Plugin::FeatureSet f[2];
195
    int rate = 44100;
196
    Results r;
197
    float **data = 0;
198
    size_t channels = 0;
199
    size_t count = 100;
200

    
201
    for (int run = 0; run < 2; ++run) {
202
        auto_ptr<Plugin> p(load(key, rate));
203
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
204
        if (!data) data = createTestAudio(channels, _step, count);
205
        for (size_t i = 0; i < count; ++i) {
206
            float *ptr[channels];
207
            size_t idx = i * _step;
208
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
209
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
210
            if (run == 1) timestamp = timestamp + RealTime::fromSeconds(10);
211
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
212
            appendFeatures(f[run], fs);
213
        }
214
        Plugin::FeatureSet fs = p->getRemainingFeatures();
215
        appendFeatures(f[run], fs);
216
    }
217
    if (data) destroyTestAudio(data, channels);
218

    
219
    if (f[0] == f[1]) {
220
        Result res = warning("Consecutive runs with different starting timestamps produce the same result");
221
        dump(res, f[0], f[1]);
222
        r.push_back(res);
223
    } else {
224
        r.push_back(success());
225
    }
226

    
227
    return r;
228
}