Mercurial > hg > piper-cpp
comparison test/vamp-client/tst_PluginStub.cpp @ 191:79c64ff2610b
Test setup for testing PluginCache caches framing sizes across init calls.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 07 Feb 2017 16:35:16 +0000 |
parents | 70b0f1f9e039 |
children | 4848852c4fbd |
comparison
equal
deleted
inserted
replaced
190:70b0f1f9e039 | 191:79c64ff2610b |
---|---|
1 #include "catch/catch.hpp" | 1 #include "catch/catch.hpp" |
2 #include "vamp-client/Loader.h" | |
3 #include "vamp-client/PluginClient.h" | |
4 #include "vamp-client/PluginStub.h" | |
5 #include "vamp-support/RequestResponse.h" | |
6 #include <vector> | |
2 | 7 |
3 TEST_CASE("Configure plugin with parameter dependent preferred framing sizes") { | 8 using namespace piper_vamp; |
9 using namespace piper_vamp::client; | |
10 using AudioBuffer = std::vector<std::vector<float>>; | |
4 | 11 |
12 // This stub mimicks the interaction with a Piper server | |
13 // Here we only need to implement the configure method | |
14 // due to testing only the initialise implemention of PluginStub | |
15 class StubClient : public PluginClient | |
16 { | |
17 public: | |
18 StubClient(PluginStaticData staticData) : m_staticData(staticData) {} | |
19 | |
20 ConfigurationResponse | |
21 configure(PluginStub* plugin, | |
22 PluginConfiguration config) override | |
23 { | |
24 const float scale = plugin->getParameter("framing-scale"); | |
25 ConfigurationResponse cr; | |
26 cr.plugin = plugin; | |
27 | |
28 // we want to return different framing sizes | |
29 // than config provides | |
30 // there isn't really any need to be doing this with a plugin param | |
31 cr.framing.blockSize = config.framing.stepSize * scale; | |
32 cr.framing.stepSize = config.framing.blockSize * scale; | |
33 | |
34 | |
35 // just return some outputs anyway | |
36 // to avoid a failure case we are not testing here. | |
37 Vamp::Plugin::OutputDescriptor output; | |
38 const auto basic = m_staticData.basicOutputInfo[0]; | |
39 output.identifier = basic.identifier; | |
40 output.name = basic.name; | |
41 output.description = basic.description; | |
42 cr.outputs = {output}; | |
43 return cr; | |
44 } | |
45 | |
46 Vamp::Plugin::FeatureSet | |
47 process(PluginStub* /*plugin*/, | |
48 AudioBuffer /*channels*/, | |
49 Vamp::RealTime /*timestamp*/) override | |
50 { | |
51 return {}; | |
52 } | |
53 | |
54 Vamp::Plugin::FeatureSet | |
55 finish(PluginStub* /*plugin*/) override | |
56 { | |
57 return {}; | |
58 } | |
59 | |
60 void | |
61 reset(PluginStub* /*plugin*/, PluginConfiguration /*config*/) override | |
62 {} | |
63 private: | |
64 PluginStaticData m_staticData; | |
65 }; | |
66 | |
67 | |
68 TEST_CASE("Init plugin with parameter dependent preferred framing sizes") { | |
69 | |
70 PluginConfiguration defaultConfig; | |
71 defaultConfig.channelCount = 1; | |
72 defaultConfig.parameterValues = {}; | |
73 defaultConfig.framing.blockSize = 1024; | |
74 defaultConfig.framing.stepSize = 512; | |
75 defaultConfig.parameterValues = {{"framing-scale", 1.0}}; | |
76 | |
77 Vamp::PluginBase::ParameterDescriptor stubParam; | |
78 stubParam.identifier = "framing-scale"; | |
79 stubParam.name = "Framing Scale Factor"; | |
80 stubParam.description = "Scales the preferred framing sizes"; | |
81 stubParam.maxValue = 2.0; | |
82 | |
83 PluginStaticData staticData; | |
84 staticData.pluginKey = "stub"; | |
85 staticData.basic = {"stub:param-init", "Stub", "Testing init"}; | |
86 staticData.maker = "Lucas Thompson"; | |
87 staticData.copyright = "GPL"; | |
88 staticData.pluginVersion = 1; | |
89 staticData.category = {"Test"}; | |
90 staticData.minChannelCount = 1; | |
91 staticData.maxChannelCount = 1; | |
92 staticData.parameters = {stubParam}; | |
93 staticData.inputDomain = Vamp::Plugin::InputDomain::TimeDomain; | |
94 staticData.basicOutputInfo = {{"output", "NA", "Not real"}}; | |
95 | |
96 StubClient stub {staticData}; | |
97 | |
98 PluginStub vampPiperAdapter { | |
99 &stub, | |
100 "stub", // plugin key | |
101 44100.0, // sample rate | |
102 0, // adapter flags, don't care here | |
103 staticData, | |
104 defaultConfig | |
105 }; | |
106 | |
107 vampPiperAdapter.setParameter("framing-scale", 2.0); | |
108 // setup | |
109 REQUIRE( | |
110 vampPiperAdapter.initialise( | |
111 1, | |
112 vampPiperAdapter.getPreferredStepSize(), | |
113 vampPiperAdapter.getPreferredBlockSize() | |
114 ) == false | |
115 ); | |
116 REQUIRE( | |
117 vampPiperAdapter.initialise( | |
118 1, | |
119 vampPiperAdapter.getPreferredStepSize(), | |
120 vampPiperAdapter.getPreferredBlockSize() | |
121 ) | |
122 ); | |
5 } | 123 } |