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 / TestInputExtremes.cpp @ 42:f1e8e14e9c96

History | View | Annotate | Download (8.08 KB)

1 1:d7ef749300ed 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 1:d7ef749300ed 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 "TestInputExtremes.h"
41
42
#include <vamp-hostsdk/Plugin.h>
43
using namespace Vamp;
44
45
#include <memory>
46
using namespace std;
47
48 2:c9a4bd247497 cannam
#include <cstdlib>
49 1:d7ef749300ed cannam
#include <cmath>
50
51
Tester::TestRegistrar<TestNormalInput>
52 39:07144cdcbedf Chris
TestNormalInput::m_registrar("C1", "Normal input");
53 1:d7ef749300ed cannam
54
Tester::TestRegistrar<TestNoInput>
55 39:07144cdcbedf Chris
TestNoInput::m_registrar("C2", "Empty input");
56 1:d7ef749300ed cannam
57
Tester::TestRegistrar<TestShortInput>
58 39:07144cdcbedf Chris
TestShortInput::m_registrar("C3", "Short input");
59 1:d7ef749300ed cannam
60
Tester::TestRegistrar<TestSilentInput>
61 39:07144cdcbedf Chris
TestSilentInput::m_registrar("C4", "Absolutely silent input");
62 1:d7ef749300ed cannam
63
Tester::TestRegistrar<TestTooLoudInput>
64 39:07144cdcbedf Chris
TestTooLoudInput::m_registrar("C5", "Input beyond traditional +/-1 range");
65 1:d7ef749300ed cannam
66
Tester::TestRegistrar<TestRandomInput>
67 39:07144cdcbedf Chris
TestRandomInput::m_registrar("C6", "Random input");
68 1:d7ef749300ed cannam
69
Test::Results
70 8:3019cb6b538d cannam
TestNormalInput::test(string key, Options options)
71 1:d7ef749300ed cannam
{
72 2:c9a4bd247497 cannam
    Plugin::FeatureSet f;
73 1:d7ef749300ed cannam
    int rate = 44100;
74
    auto_ptr<Plugin> p(load(key, rate));
75
    Results r;
76
    size_t channels, step, blocksize;
77
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
78
    float **block = createBlock(channels, blocksize);
79
    int idx = 0;
80
    for (int i = 0; i < 200; ++i) {
81
        for (size_t j = 0; j < blocksize; ++j) {
82
            for (size_t c = 0; c < channels; ++c) {
83
                block[c][j] = sinf(float(idx) / 10.f);
84
            }
85
            ++idx;
86
        }
87
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
88 2:c9a4bd247497 cannam
        Plugin::FeatureSet fs = p->process(block, timestamp);
89
        appendFeatures(f, fs);
90 1:d7ef749300ed cannam
    }
91
    destroyBlock(block, channels);
92
    Plugin::FeatureSet fs = p->getRemainingFeatures();
93 2:c9a4bd247497 cannam
    appendFeatures(f, fs);
94
    if (allFeaturesValid(f)) {
95 1:d7ef749300ed cannam
        r.push_back(success());
96
    } else {
97 17:ea8865f488a0 cannam
        r.push_back(warning("Plugin returned one or more NaN/inf values"));
98 8:3019cb6b538d cannam
        if (options & Verbose) dump(f);
99 1:d7ef749300ed cannam
    }
100
    return r;
101
}
102
103
Test::Results
104 16:419d538874a8 cannam
TestNoInput::test(string key, Options)
105 1:d7ef749300ed cannam
{
106
    auto_ptr<Plugin> p(load(key));
107
    Results r;
108
    size_t channels, step, block;
109
    if (!initDefaults(p.get(), channels, step, block, r)) return r;
110
    Plugin::FeatureSet fs = p->getRemainingFeatures();
111
    if (allFeaturesValid(fs)) {
112
        r.push_back(success());
113
    } else {
114 17:ea8865f488a0 cannam
        r.push_back(warning("Plugin returned one or more NaN/inf values"));
115 1:d7ef749300ed cannam
    }
116
    return r;
117
}
118
119
Test::Results
120 8:3019cb6b538d cannam
TestShortInput::test(string key, Options options)
121 1:d7ef749300ed cannam
{
122 2:c9a4bd247497 cannam
    Plugin::FeatureSet f;
123 1:d7ef749300ed cannam
    int rate = 44100;
124
    auto_ptr<Plugin> p(load(key, rate));
125
    Results r;
126
    size_t channels, step, blocksize;
127
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
128
    float **block = createBlock(channels, blocksize);
129
    int idx = 0;
130
    for (size_t j = 0; j < blocksize; ++j) {
131
        for (size_t c = 0; c < channels; ++c) {
132
            block[c][j] = sinf(float(idx) / 10.f);
133
        }
134
        ++idx;
135
    }
136 2:c9a4bd247497 cannam
    Plugin::FeatureSet fs = p->process(block, RealTime::zeroTime);
137
    appendFeatures(f, fs);
138 1:d7ef749300ed cannam
    destroyBlock(block, channels);
139 2:c9a4bd247497 cannam
    fs = p->getRemainingFeatures();
140
    appendFeatures(f, fs);
141
    if (allFeaturesValid(f)) {
142 1:d7ef749300ed cannam
        r.push_back(success());
143
    } else {
144 17:ea8865f488a0 cannam
        r.push_back(warning("Plugin returned one or more NaN/inf values"));
145 8:3019cb6b538d cannam
        if (options & Verbose) dump(f);
146 1:d7ef749300ed cannam
    }
147
    return r;
148
}
149
150
Test::Results
151 8:3019cb6b538d cannam
TestSilentInput::test(string key, Options options)
152 1:d7ef749300ed cannam
{
153 2:c9a4bd247497 cannam
    Plugin::FeatureSet f;
154 1:d7ef749300ed cannam
    int rate = 44100;
155
    auto_ptr<Plugin> p(load(key, rate));
156
    Results r;
157
    size_t channels, step, blocksize;
158
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
159
    float **block = createBlock(channels, blocksize);
160
    for (size_t j = 0; j < blocksize; ++j) {
161
        for (size_t c = 0; c < channels; ++c) {
162
            block[c][j] = 0.f;
163
        }
164
    }
165
    for (int i = 0; i < 200; ++i) {
166
        RealTime timestamp = RealTime::frame2RealTime(i * blocksize, rate);
167 2:c9a4bd247497 cannam
        Plugin::FeatureSet fs = p->process(block, timestamp);
168
        appendFeatures(f, fs);
169 1:d7ef749300ed cannam
    }
170
    destroyBlock(block, channels);
171
    Plugin::FeatureSet fs = p->getRemainingFeatures();
172 2:c9a4bd247497 cannam
    appendFeatures(f, fs);
173
    if (allFeaturesValid(f)) {
174 1:d7ef749300ed cannam
        r.push_back(success());
175
    } else {
176 17:ea8865f488a0 cannam
        r.push_back(warning("Plugin returned one or more NaN/inf values"));
177 8:3019cb6b538d cannam
        if (options & Verbose) dump(f);
178 1:d7ef749300ed cannam
    }
179
    return r;
180
}
181
182
Test::Results
183 8:3019cb6b538d cannam
TestTooLoudInput::test(string key, Options options)
184 1:d7ef749300ed cannam
{
185 2:c9a4bd247497 cannam
    Plugin::FeatureSet f;
186 1:d7ef749300ed cannam
    int rate = 44100;
187
    auto_ptr<Plugin> p(load(key, rate));
188
    Results r;
189
    size_t channels, step, blocksize;
190
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
191
    float **block = createBlock(channels, blocksize);
192
    int idx = 0;
193
    for (int i = 0; i < 200; ++i) {
194
        for (size_t j = 0; j < blocksize; ++j) {
195
            for (size_t c = 0; c < channels; ++c) {
196
                block[c][j] = 1000.f * sinf(float(idx) / 10.f);
197
            }
198
            ++idx;
199
        }
200
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
201 2:c9a4bd247497 cannam
        Plugin::FeatureSet fs = p->process(block, timestamp);
202
        appendFeatures(f, fs);
203 1:d7ef749300ed cannam
    }
204
    destroyBlock(block, channels);
205
    Plugin::FeatureSet fs = p->getRemainingFeatures();
206 2:c9a4bd247497 cannam
    appendFeatures(f, fs);
207
    if (allFeaturesValid(f)) {
208 1:d7ef749300ed cannam
        r.push_back(success());
209
    } else {
210 17:ea8865f488a0 cannam
        r.push_back(warning("Plugin returned one or more NaN/inf values"));
211 8:3019cb6b538d cannam
        if (options & Verbose) dump(f);
212 1:d7ef749300ed cannam
    }
213
    return r;
214
}
215
216
Test::Results
217 8:3019cb6b538d cannam
TestRandomInput::test(string key, Options options)
218 1:d7ef749300ed cannam
{
219 2:c9a4bd247497 cannam
    Plugin::FeatureSet f;
220 1:d7ef749300ed cannam
    int rate = 44100;
221
    auto_ptr<Plugin> p(load(key, rate));
222
    Results r;
223
    size_t channels, step, blocksize;
224
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
225
    float **block = createBlock(channels, blocksize);
226
    int idx = 0;
227
    for (int i = 0; i < 100; ++i) {
228
        for (size_t j = 0; j < blocksize; ++j) {
229
            for (size_t c = 0; c < channels; ++c) {
230 21:019f6415950d cannam
                block[c][j] = (float(rand()) / RAND_MAX) * 2.0 - 1.0;
231 1:d7ef749300ed cannam
            }
232
            ++idx;
233
        }
234
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
235 2:c9a4bd247497 cannam
        Plugin::FeatureSet fs = p->process(block, timestamp);
236
        appendFeatures(f, fs);
237 1:d7ef749300ed cannam
    }
238
    destroyBlock(block, channels);
239
    Plugin::FeatureSet fs = p->getRemainingFeatures();
240 2:c9a4bd247497 cannam
    appendFeatures(f, fs);
241
    if (allFeaturesValid(f)) {
242 1:d7ef749300ed cannam
        r.push_back(success());
243
    } else {
244 17:ea8865f488a0 cannam
        r.push_back(warning("Plugin returned one or more NaN/inf values"));
245 8:3019cb6b538d cannam
        if (options & Verbose) dump(f);
246 1:d7ef749300ed cannam
    }
247
    return r;
248
}