-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (39 loc) · 1.25 KB
/
app.js
File metadata and controls
45 lines (39 loc) · 1.25 KB
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
window.ctx = new AudioContext();
// ctx.suspend();
function URLFromFiles(files) {
const promises = files.map((file) =>
fetch(file).then((response) => response.text())
);
return Promise.all(promises).then((texts) => {
const text = texts.join("");
const blob = new Blob([text], { type: "application/javascript" });
return URL.createObjectURL(blob);
});
}
URLFromFiles(["./processor.js"]).then((e) => {
if (ctx.audioWorklet === undefined) {
log("No AudioWorklet.");
} else {
ctx.audioWorklet.addModule(e).then(() => {
window.dataSAB = new SharedArrayBuffer(2048 * 4); // 4 is the byte lenth
window.pointerSAB = new SharedArrayBuffer(2 * 4);
window.writePtr = new Uint32Array(window.pointerSAB, 0, 1);
window.readPtr = new Uint32Array(window.pointerSAB, 4, 1);
const n = new AudioWorkletNode(ctx, "processor", {
processorOptions: {
dataSAB: window.dataSAB,
pointerSAB: window.pointerSAB,
writePtr: window.writePtr,
readPtr: window.readPtr,
},
});
n.connect(ctx.destination);
});
}
});
window.audioStart = () => {
ctx.resume();
}
window.audioStop = () => {
ctx.suspend();
}