summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-10-15 21:44:15 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-10-15 21:44:15 +0200
commit17b3c1e4231288056b794ab22771d2b3fb423984 (patch)
tree6ab29ad91fca570389c42713d2ca420a24a70a3d /web
parent44e8d9cee54a24367d25410f78aa10d479eda572 (diff)
Added emscripten calls for hz interpretation
This also uncovered a weird compilation issue. Emscripten did NOT like me using the remainder operator with a floating point number.
Diffstat (limited to 'web')
-rw-r--r--web/main.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/web/main.js b/web/main.js
index 2388be8..5b58f9d 100644
--- a/web/main.js
+++ b/web/main.js
@@ -20,15 +20,28 @@ function jsArrayToF32ArrayPtr(jsArray, callback) {
return result;
}
-function find_fundamental_frequency(data, samplingRate) {
+function findFundamentalFrequency(data, samplingRate) {
return jsArrayToF32ArrayPtr(data, function(dataPtr, dataLength) {
return Module._find_fundamental_frequency(dataPtr, dataLength, samplingRate);
});
}
+function hzToCentsError(hz) {
+ return Module._hz_to_cents_error(hz);
+}
+
+function hzToPitch(hz) {
+ var wrapped = Module.cwrap('hz_to_pitch', 'string', ['number']);
+ return wrapped(hz);
+}
+
function main() {
var data = [1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0];
- var fundamental = find_fundamental_frequency(data, 44100.0);
+ var fundamental = findFundamentalFrequency(data, 44100.0);
+
+ var error = hzToCentsError(450.0);
+ var pitch = hzToPitch(450.0);
console.log("Javascript here. Our fundamental frequency according to Rust is " + fundamental + "Hz");
+ console.log("The other math shows a pitch of " + pitch + ", and an error of " + error);
}