Mercurial > hg > piper-vamp-js
comparison test/node-load-test.js @ 59:a1eb63b9ba6f
Permit running test with only one arg (picking up first plugin as default), check for successful response, etc
| author | Chris Cannam |
|---|---|
| date | Thu, 10 Nov 2016 17:07:35 +0000 |
| parents | f6220d293bff |
| children | 1cde1f236634 |
comparison
equal
deleted
inserted
replaced
| 58:f6220d293bff | 59:a1eb63b9ba6f |
|---|---|
| 2 | 2 |
| 3 function note(blah) { | 3 function note(blah) { |
| 4 console.log(blah); | 4 console.log(blah); |
| 5 } | 5 } |
| 6 | 6 |
| 7 if (process.argv.length < 4) { | 7 if (process.argv.length < 3 || process.argv.length > 4) { |
| 8 note("\nUsage: " + process.argv[0] + " <LibraryPath> <pluginKey>"); | 8 note("\nUsage: " + process.argv[0] + " <librarypath> [<pluginkey>]"); |
| 9 note("e.g. " + process.argv[0] + " ./VampExamplePlugins.js"); | |
| 9 note("e.g. " + process.argv[0] + " ./VampExamplePlugins.js vamp-example-plugins:zerocrossing"); | 10 note("e.g. " + process.argv[0] + " ./VampExamplePlugins.js vamp-example-plugins:zerocrossing"); |
| 10 throw "Wrong number of command-line args (2 expected)" | 11 throw "Wrong number of command-line args (1 or 2 expected)" |
| 11 } | 12 } |
| 12 | 13 |
| 13 var libraryPath = process.argv[2]; | 14 var libraryPath = process.argv[2]; |
| 14 var pluginKey = process.argv[3]; | 15 |
| 16 var pluginKey = ""; | |
| 17 if (process.argv.length > 3) { | |
| 18 pluginKey = process.argv[3]; | |
| 19 } | |
| 15 | 20 |
| 16 var base64 = require("./base64"); | 21 var base64 = require("./base64"); |
| 17 | 22 |
| 18 note("Loading library \"" + libraryPath + "\"..."); | 23 note("Loading library \"" + libraryPath + "\"..."); |
| 19 var extractor = require(libraryPath); | 24 var extractor = require(libraryPath); |
| 139 return features.set(key, convertWireFeatureList(wireFeatures[key])); | 144 return features.set(key, convertWireFeatureList(wireFeatures[key])); |
| 140 }); | 145 }); |
| 141 return features; | 146 return features; |
| 142 } | 147 } |
| 143 | 148 |
| 149 function checkSuccess(response) { | |
| 150 if (response.error) { | |
| 151 console.log("Request type " + response.method + " failed: " + | |
| 152 response.error.message); | |
| 153 throw response.error.message; | |
| 154 } | |
| 155 } | |
| 156 | |
| 144 function test() { | 157 function test() { |
| 145 | 158 |
| 146 const rate = 44100; | 159 const rate = 44100; |
| 147 | 160 |
| 148 note("Loading plugin \"" + pluginKey + "\"..."); | 161 note("Listing plugins..."); |
| 149 let response = request({ | 162 let response = request({ |
| 163 method: "list" | |
| 164 }); | |
| 165 checkSuccess(response); | |
| 166 | |
| 167 if (pluginKey === "") { | |
| 168 pluginKey = response.result.available[0].key; | |
| 169 note("Loading first plugin \"" + pluginKey + "\"..."); | |
| 170 } else { | |
| 171 note("Loading requested plugin \"" + pluginKey + "\"..."); | |
| 172 } | |
| 173 | |
| 174 response = request({ | |
| 150 method: "load", | 175 method: "load", |
| 151 params: { | 176 params: { |
| 152 key: pluginKey, | 177 key: pluginKey, |
| 153 inputSampleRate: rate, | 178 inputSampleRate: rate, |
| 154 adapterFlags: ["AdaptAllSafe"] | 179 adapterFlags: ["AdaptAllSafe"] |
| 155 } | 180 } |
| 156 }); | 181 }); |
| 157 | 182 checkSuccess(response); |
| 158 const blockSize = 1024; | 183 |
| 184 const blockSize = response.result.defaultConfiguration.blockSize; | |
| 185 const stepSize = response.result.defaultConfiguration.stepSize; | |
| 159 | 186 |
| 160 response = request({ | 187 response = request({ |
| 161 method: "configure", | 188 method: "configure", |
| 162 params: { | 189 params: { |
| 163 handle: 1, | 190 handle: 1, |
| 164 configuration: { | 191 configuration: { |
| 165 blockSize: blockSize, | 192 blockSize: blockSize, |
| 166 channelCount: 1, | 193 stepSize: stepSize, |
| 167 stepSize: blockSize | 194 channelCount: 1 |
| 168 } | 195 } |
| 169 } | 196 } |
| 170 }); | 197 }); |
| 198 checkSuccess(response); | |
| 171 | 199 |
| 172 const nblocks = 1000; | 200 const nblocks = 1000; |
| 173 | 201 |
| 174 const makeBlock = (n => { | 202 const makeBlock = (n => { |
| 175 return { | 203 return { |
| 194 }); | 222 }); |
| 195 let features = responseToFeatureSet(response); | 223 let features = responseToFeatureSet(response); |
| 196 for (let featureList of features.values()) { | 224 for (let featureList of features.values()) { |
| 197 featureCount += featureList.length; | 225 featureCount += featureList.length; |
| 198 } | 226 } |
| 199 console.log(i); | |
| 200 } | 227 } |
| 201 | 228 |
| 202 note("Cleaning up the plugin and getting any remaining features..."); | 229 note("Cleaning up the plugin and getting any remaining features..."); |
| 203 response = request({ | 230 response = request({ |
| 204 method: "finish", | 231 method: "finish", |
| 205 params: { | 232 params: { |
| 206 handle: 1 | 233 handle: 1 |
| 207 } | 234 } |
| 208 }); | 235 }); |
| 236 checkSuccess(response); | |
| 209 | 237 |
| 210 let features = responseToFeatureSet(response); | 238 let features = responseToFeatureSet(response); |
| 211 for (let featureList of features.values()) { | 239 for (let featureList of features.values()) { |
| 212 featureCount += featureList.length; | 240 featureCount += featureList.length; |
| 213 } | 241 } |
