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 / TestOutputs.cpp @ 60:9f2a6d843639

History | View | Annotate | Download (6.63 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-2014 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 "TestOutputs.h"
41

    
42
#include <vamp-hostsdk/Plugin.h>
43
#include <vamp-hostsdk/PluginLoader.h>
44
using namespace Vamp;
45
using namespace Vamp::HostExt;
46

    
47
#include <set>
48
#include <memory>
49
using namespace std;
50

    
51
#include <cmath>
52

    
53
#ifndef __GNUC__
54
#include <alloca.h>
55
#endif
56

    
57
Tester::TestRegistrar<TestOutputNumbers>
58
TestOutputNumbers::m_registrar("B1", "Output number mismatching");
59

    
60
Tester::TestRegistrar<TestTimestamps>
61
TestTimestamps::m_registrar("B2", "Invalid or dubious timestamp usage");
62

    
63
static const size_t _step = 1000;
64

    
65
Test::Results
66
TestOutputNumbers::test(string key, Options options)
67
{
68
    int rate = 44100;
69
    auto_ptr<Plugin> p(load(key, rate));
70
    Plugin::FeatureSet f;
71
    Results r;
72
    float **data = 0;
73
    size_t channels = 0;
74
    size_t count = 100;
75

    
76
    if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
77
    if (!data) data = createTestAudio(channels, _step, count);
78
    for (size_t i = 0; i < count; ++i) {
79
#ifdef __GNUC__
80
        float *ptr[channels];
81
#else
82
        float **ptr = (float **)alloca(channels * sizeof(float));
83
#endif
84
        size_t idx = i * _step;
85
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
86
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
87
        Plugin::FeatureSet fs = p->process(ptr, timestamp);
88
        appendFeatures(f, fs);
89
    }
90
    Plugin::FeatureSet fs = p->getRemainingFeatures();
91
    appendFeatures(f, fs);
92
    if (data) destroyTestAudio(data, channels);
93

    
94
    std::set<int> used;
95
    Plugin::OutputList outputs = p->getOutputDescriptors();
96
    for (Plugin::FeatureSet::const_iterator i = f.begin();
97
         i != f.end(); ++i) {
98
        int o = i->first;
99
        used.insert(o);
100
        if (o < 0 || o >= (int)outputs.size()) {
101
            r.push_back(error("Data returned on nonexistent output"));
102
        }
103
    }
104
    for (int o = 0; o < (int)outputs.size(); ++o) {
105
        if (used.find(o) == used.end()) {
106
            r.push_back(note("No results returned for output \"" + outputs[o].identifier + "\"")); 
107
        }
108
    }
109
                
110
    if (!r.empty() && (options & Verbose)) dump(f);
111
    return r;
112
}
113

    
114
Test::Results
115
TestTimestamps::test(string key, Options options)
116
{
117
    int rate = 44100;
118

    
119
    // we want to be sure that a buffer size adapter is not used:
120
    auto_ptr<Plugin> p(PluginLoader::getInstance()->loadPlugin
121
                       (key, rate, PluginLoader::ADAPT_ALL_SAFE));
122

    
123
    Results r;
124
    Plugin::FeatureSet f;
125
    float **data = 0;
126
    size_t channels = 0;
127
    size_t step = 0, block = 0;
128
    size_t count = 100;
129

    
130
    if (!initDefaults(p.get(), channels, step, block, r)) return r;
131

    
132
    Plugin::OutputList outputs = p->getOutputDescriptors();
133
    for (int i = 0; i < (int)outputs.size(); ++i) {
134
        if (outputs[i].sampleType == Plugin::OutputDescriptor::FixedSampleRate &&
135
            outputs[i].sampleRate == 0.f) {
136
            r.push_back(error("Plugin output \"" + outputs[i].identifier +
137
                              "\" has FixedSampleRate but gives sample rate as 0"));
138
        }
139
    }
140

    
141
    if (!data) data = createTestAudio(channels, block, count);
142
    for (size_t i = 0; i < count; ++i) {
143
#ifdef __GNUC__
144
        float *ptr[channels];
145
#else
146
        float **ptr = (float **)alloca(channels * sizeof(float));
147
#endif
148
        size_t idx = i * step;
149
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
150
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
151
        Plugin::FeatureSet fs = p->process(ptr, timestamp);
152
        appendFeatures(f, fs);
153
    }
154
    Plugin::FeatureSet fs = p->getRemainingFeatures();
155
    appendFeatures(f, fs);
156
    if (data) destroyTestAudio(data, channels);
157

    
158
    for (Plugin::FeatureSet::const_iterator i = f.begin();
159
         i != f.end(); ++i) {
160
        const Plugin::OutputDescriptor &o = outputs[i->first];
161
        const Plugin::FeatureList &fl = i->second;
162
        for (int j = 0; j < (int)fl.size(); ++j) {
163
            const Plugin::Feature &fe = fl[j];
164
            switch (o.sampleType) {
165
            case Plugin::OutputDescriptor::OneSamplePerStep:
166
                if (fe.hasTimestamp) {
167
                    r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output \"" + o.identifier + "\""));
168
                }
169
                if (fe.hasDuration) {
170
                    r.push_back(note("Plugin returns features with durations on OneSamplePerStep output \"" + o.identifier + "\""));
171
                }
172
                break;
173
            case Plugin::OutputDescriptor::FixedSampleRate:
174
                break;
175
            case Plugin::OutputDescriptor::VariableSampleRate:
176
                if (!fe.hasTimestamp) {
177
                    r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output \"" + o.identifier + "\""));
178
                }
179
                break;
180
            }
181
        }
182
    }
183

    
184
    if (!r.empty() && (options & Verbose)) dump(f);
185
    return r;
186
}