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 @ 1:d7ef749300ed

History | View | Annotate | Download (7.22 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 <cmath>
49

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

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

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

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

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

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

    
68
Test::Results
69
TestNormalInput::test(string key)
70
{
71
    int rate = 44100;
72
    auto_ptr<Plugin> p(load(key, rate));
73
    Results r;
74
    size_t channels, step, blocksize;
75
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
76
    float **block = createBlock(channels, blocksize);
77
    int idx = 0;
78
    for (int i = 0; i < 200; ++i) {
79
        for (size_t j = 0; j < blocksize; ++j) {
80
            for (size_t c = 0; c < channels; ++c) {
81
                block[c][j] = sinf(float(idx) / 10.f);
82
            }
83
            ++idx;
84
        }
85
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
86
        p->process(block, timestamp);
87
    }
88
    destroyBlock(block, channels);
89
    Plugin::FeatureSet fs = p->getRemainingFeatures();
90
    if (allFeaturesValid(fs)) {
91
        r.push_back(success());
92
    } else {
93
        r.push_back(warning("plugin returned one or more NaN/inf values"));
94
    }
95
    return r;
96
}
97

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

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

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

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

    
199
Test::Results
200
TestRandomInput::test(string key)
201
{
202
    int rate = 44100;
203
    auto_ptr<Plugin> p(load(key, rate));
204
    Results r;
205
    size_t channels, step, blocksize;
206
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
207
    float **block = createBlock(channels, blocksize);
208
    int idx = 0;
209
    for (int i = 0; i < 100; ++i) {
210
        for (size_t j = 0; j < blocksize; ++j) {
211
            for (size_t c = 0; c < channels; ++c) {
212
                block[c][j] = float(drand48() * 2.0 - 1.0);
213
            }
214
            ++idx;
215
        }
216
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
217
        p->process(block, timestamp);
218
    }
219
    destroyBlock(block, channels);
220
    Plugin::FeatureSet fs = p->getRemainingFeatures();
221
    if (allFeaturesValid(fs)) {
222
        r.push_back(success());
223
    } else {
224
        r.push_back(warning("plugin returned one or more NaN/inf values"));
225
    }
226
    return r;
227
}
228