1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<pre>
Wasm audio FIR. Version: 0.1
</pre>
<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.");
get_cutoff_freq = Module.cwrap("get_cutoff_freq","number",[]);
set_cutoff_plus_1k= Module.cwrap("set_cutoff_plus_1k",[],[]);
set_cutoff_minus_1k = Module.cwrap("set_cutoff_minus_1k",[],[]);
get_tap_number = Module.cwrap("get_tap_number","number",[]);
recalculate_fir = Module.cwrap("recalculate_fir",'number',['float']);
start_loop = Module.cwrap("start_loop",'number',[]);
stop_loop = Module.cwrap("stop_loop",'number',[]);
set_tap_number_plus_10 = Module.cwrap("set_tap_number_plus_10",[],[]);
set_tap_number_minus_10 = Module.cwrap("set_tap_number_minus_10",[],[]);
var setCutoffFrequency = document.querySelector('.setCutoffFrequency')
var getCutoffFrequency = document.querySelector('.getCutoffFrequency')
var outSetCutoffFrequency = document.querySelector('.outSetCutoffFrequency')
var minusNumberTaps = document.querySelector('.minusNumberTaps')
var plusNumberTaps = document.querySelector('.pplusNumberTaps')
var outSetNumberTaps = document.querySelector('.outSetNumberTaps')
var recalculateFir = document.querySelector('.recalculateFir')
var outCoeficients = document.querySelector('.outCoeficients')
//outSetCutoffFrequency.value = get_cutoff_freq();
//outSetCutoffFrequency.value = "Hello";
//outSetNumberTaps.value = get_tap_number();
document.querySelector("#recalculateFir").onclick = function() {
console.log("Oh noe");
//https://stackoverflow.com/questions/17883799/how-to-handle-passing-returning-array-pointers-to-emscripten-compiled-code
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
}
}
myArray = cArray(200);
var result = recalculate_fir(myArray.offset);
var arr = Array(myArray.data.slice(1,result-1));
arr = arr.map(function(item){
return item.map(function(num){
return parseFloat(num.toFixed(5));
});
});
outCoeficients.value = arr;
}
document.querySelector("#getCutoffFrequency").onclick = function() {
console.log("--1kHz");
set_cutoff_minus_1k();
var result=get_cutoff_freq();
outSetCutoffFrequency.value = result;
}
document.querySelector("#setCutoffFrequency").onclick = function() {
console.log("+1kHz");
set_cutoff_plus_1k();
var result=get_cutoff_freq();
outSetCutoffFrequency.value = result;
}
document.querySelector("#plusNumberTaps").onclick = function() {
console.log("Oh noe");
set_tap_number_plus_10();
var result = get_tap_number()
outSetNumberTaps.value = result;
}
document.querySelector("#minusNumberTaps").onclick = function() {
console.log("Oh noe");
set_tap_number_minus_10();
var result = get_tap_number()
outSetNumberTaps.value = result;
}
}
document.body.appendChild(script);
});
</script>
<div align="center">
<canvas id="canvas" ></canvas>
</div>
<button id="setCutoffFrequency" type="button">Cutoff +1KHz</button>
<button id="getCutoffFrequency" type="button">Cutoff -1Khz</button>
<textarea class="outSetCutoffFrequency"></textarea>
<button id="plusNumberTaps" type="button">Tap N+10</button>
<button id="minusNumberTaps" type="button">Tap N-10</button>
<textarea class="outSetNumberTaps"></textarea>
<button id="recalculateFir" type="button">Calc</button>
<textarea class="outCoeficients"></textarea>
<script>
</script>
<pre>
If no recording, check developer console(Ctrl+Shift+I) or add domain (http://wasm.main.lv) to chrome://flags/#unsafely-treat-insecure-origin-as-secure
Workflow(r->s->q)
Supported keys:
r - record sound buffer
s - play recorded buffer
q - applay fir filter
</pre>
<pre>
Changelog:
v0.1 - initial release
</pre>
</body>
</html>
|