comparison quick-test.js @ 6:9bba59806014

Include the requested JSON in the html as well as the returned stuff
author Chris Cannam
date Wed, 24 Aug 2016 18:00:28 +0100
parents 3a5a6535d50d
children 2a4685f230ac
comparison
equal deleted inserted replaced
5:7826fe343733 6:9bba59806014
20 20
21 var vampipeFreeJson = exampleModule.cwrap( 21 var vampipeFreeJson = exampleModule.cwrap(
22 'vampipeFreeJson', 'void', ['number'] 22 'vampipeFreeJson', 'void', ['number']
23 ); 23 );
24 24
25 function note(blah) {
26 document.getElementById("test-result").innerHTML += blah + "<br>";
27 }
28
29 function comment(blah) {
30 note("<br><i>" + blah + "</i>");
31 }
32
25 function request(jsonStr) { 33 function request(jsonStr) {
34 note("Request JSON = " + jsonStr);
26 var m = exampleModule; 35 var m = exampleModule;
27 // Inspection reveals that intArrayFromString converts the string 36 // Inspection reveals that intArrayFromString converts the string
28 // from utf16 to utf8, which is what we want (though the docs 37 // from utf16 to utf8, which is what we want (though the docs
29 // don't mention this). Note the *Cstr values are Emscripten heap 38 // don't mention this). Note the *Cstr values are Emscripten heap
30 // pointers 39 // pointers
31 var inCstr = m.allocate(m.intArrayFromString(jsonStr), 'i8', m.ALLOC_NORMAL); 40 var inCstr = m.allocate(m.intArrayFromString(jsonStr), 'i8', m.ALLOC_NORMAL);
32 var outCstr = vampipeRequestJson(inCstr); 41 var outCstr = vampipeRequestJson(inCstr);
33 m._free(inCstr); 42 m._free(inCstr);
34 var result = m.Pointer_stringify(outCstr); 43 var result = m.Pointer_stringify(outCstr);
35 vampipeFreeJson(outCstr); 44 vampipeFreeJson(outCstr);
45 note("Returned JSON = " + result);
36 return result; 46 return result;
37 }
38
39 function note(blah) {
40 document.getElementById("test-result").innerHTML += blah + "<br>";
41 } 47 }
42 48
43 function test() { 49 function test() {
44 50
45 note("Querying plugin list..."); 51 comment("Querying plugin list...");
46 var result = request('{"type": "list"}'); 52 var result = request('{"type": "list"}');
47 note("Result JSON = " + result);
48 53
49 note("<br>Loading zero crossings plugin..."); 54 comment("Loading zero crossings plugin...");
50 result = request('{"type":"load","content": {"pluginKey":"vamp-example-plugins:zerocrossing","inputSampleRate":16,"adapterFlags":["AdaptAllSafe"]}}'); 55 result = request('{"type":"load","content": {"pluginKey":"vamp-example-plugins:zerocrossing","inputSampleRate":16,"adapterFlags":["AdaptAllSafe"]}}');
51 note("Result JSON = " + result);
52 56
53 note("<br>I'm now assuming that the load succeeded and the returned pluginHandle was 1. I haven't bothered to parse the JSON. If those assumptions are wrong, this obviously isn't going to work. Configuring the plugin..."); 57 comment("I'm now assuming that the load succeeded and the returned pluginHandle was 1. I haven't bothered to parse the JSON. If those assumptions are wrong, this obviously isn't going to work. Configuring the plugin...");
54 result = request('{"type":"configure","content":{"pluginHandle":1,"configuration":{"blockSize": 8, "channelCount": 1, "stepSize": 8}}}'); 58 result = request('{"type":"configure","content":{"pluginHandle":1,"configuration":{"blockSize": 8, "channelCount": 1, "stepSize": 8}}}');
55 note("Result JSON = " + result);
56 59
57 note("<br>If I try to configure it again, it should fail because it's already configured... but this doesn't change anything, and subsequent processing should work fine. Just an example of a failure call. NB this only works if Emscripten has exception catching enabled -- it's off by default in opt builds, which would just end the script here. Wonder what the performance penalty is like."); 60 comment("If I try to configure it again, it should fail because it's already configured... but this doesn't change anything, and subsequent processing should work fine. Just an example of a failure call. NB this only works if Emscripten has exception catching enabled -- it's off by default in opt builds, which would just end the script here. Wonder what the performance penalty is like.");
58 result = request('{"type":"configure","content":{"pluginHandle":1,"configuration":{"blockSize": 8, "channelCount": 1, "stepSize": 8}}}'); 61 result = request('{"type":"configure","content":{"pluginHandle":1,"configuration":{"blockSize": 8, "channelCount": 1, "stepSize": 8}}}');
59 note("Result JSON = " + result);
60 62
61 note("<br>Now processing a couple of blocks of data, on the same assumptions..."); 63 comment("Now processing a couple of blocks of data, on the same assumptions...");
62 result = request('{"type":"process","content":{"pluginHandle":1,"processInput":{"timestamp":{"s":0,"n":0},"inputBuffers":[{"values":[0,1,-1,0,1,-1,0,1]}]}}}'); 64 result = request('{"type":"process","content":{"pluginHandle":1,"processInput":{"timestamp":{"s":0,"n":0},"inputBuffers":[{"values":[0,1,-1,0,1,-1,0,1]}]}}}');
63 note("Result JSON = " + result);
64 result = request('{"type":"process","content":{"pluginHandle":1,"processInput":{"timestamp":{"s":0,"n":500000000},"inputBuffers":[{"values":[0,1,-1,0,1,-1,0,1]}]}}}'); 65 result = request('{"type":"process","content":{"pluginHandle":1,"processInput":{"timestamp":{"s":0,"n":500000000},"inputBuffers":[{"values":[0,1,-1,0,1,-1,0,1]}]}}}');
65 note("Result JSON = " + result);
66 66
67 note("<br>Cleaning up the plugin and getting any remaining features..."); 67 comment("Cleaning up the plugin and getting any remaining features...");
68 result = request('{"type":"finish","content":{"pluginHandle":1}}'); 68 result = request('{"type":"finish","content":{"pluginHandle":1}}');
69 note("Result JSON = " + result);
70 69
71 note("<br>A process call should now fail, as the plugin has been cleaned up."); 70 comment("A process call should now fail, as the plugin has been cleaned up.");
72 result = request('{"type":"process","content":{"pluginHandle":1,"processInput":{"timestamp":{"s":0,"n":1000000000},"inputBuffers":[{"values":[0,1,-1,0,1,-1,0,1]}]}}}'); 71 result = request('{"type":"process","content":{"pluginHandle":1,"processInput":{"timestamp":{"s":0,"n":1000000000},"inputBuffers":[{"values":[0,1,-1,0,1,-1,0,1]}]}}}');
73 note("Result JSON = " + result);
74 } 72 }
75 73
76 window.onload = function() { 74 window.onload = function() {
77 test(); 75 test();
78 } 76 }