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 / TestMultipleRuns.cpp @ 3:0f65bb22172b

History | View | Annotate | Download (5.96 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 "TestMultipleRuns.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<TestDistinctRuns>
51
TestDistinctRuns::m_registrar("Consecutive runs with separate instances");
52

    
53
Tester::TestRegistrar<TestReset>
54
TestReset::m_registrar("Consecutive runs with a single instance using reset");
55

    
56
Tester::TestRegistrar<TestInterleavedRuns>
57
TestInterleavedRuns::m_registrar("Simultaneous interleaved runs in a single thread");
58

    
59
static const size_t _step = 1000;
60

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

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

    
88
    if (!(f[0] == f[1])) {
89
        r.push_back(warning("Consecutive runs with separate instances produce different results"));
90
    } else {
91
        r.push_back(success());
92
    }
93

    
94
    return r;
95
}
96

    
97
Test::Results
98
TestReset::test(string key)
99
{
100
    Plugin::FeatureSet f[2];
101
    int rate = 44100;
102
    Results r;
103
    float **data = 0;
104
    size_t channels = 0;
105
    size_t count = 100;
106

    
107
    auto_ptr<Plugin> p(load(key, rate));
108

    
109
    for (int run = 0; run < 2; ++run) {
110
        if (run == 1) p->reset();
111
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
112
        if (!data) data = createTestAudio(channels, _step, count);
113
        for (size_t i = 0; i < count; ++i) {
114
            float *ptr[channels];
115
            size_t idx = i * _step;
116
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
117
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
118
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
119
            appendFeatures(f[run], fs);
120
        }
121
        Plugin::FeatureSet fs = p->getRemainingFeatures();
122
        appendFeatures(f[run], fs);
123
    }
124
    if (data) destroyTestAudio(data, channels);
125

    
126
    if (!(f[0] == f[1])) {
127
        Result res = warning("Consecutive runs with the same instance (using reset) produce different results");
128
        dump(res, f[0], f[1]);
129
        r.push_back(res);
130
    } else {
131
        r.push_back(success());
132
    }
133

    
134
    return r;
135
}
136

    
137
Test::Results
138
TestInterleavedRuns::test(string key)
139
{
140
    Plugin::FeatureSet f[2];
141
    int rate = 44100;
142
    Results r;
143
    float **data = 0;
144
    size_t channels = 0;
145
    size_t count = 100;
146

    
147
    Plugin *p[2];
148
    for (int run = 0; run < 2; ++run) {
149
        p[run] = load(key, rate);
150
        if (!initAdapted(p[run], channels, _step, _step, r)) {
151
            delete p[run];
152
            if (run > 0) delete p[0];
153
            return r;
154
        }
155
        if (!data) data = createTestAudio(channels, _step, count);
156
    }
157
    for (size_t i = 0; i < count; ++i) {
158
        float *ptr[channels];
159
        size_t idx = i * _step;
160
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
161
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
162
        for (int run = 0; run < 2; ++run) {
163
            Plugin::FeatureSet fs = p[run]->process(ptr, timestamp);
164
            appendFeatures(f[run], fs);
165
        }
166
    }
167
    for (int run = 0; run < 2; ++run) {
168
        Plugin::FeatureSet fs = p[run]->getRemainingFeatures();
169
        appendFeatures(f[run], fs);
170
        delete p[run];
171
    }
172

    
173
    if (data) destroyTestAudio(data, channels);
174

    
175
    if (!(f[0] == f[1])) {
176
        r.push_back(warning("Simultaneous runs with separate instances produce different results"));
177
    } else {
178
        r.push_back(success());
179
    }
180

    
181
    return r;
182
}