-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc-test.html
63 lines (49 loc) · 1.69 KB
/
gc-test.html
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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button id="henlo">Start</button>
<button id="go" style="visibility: hidden;">Add nodes</button>
<script type="module">
import {Faust} from "faust2webaudio";
import {SynthContext} from "/src/synthContext";
const start_btn = document.getElementById("henlo");
const add_btn = document.getElementById("go");
start_btn.addEventListener("click", start);
add_btn.addEventListener("click", go);
let faust;
let audioContext;
let context;
let i = 0;
let running = false;
let gain_node;
async function start() {
// Connect to Web Audio
audioContext = new window.AudioContext();
// Enable Faust compiler; wait until it's ready
faust = new Faust({
debug: true,
wasmLocation: "src/libfaust/libfaust-wasm.wasm",
dataLocation: "src/libfaust/libfaust-wasm.data"
});
await faust.ready;
context = new SynthContext(i, audioContext, undefined, true);
start_btn.style.visibility = "hidden";
add_btn.style.visibility = "visible";
}
async function go() {
if (running) return;
running = true;
gain_node = new GainNode(audioContext);
gain_node.connect(audioContext.destination);
context.generateSynth();
await context.compile(faust);
context.cleanUp();
gain_node.disconnect(audioContext.destination);
gain_node = undefined;
running = false;
}
</script>
</body>
</html>