annotate vamp-client/client.cpp @ 98:f55631599988

Plugin that creates its own server
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 13 Oct 2016 19:11:24 +0100
parents 427c4c725085
children 8c449824e08d
rev   line source
c@78 1
c@94 2 #include "ProcessQtTransport.h"
c@96 3 #include "CapnpRRClient.h"
c@98 4 #include "AutoPlugin.h"
c@83 5
c@83 6 #include <stdexcept>
c@83 7
c@83 8 using std::cerr;
c@83 9 using std::endl;
c@83 10
c@84 11 int main(int, char **)
c@84 12 {
c@97 13 piper_vamp::client::ProcessQtTransport transport("../bin/piper-vamp-server");
c@97 14 piper_vamp::client::CapnpRRClient client(&transport);
c@94 15
c@97 16 piper_vamp::ListResponse lr = client.listPluginData();
c@95 17 cerr << "Plugins available:" << endl;
c@95 18 int i = 1;
c@95 19 for (const auto &p: lr.available) {
c@95 20 cerr << i++ << ". [" << p.pluginKey << "] " << p.basic.name << endl;
c@95 21 }
c@95 22
c@97 23 piper_vamp::LoadRequest req;
c@95 24 req.pluginKey = "vamp-example-plugins:zerocrossing";
c@95 25 req.inputSampleRate = 16;
c@97 26 piper_vamp::LoadResponse resp = client.loadPlugin(req);
c@95 27 Vamp::Plugin *plugin = resp.plugin;
c@95 28
c@84 29 if (!plugin->initialise(1, 4, 4)) {
c@84 30 cerr << "initialisation failed" << endl;
c@84 31 } else {
c@84 32 std::vector<float> buf = { 1.0, -1.0, 1.0, -1.0 };
c@84 33 float *bd = buf.data();
c@84 34 Vamp::Plugin::FeatureSet features = plugin->process
c@84 35 (&bd, Vamp::RealTime::zeroTime);
c@84 36 cerr << "results for output 0:" << endl;
c@84 37 auto fl(features[0]);
c@84 38 for (const auto &f: fl) {
c@84 39 cerr << f.values[0] << endl;
c@84 40 }
c@84 41 }
c@88 42
c@87 43 (void)plugin->getRemainingFeatures();
c@89 44
c@89 45 cerr << "calling reset..." << endl;
c@89 46 plugin->reset();
c@89 47 cerr << "...round 2!" << endl;
c@89 48
c@89 49 std::vector<float> buf = { 1.0, -1.0, 1.0, -1.0 };
c@89 50 float *bd = buf.data();
c@89 51 Vamp::Plugin::FeatureSet features = plugin->process
c@89 52 (&bd, Vamp::RealTime::zeroTime);
c@89 53 cerr << "results for output 0:" << endl;
c@89 54 auto fl(features[0]);
c@89 55 for (const auto &f: fl) {
c@89 56 cerr << f.values[0] << endl;
c@89 57 }
c@89 58
c@89 59 (void)plugin->getRemainingFeatures();
c@89 60
c@88 61 delete plugin;
c@98 62
c@98 63 // Let's try a crazy AutoPlugin
c@98 64
c@98 65 piper_vamp::client::AutoPlugin ap("vamp-example-plugins:zerocrossing", 16, 0);
c@98 66 if (!ap.isOK()) {
c@98 67 cerr << "AutoPlugin creation failed" << endl;
c@98 68 } else {
c@98 69 if (!ap.initialise(1, 4, 4)) {
c@98 70 cerr << "initialisation failed" << endl;
c@98 71 } else {
c@98 72 std::vector<float> buf = { 1.0, -1.0, 1.0, -1.0 };
c@98 73 float *bd = buf.data();
c@98 74 Vamp::Plugin::FeatureSet features = ap.process
c@98 75 (&bd, Vamp::RealTime::zeroTime);
c@98 76 cerr << "results for output 0:" << endl;
c@98 77 auto fl(features[0]);
c@98 78 for (const auto &f: fl) {
c@98 79 cerr << f.values[0] << endl;
c@98 80 }
c@98 81 }
c@98 82 }
c@84 83 }
c@84 84