comparison perf-test-node.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
6 6
7 // It is possible to declare both parameters and return values as 7 // It is possible to declare both parameters and return values as
8 // "string", in which case Emscripten will take care of 8 // "string", in which case Emscripten will take care of
9 // conversions. But it's not clear how one would manage memory for 9 // conversions. But it's not clear how one would manage memory for
10 // newly-constructed returned C strings -- the returned pointer from 10 // newly-constructed returned C strings -- the returned pointer from
11 // vampipeRequestJson would appear (?) to be thrown away by the 11 // piperRequestJson would appear (?) to be thrown away by the
12 // Emscripten string converter if we declare it as returning a string, 12 // Emscripten string converter if we declare it as returning a string,
13 // so we have no opportunity to pass it to vampipeFreeJson, which 13 // so we have no opportunity to pass it to piperFreeJson, which
14 // suggests this would leak memory if the string isn't static. Not 14 // suggests this would leak memory if the string isn't static. Not
15 // wholly sure though. Anyway, passing and returning pointers (as 15 // wholly sure though. Anyway, passing and returning pointers (as
16 // numbers) means we can manage the Emscripten heap memory however we 16 // numbers) means we can manage the Emscripten heap memory however we
17 // want in our request wrapper function below. 17 // want in our request wrapper function below.
18 18
19 var vampipeRequestJson = exampleModule.cwrap( 19 var piperRequestJson = exampleModule.cwrap(
20 'vampipeRequestJson', 'number', ['number'] 20 'piperRequestJson', 'number', ['number']
21 ); 21 );
22 22
23 var vampipeProcessRaw = exampleModule.cwrap( 23 var piperProcessRaw = exampleModule.cwrap(
24 "vampipeProcessRaw", "number", ["number", "number", "number", "number"] 24 "piperProcessRaw", "number", ["number", "number", "number", "number"]
25 ); 25 );
26 26
27 var vampipeFreeJson = exampleModule.cwrap( 27 var piperFreeJson = exampleModule.cwrap(
28 'vampipeFreeJson', 'void', ['number'] 28 'piperFreeJson', 'void', ['number']
29 ); 29 );
30 30
31 function note(blah) { 31 function note(blah) {
32 console.log(blah); 32 console.log(blah);
33 } 33 }
51 exampleModule.HEAPU8.buffer, framesPtr, nFrames); 51 exampleModule.HEAPU8.buffer, framesPtr, nFrames);
52 frames.set(request.processInput.inputBuffers[i]); 52 frames.set(request.processInput.inputBuffers[i]);
53 buffers[i] = framesPtr; 53 buffers[i] = framesPtr;
54 } 54 }
55 55
56 const responseJson = vampipeProcessRaw( 56 const responseJson = piperProcessRaw(
57 request.handle, 57 request.handle,
58 buffersPtr, 58 buffersPtr,
59 request.processInput.timestamp.s, 59 request.processInput.timestamp.s,
60 request.processInput.timestamp.n); 60 request.processInput.timestamp.n);
61 61
65 exampleModule._free(buffersPtr); 65 exampleModule._free(buffersPtr);
66 66
67 const responseJstr = exampleModule.Pointer_stringify(responseJson); 67 const responseJstr = exampleModule.Pointer_stringify(responseJson);
68 const response = JSON.parse(responseJstr); 68 const response = JSON.parse(responseJstr);
69 69
70 vampipeFreeJson(responseJson); 70 piperFreeJson(responseJson);
71 71
72 return response; 72 return response;
73 } 73 }
74 74
75 function makeTimestamp(seconds) { 75 function makeTimestamp(seconds) {
94 // Inspection reveals that intArrayFromString converts the string 94 // Inspection reveals that intArrayFromString converts the string
95 // from utf16 to utf8, which is what we want (though the docs 95 // from utf16 to utf8, which is what we want (though the docs
96 // don't mention this). Note the *Cstr values are Emscripten heap 96 // don't mention this). Note the *Cstr values are Emscripten heap
97 // pointers 97 // pointers
98 var inCstr = m.allocate(m.intArrayFromString(jsonStr), 'i8', m.ALLOC_NORMAL); 98 var inCstr = m.allocate(m.intArrayFromString(jsonStr), 'i8', m.ALLOC_NORMAL);
99 var outCstr = vampipeRequestJson(inCstr); 99 var outCstr = piperRequestJson(inCstr);
100 m._free(inCstr); 100 m._free(inCstr);
101 var result = m.Pointer_stringify(outCstr); 101 var result = m.Pointer_stringify(outCstr);
102 vampipeFreeJson(outCstr); 102 piperFreeJson(outCstr);
103 note("Returned JSON = " + result); 103 note("Returned JSON = " + result);
104 return result; 104 return result;
105 } 105 }
106 106
107 function myFromBase64(b64) { 107 function myFromBase64(b64) {