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 @ 2:c9a4bd247497

History | View | Annotate | Download (6.53 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
Test::Results
60
TestDistinctRuns::test(string key)
61
{
62
    Plugin::FeatureSet f[2];
63
    int rate = 44100;
64
    Results r;
65
    float **block = 0;
66
    size_t channels = 0, step = 0, blocksize = 0;
67

    
68
    for (int run = 0; run < 2; ++run) {
69
        auto_ptr<Plugin> p(load(key, rate));
70
        if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
71
        if (!block) block = createBlock(channels, blocksize);
72
        int idx = 0;
73
        for (int i = 0; i < 100; ++i) {
74
            for (size_t j = 0; j < blocksize; ++j) {
75
                for (size_t c = 0; c < channels; ++c) {
76
                    block[c][j] = sinf(float(idx) / 10.f);
77
                    if ((i == 20 || i == 80) && (j < 2)) {
78
                        block[c][j] = float(j) - 1.f;
79
                    }
80
                }
81
                ++idx;
82
            }
83
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
84
            Plugin::FeatureSet fs = p->process(block, timestamp);
85
            appendFeatures(f[run], fs);
86
        }
87
        Plugin::FeatureSet fs = p->getRemainingFeatures();
88
        appendFeatures(f[run], fs);
89
    }
90
    if (block) destroyBlock(block, channels);
91

    
92
    if (!(f[0] == f[1])) {
93
        r.push_back(warning("Consecutive runs with separate instances produce different results"));
94
    } else {
95
        r.push_back(success());
96
    }
97

    
98
    return r;
99
}
100

    
101
Test::Results
102
TestReset::test(string key)
103
{
104
    Plugin::FeatureSet f[2];
105
    int rate = 44100;
106
    Results r;
107
    float **block = 0;
108
    size_t channels = 0, step = 0, blocksize = 0;
109

    
110
    auto_ptr<Plugin> p(load(key, rate));
111
    for (int run = 0; run < 2; ++run) {
112
        if (run == 1) p->reset();
113
        if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
114
        if (!block) block = createBlock(channels, blocksize);
115
        int idx = 0;
116
        for (int i = 0; i < 100; ++i) {
117
            for (size_t j = 0; j < blocksize; ++j) {
118
                for (size_t c = 0; c < channels; ++c) {
119
                    block[c][j] = sinf(float(idx) / 10.f);
120
                    if ((i == 20 || i == 80) && (j < 2)) {
121
                        block[c][j] = float(j) - 1.f;
122
                    }
123
                }
124
                ++idx;
125
            }
126
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
127
            Plugin::FeatureSet fs = p->process(block, timestamp);
128
            appendFeatures(f[run], fs);
129
        }
130
        Plugin::FeatureSet fs = p->getRemainingFeatures();
131
        appendFeatures(f[run], fs);
132
    }
133
    if (block) destroyBlock(block, channels);
134

    
135
    if (!(f[0] == f[1])) {
136
        r.push_back(warning("Consecutive runs with the same instance (using reset) produce different results"));
137
    } else {
138
        r.push_back(success());
139
    }
140

    
141
    return r;
142
}
143

    
144
Test::Results
145
TestInterleavedRuns::test(string key)
146
{
147
    Plugin::FeatureSet f[2];
148
    int rate = 44100;
149
    Results r;
150
    float **block = 0;
151
    size_t channels = 0, step = 0, blocksize = 0;
152
    Plugin *p[2];
153
    for (int run = 0; run < 2; ++run) {
154
        p[run] = load(key, rate);
155
        if (!initDefaults(p[run], channels, step, blocksize, r)) {
156
            delete p[run];
157
            if (run > 0) delete p[0];
158
            return r;
159
        }
160
        if (!block) block = createBlock(channels, blocksize);
161
    }
162
    int idx = 0;
163
    for (int i = 0; i < 100; ++i) {
164
        for (size_t j = 0; j < blocksize; ++j) {
165
            for (size_t c = 0; c < channels; ++c) {
166
                block[c][j] = sinf(float(idx) / 10.f);
167
                if ((i == 20 || i == 80) && (j < 2)) {
168
                    block[c][j] = float(j) - 1.f;
169
                }
170
            }
171
            ++idx;
172
        }
173
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
174
        for (int run = 0; run < 2; ++run) {
175
            Plugin::FeatureSet fs = p[run]->process(block, timestamp);
176
            appendFeatures(f[run], fs);
177
        }
178
    }
179
    for (int run = 0; run < 2; ++run) {
180
        Plugin::FeatureSet fs = p[run]->getRemainingFeatures();
181
        appendFeatures(f[run], fs);
182
        delete p[run];
183
    }
184

    
185
    if (block) destroyBlock(block, channels);
186

    
187
    if (!(f[0] == f[1])) {
188
        r.push_back(warning("Consecutive runs with the same instance (using reset) produce different results"));
189
    } else {
190
        r.push_back(success());
191
    }
192

    
193
    return r;
194
}