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 @ 3:0f65bb22172b

History | View | Annotate | Download (5.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 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
using namespace Vamp;
44

    
45
#include <set>
46
#include <memory>
47
using namespace std;
48

    
49
#include <cmath>
50

    
51
Tester::TestRegistrar<TestOutputNumbers>
52
TestOutputNumbers::m_registrar("Output number mismatching");
53

    
54
Tester::TestRegistrar<TestTimestamps>
55
TestTimestamps::m_registrar("Invalid or dubious timestamp usage");
56

    
57
static const size_t _step = 1000;
58

    
59
Test::Results
60
TestOutputNumbers::test(string key)
61
{
62
    int rate = 44100;
63
    auto_ptr<Plugin> p(load(key, rate));
64
    Plugin::FeatureSet f;
65
    Results r;
66
    float **data = 0;
67
    size_t channels = 0;
68
    size_t count = 100;
69

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

    
84
    std::set<int> used;
85
    Plugin::OutputList outputs = p->getOutputDescriptors();
86
    for (Plugin::FeatureSet::const_iterator i = fs.begin();
87
         i != fs.end(); ++i) {
88
        int o = i->first;
89
        used.insert(o);
90
        if (o < 0 || o >= outputs.size()) {
91
            r.push_back(error("Data returned on nonexistent output"));
92
        }
93
    }
94
    for (int o = 0; o < outputs.size(); ++o) {
95
        if (used.find(o) == used.end()) {
96
            r.push_back(note("No results returned for one or more outputs"));       }
97
    }
98
                
99
    return r;
100
}
101

    
102
Test::Results
103
TestTimestamps::test(string key)
104
{
105
    int rate = 44100;
106
    auto_ptr<Plugin> p(load(key, rate));
107
    Plugin::FeatureSet f;
108
    Results r;
109
    float **data = 0;
110
    size_t channels = 0;
111
    size_t step = 0, block = 0;
112
    size_t count = 100;
113

    
114
    //!!! want to ensure buffer size adapter is not used:
115
    if (!initDefaults(p.get(), channels, step, block, r)) return r;
116
    if (!data) data = createTestAudio(channels, block, count);
117
    for (size_t i = 0; i < count; ++i) {
118
        float *ptr[channels];
119
        size_t idx = i * step;
120
        for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
121
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
122
        Plugin::FeatureSet fs = p->process(ptr, timestamp);
123
        appendFeatures(f, fs);
124
    }
125
    Plugin::FeatureSet fs = p->getRemainingFeatures();
126
    appendFeatures(f, fs);
127
    if (data) destroyTestAudio(data, channels);
128

    
129
    Plugin::OutputList outputs = p->getOutputDescriptors();
130
    for (Plugin::FeatureSet::const_iterator i = fs.begin();
131
         i != fs.end(); ++i) {
132
        const Plugin::OutputDescriptor &o = outputs[i->first];
133
        const Plugin::FeatureList &fl = i->second;
134
        for (int j = 0; j < (int)fl.size(); ++j) {
135
            const Plugin::Feature &f = fl[j];
136
            switch (o.sampleType) {
137
            case Plugin::OutputDescriptor::OneSamplePerStep:
138
                if (f.hasTimestamp) {
139
                    r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output"));
140
                }
141
                if (f.hasDuration) {
142
                    r.push_back(note("Plugin returns features with durations on OneSamplePerStep output"));
143
                }
144
                break;
145
            case Plugin::OutputDescriptor::FixedSampleRate:
146
                break;
147
            case Plugin::OutputDescriptor::VariableSampleRate:
148
                if (!f.hasTimestamp) {
149
                    r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output"));
150
                }
151
                break;
152
            }
153
        }
154
    }
155

    
156
    return r;
157
}