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 / Test.cpp @ 28:b1bc4d045a4b

History | View | Annotate | Download (7.43 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

    
3
/*
4
    Vamp Plugin Fuzz 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 "Test.h"
41

    
42
#include <vamp-hostsdk/PluginLoader.h>
43

    
44
using namespace Vamp;
45
using namespace Vamp::HostExt;
46

    
47
#include <math.h>
48

    
49
#ifdef __SUNPRO_CC
50
#include <ieeefp.h>
51
#define isinf(x) (!finite(x))
52
#endif
53

    
54
Test::Test() { }
55
Test::~Test() { }
56

    
57
Plugin *
58
Test::load(std::string key, float rate)
59
{
60
    Plugin *p = PluginLoader::getInstance()->loadPlugin
61
        (key, rate, PluginLoader::ADAPT_ALL);
62
    if (!p) throw FailedToLoadPlugin();
63
    return p;
64
}
65

    
66
float **
67
Test::createBlock(size_t channels, size_t blocksize)
68
{
69
    float **b = new float *[channels];
70
    for (size_t c = 0; c < channels; ++c) {
71
        b[c] = new float[blocksize];
72
    }
73
    return b;
74
}
75

    
76
void
77
Test::destroyBlock(float **blocks, size_t channels)
78
{
79
    for (size_t c = 0; c < channels; ++c) {
80
        delete[] blocks[c];
81
    }
82
    delete[] blocks;
83
}
84

    
85
float **
86
Test::createTestAudio(size_t channels, size_t blocksize, size_t blocks)
87
{
88
    float **b = new float *[channels];
89
    for (size_t c = 0; c < channels; ++c) {
90
        b[c] = new float[blocksize * blocks];
91
        for (int i = 0; i < int(blocksize * blocks); ++i) {
92
            b[c][i] = sinf(float(i) / 10.f);
93
            if (i == 5005 || i == 20002) {
94
                b[c][i-2] = 0;
95
                b[c][i-1] = -1;
96
                b[c][i] = 1;
97
            }
98
        }
99
    }
100
    return b;
101
}
102

    
103
void
104
Test::destroyTestAudio(float **b, size_t channels)
105
{
106
    for (size_t c = 0; c < channels; ++c) {
107
        delete[] b[c];
108
    }
109
    delete[] b;
110
}
111

    
112
bool
113
Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block,
114
                   Results &r)
115
{
116
    channels = p->getMinChannelCount();
117
    block = p->getPreferredBlockSize();
118
    step = p->getPreferredStepSize();
119
    if (block == 0) block = 1024;
120
    if (step == 0) {
121
        if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2;
122
        else step = block;
123
    }
124
    if (!p->initialise(channels, step, block)) {
125
        r.push_back(error("initialisation with default values failed"));
126
        return false;
127
    }
128
    return true;
129
}
130

    
131
bool
132
Test::initAdapted(Plugin *p, size_t &channels, size_t step, size_t block,
133
                  Results &r)
134
{
135
    channels = p->getMinChannelCount();
136
    if (!p->initialise(channels, step, block)) {
137
        r.push_back(error("initialisation failed"));
138
        return false;
139
    }
140
    return true;
141
}
142

    
143
void
144
Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
145
{
146
    for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
147
        int output = i->first;
148
        const Plugin::FeatureList &fl = i->second;
149
        Plugin::FeatureList &target = a[output];
150
        for (Plugin::FeatureList::const_iterator j = fl.begin(); j != fl.end(); ++j) {
151
            target.push_back(*j);
152
        }
153
    }
154
}
155

    
156
bool
157
Test::allFeaturesValid(const Plugin::FeatureSet &b)
158
{
159
    for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
160
        for (int j = 0; j < (int)i->second.size(); ++j) {
161
            if (i->second[j].values.empty()) continue;
162
            for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
163
                if (isnan(i->second[j].values[k]) ||
164
                    isinf(i->second[j].values[k])) {
165
                    return false;
166
                }
167
            }
168
        }
169
    }
170
    return true;
171
}
172

    
173
void
174
Test::dump(const Plugin::FeatureSet &fs)
175
{
176
    for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
177
         fsi != fs.end(); ++fsi) {
178
        int output = fsi->first;
179
        std::cout << "Output " << output << ":" << std::endl;
180
        const Plugin::FeatureList &fl = fsi->second;
181
        for (int i = 0; i < (int)fl.size(); ++i) {
182
            std::cout << "  Feature " << i << ":" << std::endl;
183
            const Plugin::Feature &f = fl[i];
184
            std::cout << "    Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl;
185
            std::cout << "    Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl;
186
            std::cout << "    Label: " << (f.label == "" ? "(none)" : f.label) << std::endl;
187
            std::cout << "    Value: " << (f.values.empty() ? "(none)" : "");
188
            for (int j = 0; j < (int)f.values.size(); ++j) {
189
                std::cout << f.values[j] << " ";
190
            }
191
            std::cout << std::endl;
192
        }
193
    }
194
}
195

    
196
void
197
Test::dump(const Result &r,
198
           const Plugin::FeatureSet &a,
199
           const Plugin::FeatureSet &b)
200
{
201
    std::cout << r.message() << std::endl;
202
    std::cout << "\nFirst result set:" << std::endl;
203
    dump(a);
204
    std::cout << "\nSecond result set:" << std::endl;
205
    dump(b);
206
    std::cout << std::endl;
207
}
208

    
209
bool
210
operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
211
{
212
    if (a.size() != b.size()) return false;
213
    for (Plugin::FeatureSet::const_iterator ai = a.begin();
214
         ai != a.end(); ++ai) {
215
        int output = ai->first;
216
        Plugin::FeatureSet::const_iterator bi = b.find(output);
217
        if (bi == b.end()) return false;
218
        if (!(ai->second == bi->second)) return false;
219
    }
220
    return true;
221
}
222

    
223
bool
224
operator==(const Plugin::FeatureList &a, const Plugin::FeatureList &b)
225
{
226
    if (a.size() != b.size()) return false;
227
    for (int i = 0; i < (int)a.size(); ++i) {
228
        if (!(a[i] == b[i])) return false;
229
    }
230
    return true;
231
}
232

    
233
bool
234
operator==(const Plugin::Feature &a, const Plugin::Feature &b)
235
{
236
    if (a.hasTimestamp != b.hasTimestamp) return false;
237
    if (a.hasTimestamp && (a.timestamp != b.timestamp)) return false;
238
    if (a.hasDuration != b.hasDuration) return false;
239
    if (a.hasDuration && (a.duration != b.duration)) return false;
240
    if (a.values != b.values) return false;
241
    if (a.label != b.label) return false;
242
    return true;
243
}
244