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 @ 4:d8724c5a6d83

History | View | Annotate | Download (7.76 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 "TestInputExtremes.h"
41

    
42
#include <vamp-hostsdk/Plugin.h>
43
using namespace Vamp;
44

    
45
#include <memory>
46
using namespace std;
47

    
48
#include <cstdlib>
49
#include <cmath>
50

    
51
Tester::TestRegistrar<TestNormalInput>
52
TestNormalInput::m_registrar("C1 Normal input");
53

    
54
Tester::TestRegistrar<TestNoInput>
55
TestNoInput::m_registrar("C2 Empty input");
56

    
57
Tester::TestRegistrar<TestShortInput>
58
TestShortInput::m_registrar("C3 Short input");
59

    
60
Tester::TestRegistrar<TestSilentInput>
61
TestSilentInput::m_registrar("C4 Absolutely silent input");
62

    
63
Tester::TestRegistrar<TestTooLoudInput>
64
TestTooLoudInput::m_registrar("C5 Input beyond expected +/-1 range");
65

    
66
Tester::TestRegistrar<TestRandomInput>
67
TestRandomInput::m_registrar("C6 Random input");
68

    
69
Test::Results
70
TestNormalInput::test(string key)
71
{
72
    Plugin::FeatureSet f;
73
    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
        Plugin::FeatureSet fs = p->process(block, timestamp);
89
        appendFeatures(f, fs);
90
    }
91
    destroyBlock(block, channels);
92
    Plugin::FeatureSet fs = p->getRemainingFeatures();
93
    appendFeatures(f, fs);
94
    if (allFeaturesValid(f)) {
95
        r.push_back(success());
96
    } else {
97
        r.push_back(warning("plugin returned one or more NaN/inf values"));
98
    }
99
    return r;
100
}
101

    
102
Test::Results
103
TestNoInput::test(string key)
104
{
105
    auto_ptr<Plugin> p(load(key));
106
    Results r;
107
    size_t channels, step, block;
108
    if (!initDefaults(p.get(), channels, step, block, r)) return r;
109
    Plugin::FeatureSet fs = p->getRemainingFeatures();
110
    if (allFeaturesValid(fs)) {
111
        r.push_back(success());
112
    } else {
113
        r.push_back(warning("plugin returned one or more NaN/inf values"));
114
    }
115
    return r;
116
}
117

    
118
Test::Results
119
TestShortInput::test(string key)
120
{
121
    Plugin::FeatureSet f;
122
    int rate = 44100;
123
    auto_ptr<Plugin> p(load(key, rate));
124
    Results r;
125
    size_t channels, step, blocksize;
126
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
127
    float **block = createBlock(channels, blocksize);
128
    int idx = 0;
129
    for (size_t j = 0; j < blocksize; ++j) {
130
        for (size_t c = 0; c < channels; ++c) {
131
            block[c][j] = sinf(float(idx) / 10.f);
132
        }
133
        ++idx;
134
    }
135
    Plugin::FeatureSet fs = p->process(block, RealTime::zeroTime);
136
    appendFeatures(f, fs);
137
    destroyBlock(block, channels);
138
    fs = p->getRemainingFeatures();
139
    appendFeatures(f, fs);
140
    if (allFeaturesValid(f)) {
141
        r.push_back(success());
142
    } else {
143
        r.push_back(warning("plugin returned one or more NaN/inf values"));
144
    }
145
    return r;
146
}
147

    
148
Test::Results
149
TestSilentInput::test(string key)
150
{
151
    Plugin::FeatureSet f;
152
    int rate = 44100;
153
    auto_ptr<Plugin> p(load(key, rate));
154
    Results r;
155
    size_t channels, step, blocksize;
156
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
157
    float **block = createBlock(channels, blocksize);
158
    for (size_t j = 0; j < blocksize; ++j) {
159
        for (size_t c = 0; c < channels; ++c) {
160
            block[c][j] = 0.f;
161
        }
162
    }
163
    for (int i = 0; i < 200; ++i) {
164
        RealTime timestamp = RealTime::frame2RealTime(i * blocksize, rate);
165
        Plugin::FeatureSet fs = p->process(block, timestamp);
166
        appendFeatures(f, fs);
167
    }
168
    destroyBlock(block, channels);
169
    Plugin::FeatureSet fs = p->getRemainingFeatures();
170
    appendFeatures(f, fs);
171
    if (allFeaturesValid(f)) {
172
        r.push_back(success());
173
    } else {
174
        r.push_back(warning("plugin returned one or more NaN/inf values"));
175
    }
176
    return r;
177
}
178

    
179
Test::Results
180
TestTooLoudInput::test(string key)
181
{
182
    Plugin::FeatureSet f;
183
    int rate = 44100;
184
    auto_ptr<Plugin> p(load(key, rate));
185
    Results r;
186
    size_t channels, step, blocksize;
187
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
188
    float **block = createBlock(channels, blocksize);
189
    int idx = 0;
190
    for (int i = 0; i < 200; ++i) {
191
        for (size_t j = 0; j < blocksize; ++j) {
192
            for (size_t c = 0; c < channels; ++c) {
193
                block[c][j] = 1000.f * sinf(float(idx) / 10.f);
194
            }
195
            ++idx;
196
        }
197
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
198
        Plugin::FeatureSet fs = p->process(block, timestamp);
199
        appendFeatures(f, fs);
200
    }
201
    destroyBlock(block, channels);
202
    Plugin::FeatureSet fs = p->getRemainingFeatures();
203
    appendFeatures(f, fs);
204
    if (allFeaturesValid(f)) {
205
        r.push_back(success());
206
    } else {
207
        r.push_back(warning("plugin returned one or more NaN/inf values"));
208
    }
209
    return r;
210
}
211

    
212
Test::Results
213
TestRandomInput::test(string key)
214
{
215
    Plugin::FeatureSet f;
216
    int rate = 44100;
217
    auto_ptr<Plugin> p(load(key, rate));
218
    Results r;
219
    size_t channels, step, blocksize;
220
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
221
    float **block = createBlock(channels, blocksize);
222
    int idx = 0;
223
    for (int i = 0; i < 100; ++i) {
224
        for (size_t j = 0; j < blocksize; ++j) {
225
            for (size_t c = 0; c < channels; ++c) {
226
                block[c][j] = float(drand48() * 2.0 - 1.0);
227
            }
228
            ++idx;
229
        }
230
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
231
        Plugin::FeatureSet fs = p->process(block, timestamp);
232
        appendFeatures(f, fs);
233
    }
234
    destroyBlock(block, channels);
235
    Plugin::FeatureSet fs = p->getRemainingFeatures();
236
    appendFeatures(f, fs);
237
    if (allFeaturesValid(f)) {
238
        r.push_back(success());
239
    } else {
240
        r.push_back(warning("plugin returned one or more NaN/inf values"));
241
    }
242
    return r;
243
}
244