From ec585ba33f61381e5b2095c2386083ea843b2c47 Mon Sep 17 00:00:00 2001 From: ZoRo Date: Fri, 27 Aug 2021 09:32:54 +0100 Subject: Demo wasm page --- Build/Makefile | 5 ++-- Build/index.html | 86 +++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/Build/Makefile b/Build/Makefile index f56677d..06076fb 100644 --- a/Build/Makefile +++ b/Build/Makefile @@ -2,7 +2,7 @@ EMCC=emcc CC=gcc SOURCEDIR=../NaiveFFT LDFLAGS=-lm -EM_LDFALGS=-s LLD_REPORT_UNDEFINED +EM_LDFALGS=-s USE_SDL=2 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s LLD_REPORT_UNDEFINED -s USE_GLFW=3 make: @@ -10,8 +10,9 @@ make: $(CC) -c $(SOURCEDIR)/fft.c -g3 $(CC) main.o fft.o -o NaiveFFT $(LDFLAGS) +#https://github.com/emscripten-core/emscripten/issues/6882 no malloc emcc: - $(EMCC) $(SOURCEDIR)/main.c $(SOURCEDIR)/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 -O0 -o index.js $(EM_LDFALGS) -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' web: diff --git a/Build/index.html b/Build/index.html index 8f510ac..1a571f7 100644 --- a/Build/index.html +++ b/Build/index.html @@ -17,18 +17,23 @@ .then(response => response.arrayBuffer() ).then(buffer => { - Module.canvas = document.getElementById("canvas"); + //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']); + run_fft= Module.cwrap("fft_1",[],[['float'],['float'],'number','number']); - var inputData = document.querySelector('.inputData'); + var inputDataI = document.querySelector('.inputDataI'); + var inputDataIerr = document.querySelector('.inputDataIerr'); + var inputDataQ = document.querySelector('.inputDataQ'); + var inputDataQerr = document.querySelector('.inputDataQerr'); + var outputDataI = document.querySelector('.outputDataI'); + var outputDataQ = document.querySelector('.outputDataQ'); document.querySelector("#calcButton").onclick = function() { console.log("calc FFT"); @@ -42,18 +47,67 @@ } } - var strArr = inputData.value; - strArr = strArr.replace(/ +(?= )/g,''); - var splArr = strArr.split(" "); - if (splArr.some(i => i != parseFloat(i))) { - throw i + " is not integer" + function checkArr(inputData,errorOutput) { + var strArr = inputDataI.value; + + strArr = strArr.replace(/ +(?= )/g,''); + var splArr = strArr.split(" "); + var data = Array(splArr.length).fill(0); + for (let i=0; i - FFT demo - - + + + FFT demo, max value N=8
+ Input I:
+ Input Q:
+ Output I:
+ Output Q:
+