Mercurial > hg > piper-cpp
comparison test/vamp-client/tst_PluginStub.cpp @ 194:4848852c4fbd
Add some more tests for calling process after successful and failed initialise calls.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 07 Feb 2017 18:19:57 +0000 |
parents | 79c64ff2610b |
children | ec95a44bab22 |
comparison
equal
deleted
inserted
replaced
193:bc35e19f3345 | 194:4848852c4fbd |
---|---|
23 { | 23 { |
24 const float scale = plugin->getParameter("framing-scale"); | 24 const float scale = plugin->getParameter("framing-scale"); |
25 ConfigurationResponse cr; | 25 ConfigurationResponse cr; |
26 cr.plugin = plugin; | 26 cr.plugin = plugin; |
27 | 27 |
28 // we want to return different framing sizes | 28 // we want to return different framing sizes than config provides |
29 // than config provides | |
30 // there isn't really any need to be doing this with a plugin param | 29 // there isn't really any need to be doing this with a plugin param |
31 cr.framing.blockSize = config.framing.stepSize * scale; | 30 cr.framing.blockSize = config.framing.blockSize * scale; |
32 cr.framing.stepSize = config.framing.blockSize * scale; | 31 cr.framing.stepSize = config.framing.stepSize * scale; |
33 | |
34 | 32 |
35 // just return some outputs anyway | 33 // just return some outputs anyway |
36 // to avoid a failure case we are not testing here. | 34 // to avoid a failure case we are not testing here. |
37 Vamp::Plugin::OutputDescriptor output; | 35 Vamp::Plugin::OutputDescriptor output; |
38 const auto basic = m_staticData.basicOutputInfo[0]; | 36 const auto basic = m_staticData.basicOutputInfo[0]; |
64 PluginStaticData m_staticData; | 62 PluginStaticData m_staticData; |
65 }; | 63 }; |
66 | 64 |
67 | 65 |
68 TEST_CASE("Init plugin with parameter dependent preferred framing sizes") { | 66 TEST_CASE("Init plugin with parameter dependent preferred framing sizes") { |
69 | 67 const std::size_t initialBlockSize = 1024; |
68 const std::size_t initialStepSize = 512; | |
70 PluginConfiguration defaultConfig; | 69 PluginConfiguration defaultConfig; |
71 defaultConfig.channelCount = 1; | 70 defaultConfig.channelCount = 1; |
72 defaultConfig.parameterValues = {}; | 71 defaultConfig.parameterValues = {}; |
73 defaultConfig.framing.blockSize = 1024; | 72 defaultConfig.framing.blockSize = initialBlockSize; |
74 defaultConfig.framing.stepSize = 512; | 73 defaultConfig.framing.stepSize = initialStepSize; |
75 defaultConfig.parameterValues = {{"framing-scale", 1.0}}; | 74 defaultConfig.parameterValues = {{"framing-scale", 1.0}}; |
76 | 75 |
77 Vamp::PluginBase::ParameterDescriptor stubParam; | 76 Vamp::PluginBase::ParameterDescriptor stubParam; |
78 stubParam.identifier = "framing-scale"; | 77 stubParam.identifier = "framing-scale"; |
79 stubParam.name = "Framing Scale Factor"; | 78 stubParam.name = "Framing Scale Factor"; |
102 0, // adapter flags, don't care here | 101 0, // adapter flags, don't care here |
103 staticData, | 102 staticData, |
104 defaultConfig | 103 defaultConfig |
105 }; | 104 }; |
106 | 105 |
107 vampPiperAdapter.setParameter("framing-scale", 2.0); | 106 const auto initWithPreferredFraming = [&]() -> bool { |
108 // setup | 107 return vampPiperAdapter.initialise( |
109 REQUIRE( | |
110 vampPiperAdapter.initialise( | |
111 1, | 108 1, |
112 vampPiperAdapter.getPreferredStepSize(), | 109 vampPiperAdapter.getPreferredStepSize(), |
113 vampPiperAdapter.getPreferredBlockSize() | 110 vampPiperAdapter.getPreferredBlockSize() |
114 ) == false | 111 ); |
115 ); | 112 }; |
116 REQUIRE( | 113 |
117 vampPiperAdapter.initialise( | 114 SECTION("Initialises with default parameters") |
118 1, | 115 { |
119 vampPiperAdapter.getPreferredStepSize(), | 116 REQUIRE( initWithPreferredFraming() ); |
120 vampPiperAdapter.getPreferredBlockSize() | 117 } |
121 ) | 118 |
122 ); | 119 SECTION("Fails to init when changing framing influencing parameter") |
120 { | |
121 const float scalingFactor = 2.0; | |
122 vampPiperAdapter.setParameter("framing-scale", scalingFactor); | |
123 REQUIRE( initWithPreferredFraming() == false ); | |
124 const float configuredStepSize = vampPiperAdapter.getPreferredStepSize(); | |
125 const float configuredBlockSize = vampPiperAdapter.getPreferredBlockSize(); | |
126 REQUIRE( configuredStepSize == initialStepSize * scalingFactor ); | |
127 REQUIRE( configuredBlockSize == initialBlockSize * scalingFactor ); | |
128 } | |
129 | |
130 SECTION("Cannot process after a failed init call (due to framing)") | |
131 { | |
132 const float scalingFactor = 2.0; | |
133 vampPiperAdapter.setParameter("framing-scale", scalingFactor); | |
134 REQUIRE( initWithPreferredFraming() == false ); | |
135 REQUIRE_THROWS( vampPiperAdapter.process(nullptr, {}) ); | |
136 } | |
137 | |
138 SECTION("Can process after correctly initialising framing") | |
139 { | |
140 const float scalingFactor = 2.0; | |
141 vampPiperAdapter.setParameter("framing-scale", scalingFactor); | |
142 REQUIRE( initWithPreferredFraming() == false ); | |
143 REQUIRE( initWithPreferredFraming() ); | |
144 | |
145 const AudioBuffer monoAudio = { | |
146 std::vector<float>(vampPiperAdapter.getPreferredBlockSize()) | |
147 }; | |
148 const std::vector<const float*> channelPtrs { | |
149 monoAudio[0].data() | |
150 }; | |
151 REQUIRE( vampPiperAdapter.process(channelPtrs.data(), {}).empty() ); | |
152 } | |
123 } | 153 } |