Mercurial > hg > piper-cpp
comparison test/vamp-client/tst_PluginStub.cpp @ 205:587e9691a44e
Merge pull request #4 from piper-audio/test/plugin-stub-configured-framing
Test/plugin stub configured framing
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Thu, 09 Feb 2017 12:54:00 +0000 |
parents | c9471a9f4b71 |
children | a69724686f0b |
comparison
equal
deleted
inserted
replaced
204:fbc61cf65c64 | 205:587e9691a44e |
---|---|
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> | |
7 | |
8 using namespace piper_vamp; | |
9 using namespace piper_vamp::client; | |
10 using AudioBuffer = std::vector<std::vector<float>>; | |
11 | |
12 // This stub fakes 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 than config provides | |
29 // there isn't really any need to be doing this with a plugin param | |
30 cr.framing.blockSize = config.framing.blockSize * scale; | |
31 cr.framing.stepSize = config.framing.stepSize * scale; | |
32 | |
33 // just return some outputs anyway | |
34 // to avoid a failure case we are not testing here. | |
35 Vamp::Plugin::OutputDescriptor output; | |
36 const auto basic = m_staticData.basicOutputInfo[0]; | |
37 output.identifier = basic.identifier; | |
38 output.name = basic.name; | |
39 output.description = basic.description; | |
40 cr.outputs = {output}; | |
41 return cr; | |
42 } | |
43 | |
44 Vamp::Plugin::FeatureSet | |
45 process(PluginStub* /*plugin*/, | |
46 AudioBuffer /*channels*/, | |
47 Vamp::RealTime /*timestamp*/) override | |
48 { | |
49 return {}; | |
50 } | |
51 | |
52 Vamp::Plugin::FeatureSet | |
53 finish(PluginStub* /*plugin*/) override | |
54 { | |
55 return {}; | |
56 } | |
57 | |
58 void | |
59 reset(PluginStub* /*plugin*/, PluginConfiguration /*config*/) override | |
60 {} | |
61 private: | |
62 PluginStaticData m_staticData; | |
63 }; | |
64 | |
65 | |
66 TEST_CASE("Init plugin with parameter dependent preferred framing sizes") { | |
67 const std::size_t initialBlockSize = 1024; | |
68 const std::size_t initialStepSize = 512; | |
69 PluginConfiguration defaultConfig; | |
70 defaultConfig.channelCount = 1; | |
71 defaultConfig.framing.blockSize = initialBlockSize; | |
72 defaultConfig.framing.stepSize = initialStepSize; | |
73 defaultConfig.parameterValues = {{"framing-scale", 1.0}}; | |
74 | |
75 Vamp::PluginBase::ParameterDescriptor stubParam; | |
76 stubParam.identifier = "framing-scale"; | |
77 stubParam.name = "Framing Scale Factor"; | |
78 stubParam.description = "Scales the preferred framing sizes"; | |
79 stubParam.maxValue = 2.0; | |
80 | |
81 PluginStaticData staticData; | |
82 staticData.pluginKey = "stub"; | |
83 staticData.basic = {"param-init", "Stub", "Testing init"}; | |
84 staticData.maker = "Lucas Thompson"; | |
85 staticData.copyright = "GPL"; | |
86 staticData.pluginVersion = 1; | |
87 staticData.category = {"Test"}; | |
88 staticData.minChannelCount = 1; | |
89 staticData.maxChannelCount = 1; | |
90 staticData.parameters = {stubParam}; | |
91 staticData.inputDomain = Vamp::Plugin::InputDomain::TimeDomain; | |
92 staticData.basicOutputInfo = {{"output", "NA", "Not real"}}; | |
93 | |
94 StubClient stub {staticData}; | |
95 | |
96 PluginStub vampPiperAdapter { | |
97 &stub, | |
98 "stub", // plugin key | |
99 44100.0, // sample rate | |
100 0, // adapter flags, don't care here | |
101 staticData, | |
102 defaultConfig | |
103 }; | |
104 | |
105 const auto initWithPreferredFraming = [&]() -> bool { | |
106 return vampPiperAdapter.initialise( | |
107 1, | |
108 vampPiperAdapter.getPreferredStepSize(), | |
109 vampPiperAdapter.getPreferredBlockSize() | |
110 ); | |
111 }; | |
112 | |
113 const AudioBuffer monoAudio { | |
114 std::vector<float>(vampPiperAdapter.getPreferredBlockSize()) | |
115 }; | |
116 const std::vector<const float*> channelPtrs { | |
117 monoAudio[0].data() | |
118 }; | |
119 | |
120 SECTION("Initialises with default parameters") | |
121 { | |
122 REQUIRE( initWithPreferredFraming() ); | |
123 } | |
124 | |
125 SECTION("Fails to init when changing framing influencing parameter") | |
126 { | |
127 const float scalingFactor = 2.0; | |
128 vampPiperAdapter.setParameter("framing-scale", scalingFactor); | |
129 REQUIRE( initWithPreferredFraming() == false ); | |
130 const float configuredStepSize = vampPiperAdapter.getPreferredStepSize(); | |
131 const float configuredBlockSize = vampPiperAdapter.getPreferredBlockSize(); | |
132 REQUIRE( configuredStepSize == initialStepSize * scalingFactor ); | |
133 REQUIRE( configuredBlockSize == initialBlockSize * scalingFactor ); | |
134 } | |
135 | |
136 SECTION("Cannot process after a failed init call (due to framing)") | |
137 { | |
138 const float scalingFactor = 2.0; | |
139 vampPiperAdapter.setParameter("framing-scale", scalingFactor); | |
140 REQUIRE( initWithPreferredFraming() == false ); | |
141 REQUIRE_THROWS( vampPiperAdapter.process(channelPtrs.data(), {}) ); | |
142 REQUIRE_THROWS( initWithPreferredFraming() ); | |
143 } | |
144 | |
145 SECTION("Can process after correctly initialising framing") | |
146 { | |
147 const float scalingFactor = 2.0; | |
148 vampPiperAdapter.setParameter("framing-scale", scalingFactor); | |
149 REQUIRE( initWithPreferredFraming() == false ); | |
150 REQUIRE( initWithPreferredFraming() ); | |
151 REQUIRE( vampPiperAdapter.process(channelPtrs.data(), {}).empty() ); | |
152 } | |
153 } |