cannam@150
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@150
|
2 /*
|
cannam@150
|
3 Piper C++
|
cannam@150
|
4
|
cannam@150
|
5 An API for audio analysis and feature extraction plugins.
|
cannam@150
|
6
|
cannam@150
|
7 Centre for Digital Music, Queen Mary, University of London.
|
cannam@150
|
8 Copyright 2006-2016 Chris Cannam and QMUL.
|
cannam@150
|
9
|
cannam@150
|
10 Permission is hereby granted, free of charge, to any person
|
cannam@150
|
11 obtaining a copy of this software and associated documentation
|
cannam@150
|
12 files (the "Software"), to deal in the Software without
|
cannam@150
|
13 restriction, including without limitation the rights to use, copy,
|
cannam@150
|
14 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@150
|
15 of the Software, and to permit persons to whom the Software is
|
cannam@150
|
16 furnished to do so, subject to the following conditions:
|
cannam@150
|
17
|
cannam@150
|
18 The above copyright notice and this permission notice shall be
|
cannam@150
|
19 included in all copies or substantial portions of the Software.
|
cannam@150
|
20
|
cannam@150
|
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@150
|
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@150
|
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@150
|
24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@150
|
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@150
|
26 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@150
|
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@150
|
28
|
cannam@150
|
29 Except as contained in this notice, the names of the Centre for
|
cannam@150
|
30 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@150
|
31 shall not be used in advertising or otherwise to promote the sale,
|
cannam@150
|
32 use or other dealings in this Software without prior written
|
cannam@150
|
33 authorization.
|
cannam@150
|
34 */
|
cannam@150
|
35
|
cannam@150
|
36 #include "ProcessQtTransport.h"
|
cannam@150
|
37 #include "CapnpRRClient.h"
|
cannam@150
|
38 #include "AutoPlugin.h"
|
cannam@150
|
39
|
cannam@150
|
40 #include <stdexcept>
|
cannam@150
|
41
|
cannam@150
|
42 using std::cerr;
|
cannam@150
|
43 using std::endl;
|
cannam@150
|
44 using std::exception;
|
cannam@150
|
45 using std::vector;
|
cannam@150
|
46
|
cannam@150
|
47 int main(int argc, char **argv)
|
cannam@150
|
48 {
|
cannam@150
|
49 if (argc != 2) {
|
cannam@150
|
50 cerr << "Usage: " << argv[0] << " <server-executable-path>" << endl;
|
cannam@150
|
51 return 2;
|
cannam@150
|
52 }
|
cannam@150
|
53
|
cannam@150
|
54 try {
|
cannam@150
|
55 piper_vamp::client::ProcessQtTransport transport(argv[1], "capnp", nullptr);
|
cannam@150
|
56 if (!transport.isOK()) {
|
cannam@150
|
57 cerr << "ERROR: Transport failed to start" << endl;
|
cannam@150
|
58 return 1;
|
cannam@150
|
59 }
|
cannam@150
|
60
|
cannam@150
|
61 piper_vamp::client::CapnpRRClient client(&transport, nullptr);
|
cannam@150
|
62
|
cannam@150
|
63 piper_vamp::ListResponse lr = client.listPluginData({});
|
cannam@150
|
64 cerr << "Plugins available:" << endl;
|
cannam@150
|
65 int i = 1;
|
cannam@150
|
66 for (const auto &p: lr.available) {
|
cannam@150
|
67 cerr << i++ << ". [" << p.pluginKey << "] " << p.basic.name << endl;
|
cannam@150
|
68 }
|
cannam@150
|
69
|
cannam@150
|
70 piper_vamp::LoadRequest req;
|
cannam@150
|
71 req.pluginKey = "vamp-example-plugins:zerocrossing";
|
cannam@150
|
72 req.inputSampleRate = 16;
|
cannam@150
|
73 piper_vamp::LoadResponse resp = client.loadPlugin(req);
|
cannam@150
|
74 Vamp::Plugin *plugin = resp.plugin;
|
cannam@150
|
75
|
cannam@150
|
76 if (!plugin->initialise(1, 4, 4)) {
|
cannam@150
|
77 cerr << "initialisation failed" << endl;
|
cannam@150
|
78 } else {
|
cannam@150
|
79 vector<float> buf = { 1.0, -1.0, 1.0, -1.0 };
|
cannam@150
|
80 float *bd = buf.data();
|
cannam@150
|
81 Vamp::Plugin::FeatureSet features = plugin->process
|
cannam@150
|
82 (&bd, Vamp::RealTime::zeroTime);
|
cannam@150
|
83 cerr << "results for output 0:" << endl;
|
cannam@150
|
84 auto fl(features[0]);
|
cannam@150
|
85 for (const auto &f: fl) {
|
cannam@150
|
86 cerr << f.values[0] << endl;
|
cannam@150
|
87 }
|
cannam@150
|
88 }
|
cannam@150
|
89
|
cannam@150
|
90 (void)plugin->getRemainingFeatures();
|
cannam@150
|
91
|
cannam@150
|
92 cerr << "calling reset..." << endl;
|
cannam@150
|
93 plugin->reset();
|
cannam@150
|
94 cerr << "...round 2!" << endl;
|
cannam@150
|
95
|
cannam@150
|
96 vector<float> buf = { 1.0, -1.0, 1.0, -1.0 };
|
cannam@150
|
97 float *bd = buf.data();
|
cannam@150
|
98 Vamp::Plugin::FeatureSet features = plugin->process
|
cannam@150
|
99 (&bd, Vamp::RealTime::zeroTime);
|
cannam@150
|
100 cerr << "results for output 0:" << endl;
|
cannam@150
|
101 auto fl(features[0]);
|
cannam@150
|
102 for (const auto &f: fl) {
|
cannam@150
|
103 cerr << f.values[0] << endl;
|
cannam@150
|
104 }
|
cannam@150
|
105
|
cannam@150
|
106 (void)plugin->getRemainingFeatures();
|
cannam@150
|
107
|
cannam@150
|
108 delete plugin;
|
cannam@150
|
109
|
cannam@150
|
110 // Let's try a crazy AutoPlugin
|
cannam@150
|
111
|
cannam@150
|
112 piper_vamp::client::AutoPlugin ap
|
cannam@150
|
113 (argv[1], "vamp-example-plugins:zerocrossing", 16, 0, nullptr);
|
cannam@150
|
114
|
cannam@150
|
115 if (!ap.isOK()) {
|
cannam@150
|
116 cerr << "AutoPlugin creation failed" << endl;
|
cannam@150
|
117 } else {
|
cannam@150
|
118 if (!ap.initialise(1, 4, 4)) {
|
cannam@150
|
119 cerr << "initialisation failed" << endl;
|
cannam@150
|
120 } else {
|
cannam@150
|
121 vector<float> buf = { 1.0, -1.0, 1.0, -1.0 };
|
cannam@150
|
122 float *bd = buf.data();
|
cannam@150
|
123 Vamp::Plugin::FeatureSet features = ap.process
|
cannam@150
|
124 (&bd, Vamp::RealTime::zeroTime);
|
cannam@150
|
125 cerr << "results for output 0:" << endl;
|
cannam@150
|
126 auto fl(features[0]);
|
cannam@150
|
127 for (const auto &f: fl) {
|
cannam@150
|
128 cerr << f.values[0] << endl;
|
cannam@150
|
129 }
|
cannam@150
|
130 }
|
cannam@150
|
131 }
|
cannam@150
|
132 } catch (const exception &e) {
|
cannam@150
|
133 cerr << "ERROR: Exception caught: " << e.what() << endl;
|
cannam@150
|
134 return 1;
|
cannam@150
|
135 }
|
cannam@150
|
136
|
cannam@150
|
137 return 0;
|
cannam@150
|
138 }
|
cannam@150
|
139
|