comparison perf-test.js @ 43:90bf9d9f9c95

Rearrange and rename VamPipe -> Piper as appropriate
author Chris Cannam
date Mon, 10 Oct 2016 17:05:37 +0100
parents a734a7e976fa
children
comparison
equal deleted inserted replaced
42:873ce3bfa776 43:90bf9d9f9c95
4 4
5 // It is possible to declare both parameters and return values as 5 // It is possible to declare both parameters and return values as
6 // "string", in which case Emscripten will take care of 6 // "string", in which case Emscripten will take care of
7 // conversions. But it's not clear how one would manage memory for 7 // conversions. But it's not clear how one would manage memory for
8 // newly-constructed returned C strings -- the returned pointer from 8 // newly-constructed returned C strings -- the returned pointer from
9 // vampipeRequestJson would appear (?) to be thrown away by the 9 // piperRequestJson would appear (?) to be thrown away by the
10 // Emscripten string converter if we declare it as returning a string, 10 // Emscripten string converter if we declare it as returning a string,
11 // so we have no opportunity to pass it to vampipeFreeJson, which 11 // so we have no opportunity to pass it to piperFreeJson, which
12 // suggests this would leak memory if the string isn't static. Not 12 // suggests this would leak memory if the string isn't static. Not
13 // wholly sure though. Anyway, passing and returning pointers (as 13 // wholly sure though. Anyway, passing and returning pointers (as
14 // numbers) means we can manage the Emscripten heap memory however we 14 // numbers) means we can manage the Emscripten heap memory however we
15 // want in our request wrapper function below. 15 // want in our request wrapper function below.
16 16
17 var vampipeRequestJson = exampleModule.cwrap( 17 var piperRequestJson = exampleModule.cwrap(
18 'vampipeRequestJson', 'number', ['number'] 18 'piperRequestJson', 'number', ['number']
19 ); 19 );
20 20
21 var vampipeProcessRaw = exampleModule.cwrap( 21 var piperProcessRaw = exampleModule.cwrap(
22 "vampipeProcessRaw", "number", ["number", "number", "number", "number"] 22 "piperProcessRaw", "number", ["number", "number", "number", "number"]
23 ); 23 );
24 24
25 var vampipeFreeJson = exampleModule.cwrap( 25 var piperFreeJson = exampleModule.cwrap(
26 'vampipeFreeJson', 'void', ['number'] 26 'piperFreeJson', 'void', ['number']
27 ); 27 );
28 28
29 function note(blah) { 29 function note(blah) {
30 document.getElementById("test-result").innerHTML += blah + "<br>"; 30 document.getElementById("test-result").innerHTML += blah + "<br>";
31 } 31 }
49 exampleModule.HEAPU8.buffer, framesPtr, nFrames); 49 exampleModule.HEAPU8.buffer, framesPtr, nFrames);
50 frames.set(request.processInput.inputBuffers[i]); 50 frames.set(request.processInput.inputBuffers[i]);
51 buffers[i] = framesPtr; 51 buffers[i] = framesPtr;
52 } 52 }
53 53
54 const responseJson = vampipeProcessRaw( 54 const responseJson = piperProcessRaw(
55 request.handle, 55 request.handle,
56 buffersPtr, 56 buffersPtr,
57 request.processInput.timestamp.s, 57 request.processInput.timestamp.s,
58 request.processInput.timestamp.n); 58 request.processInput.timestamp.n);
59 59
63 exampleModule._free(buffersPtr); 63 exampleModule._free(buffersPtr);
64 64
65 const responseJstr = exampleModule.Pointer_stringify(responseJson); 65 const responseJstr = exampleModule.Pointer_stringify(responseJson);
66 const response = JSON.parse(responseJstr); 66 const response = JSON.parse(responseJstr);
67 67
68 vampipeFreeJson(responseJson); 68 piperFreeJson(responseJson);
69 69
70 return response; 70 return response;
71 } 71 }
72 72
73 function makeTimestamp(seconds) { 73 function makeTimestamp(seconds) {
92 // Inspection reveals that intArrayFromString converts the string 92 // Inspection reveals that intArrayFromString converts the string
93 // from utf16 to utf8, which is what we want (though the docs 93 // from utf16 to utf8, which is what we want (though the docs
94 // don't mention this). Note the *Cstr values are Emscripten heap 94 // don't mention this). Note the *Cstr values are Emscripten heap
95 // pointers 95 // pointers
96 var inCstr = m.allocate(m.intArrayFromString(jsonStr), 'i8', m.ALLOC_NORMAL); 96 var inCstr = m.allocate(m.intArrayFromString(jsonStr), 'i8', m.ALLOC_NORMAL);
97 var outCstr = vampipeRequestJson(inCstr); 97 var outCstr = piperRequestJson(inCstr);
98 m._free(inCstr); 98 m._free(inCstr);
99 var result = m.Pointer_stringify(outCstr); 99 var result = m.Pointer_stringify(outCstr);
100 vampipeFreeJson(outCstr); 100 piperFreeJson(outCstr);
101 note("Returned JSON = " + result); 101 note("Returned JSON = " + result);
102 return result; 102 return result;
103 } 103 }
104 104
105 function myFromBase64(b64) { 105 function myFromBase64(b64) {