summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
Diffstat (limited to 'Build')
-rw-r--r--Build/Makefile5
-rw-r--r--Build/index.html80
2 files changed, 83 insertions, 2 deletions
diff --git a/Build/Makefile b/Build/Makefile
index e19df12..f56677d 100644
--- a/Build/Makefile
+++ b/Build/Makefile
@@ -7,10 +7,11 @@ EM_LDFALGS=-s LLD_REPORT_UNDEFINED
make:
$(CC) -c $(SOURCEDIR)/main.c -g3
- $(CC) main.o -o NaiveFFT $(LDFLAGS)
+ $(CC) -c $(SOURCEDIR)/fft.c -g3
+ $(CC) main.o fft.o -o NaiveFFT $(LDFLAGS)
emcc:
- $(EMCC) $(SOURCEDIR)/main.c ../NaiveFFT/fft.c -s WASM=1 -O3 -o index.js $(EM_LDFALGS) -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
+ $(EMCC) $(SOURCEDIR)/main.c $(SOURCEDIR)/fft.c -s WASM=1 -O3 -o index.js $(EM_LDFALGS) -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
web:
diff --git a/Build/index.html b/Build/index.html
new file mode 100644
index 0000000..8f510ac
--- /dev/null
+++ b/Build/index.html
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <title>WebAssembly Example</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ </head>
+ <body>
+
+
+ <!-- Include the JavaScript glue code. -->
+ <!-- This will load the WebAssembly module and run its main. -->
+ <script src="index.js"></script>
+ <script type='text/javascript'>
+ var Module = {};
+ fetch('index.wasm')
+ .then(response =>
+ response.arrayBuffer()
+ ).then(buffer => {
+ Module.canvas = document.getElementById("canvas");
+ Module.wasmBinary = buffer;
+ var script = document.createElement('script');
+ script.src = "index.js";
+ script.onload = function() {
+ console.log("Emscripten boilerplate loaded.");
+ run_dft = Module.cwrap("dft", [],[['float'],['float'],'number','number']);
+ run_fft= Module.cwrap( "fft_1",[],[['float'],['float'],'number','number']);
+
+
+
+ var inputData = document.querySelector('.inputData');
+
+ document.querySelector("#calcButton").onclick = function() {
+ console.log("calc FFT");
+
+ function cArray(size) {
+ var offset = Module._malloc(size * 8);
+ Module.HEAPF64.set(new Float64Array(size), offset / 8);
+ return {
+ "data": Module.HEAPF64.subarray(offset / 8, offset / 8 + size),
+ "offset": offset
+ }
+ }
+
+ var strArr = inputData.value;
+ strArr = strArr.replace(/ +(?= )/g,'');
+ var splArr = strArr.split(" ");
+ if (splArr.some(i => i != parseFloat(i))) {
+ throw i + " is not integer"
+ }
+ //max size 8 values, as thats enought for a demo
+ //https://stackoverflow.com/questions/17883799/how-to-handle-passing-returning-array-pointers-to-emscripten-compiled-code
+
+
+ myArray = cArray(8).fill(0.0);
+
+
+ }
+
+ } //end onload
+ document.body.appendChild(script);
+ });
+
+
+ </script>
+
+ FFT demo
+ <textarea class="inputData">12 12 12</textarea>
+ <button id="calcButton" type="button">Cals</button>
+
+ <script>
+ function calcFFT() {
+ console.log("Calculate FFT")
+ var arrStr = inputData.value;
+ console.log(arrStr)
+ }
+ </script>
+
+ </body>
+</html> \ No newline at end of file