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 / TestDefaults.cpp @ 7:43eb3a4b95c8

History | View | Annotate | Download (5.61 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 "TestDefaults.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
#include <time.h>
50

    
51
Tester::TestRegistrar<TestDefaultProgram>
52
TestDefaultProgram::m_registrar("E1 Inconsistent default program");
53

    
54
Tester::TestRegistrar<TestDefaultParameters>
55
TestDefaultParameters::m_registrar("E2 Inconsistent default parameters");
56

    
57
Tester::TestRegistrar<TestLengthyConstructor>
58
TestLengthyConstructor::m_registrar("E3 Lengthy constructor");
59

    
60
static const size_t _step = 1000;
61

    
62
Test::Results
63
TestDefaultProgram::test(string key)
64
{
65
    Plugin::FeatureSet f[2];
66
    int rate = 44100;
67
    Results r;
68
    float **data = 0;
69
    size_t channels = 0;
70
    size_t count = 100;
71

    
72
    for (int run = 0; run < 2; ++run) {
73
        auto_ptr<Plugin> p(load(key, rate));
74
        if (p->getPrograms().empty()) return r;
75
        if (run == 1) {
76
            p->selectProgram(p->getCurrentProgram());
77
        }
78
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
79
        if (!data) data = createTestAudio(channels, _step, count);
80
        for (size_t i = 0; i < count; ++i) {
81
            float *ptr[channels];
82
            size_t idx = i * _step;
83
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
84
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
85
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
86
            appendFeatures(f[run], fs);
87
        }
88
        Plugin::FeatureSet fs = p->getRemainingFeatures();
89
        appendFeatures(f[run], fs);
90
    }
91
    if (data) destroyTestAudio(data, channels);
92

    
93
    if (!(f[0] == f[1])) {
94
        Result res = warning("Explicitly setting current program to its supposed current value changes the results");
95
        dump(res, f[0], f[1]);
96
        r.push_back(res);
97
    } else {
98
        r.push_back(success());
99
    }
100

    
101
    return r;
102
}
103

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

    
114
    for (int run = 0; run < 2; ++run) {
115
        auto_ptr<Plugin> p(load(key, rate));
116
        if (p->getParameterDescriptors().empty()) return r;
117
        if (run == 1) {
118
            Plugin::ParameterList pl = p->getParameterDescriptors();
119
            for (int i = 0; i < (int)pl.size(); ++i) {
120
                if (p->getParameter(pl[i].identifier) != pl[i].defaultValue) {
121
                    r.push_back(error("Not all parameters have their default values when queried directly after construction"));
122
                }
123
                p->setParameter(pl[i].identifier, pl[i].defaultValue);
124
            }
125
        }
126
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
127
        if (!data) data = createTestAudio(channels, _step, count);
128
        for (size_t i = 0; i < count; ++i) {
129
            float *ptr[channels];
130
            size_t idx = i * _step;
131
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
132
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
133
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
134
            appendFeatures(f[run], fs);
135
        }
136
        Plugin::FeatureSet fs = p->getRemainingFeatures();
137
        appendFeatures(f[run], fs);
138
    }
139
    if (data) destroyTestAudio(data, channels);
140

    
141
    if (!(f[0] == f[1])) {
142
        Result res = warning("Explicitly setting parameters to their supposed default values changes the results");
143
        dump(res, f[0], f[1]);
144
        r.push_back(res);
145
    } else {
146
        r.push_back(success());
147
    }
148

    
149
    return r;
150
}
151

    
152
Test::Results
153
TestLengthyConstructor::test(string key)
154
{
155
    time_t t0 = time(0);
156
    auto_ptr<Plugin> p(load(key));
157
    time_t t1 = time(0);
158
    Results r;
159
    if (t1 - t0 > 1) r.push_back(warning("Constructor takes some time to run: work should be deferred to initialise?"));
160
    return r;
161
}
162