summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-09-24 23:03:39 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-09-24 23:03:39 +0200
commitf3a4cc60d71a0083586b5498fd2498801a634d04 (patch)
treeafe607b84ce474dc75952b70c4a64e686039dc9b /web
parent3f5fb1cc3de97244548538ec81dda3963f1b25c6 (diff)
Emscripten endpoint for finding fundamental frequency
IT'S ALIVE!
Diffstat (limited to 'web')
-rw-r--r--web/index.html7
-rw-r--r--web/main.js25
2 files changed, 32 insertions, 0 deletions
diff --git a/web/index.html b/web/index.html
new file mode 100644
index 0000000..f70f24b
--- /dev/null
+++ b/web/index.html
@@ -0,0 +1,7 @@
+<html>
+ <head>
+ <script src="main.js"></script>
+ <script src="rusty_microphone.js"></script>
+ </head>
+ <body></body>
+</html>
diff --git a/web/main.js b/web/main.js
new file mode 100644
index 0000000..b01340d
--- /dev/null
+++ b/web/main.js
@@ -0,0 +1,25 @@
+// This is read and used by `site.js`
+var Module = {
+ noInitialRun: true,
+ noExitRuntime: true,
+ onRuntimeInitialized: main
+};
+
+function jsArrayToF32ArrayPtr(jsArray) {
+ var data = new Float32Array(jsArray);
+ var nDataBytes = data.length * data.BYTES_PER_ELEMENT;
+ var dataPtr = Module._malloc(nDataBytes);
+
+ var dataHeap = new Uint8Array(Module.HEAPU8.buffer, dataPtr, nDataBytes);
+ dataHeap.set(new Uint8Array(data.buffer));
+ return dataHeap.byteOffset;
+}
+
+function main() {
+ var data = [1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0];
+ var dataLength = data.length;
+ var ptr = jsArrayToF32ArrayPtr(data);
+
+ var fundamental = _find_fundamental_frequency(ptr, data.length, 44100.0);
+ console.log("Javascript here. Our fundamental frequency according to Rust is " + fundamental + "Hz");
+}