-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
43 lines (39 loc) · 1.27 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>JumpFall</title>
</head>
<body>
<h1>JumpFall Bytebeat</h1>
<textarea id="code" rows="4" cols="50">
t*(((t>>12)|(t>>8))&(63&(t>>4)))
</textarea>
<button onclick="startByteBeat()">Start</button>
<button onclick="stopByteBeat()">Stop</button>
<input type="range" id="volume" min="0" max="1" step="0.01" value="0.5">
<script>
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
let gainNode = audioCtx.createGain();
let scriptNode = audioCtx.createScriptProcessor(4096, 1, 1);
let t = 0;
gainNode.connect(audioCtx.destination);
function startByteBeat() {
let code = document.getElementById("code").value;
scriptNode.onaudioprocess = function(audioProcessingEvent) {
let outputBuffer = audioProcessingEvent.outputBuffer;
let outputData = outputBuffer.getChannelData(0);
let volume = document.getElementById("volume").value;
gainNode.gain.value = volume;
for (let sample = 0; sample < outputBuffer.length; sample++) {
outputData[sample] = eval(code) / 128.0;
t++;
}
}
scriptNode.connect(gainNode);
}
function stopByteBeat() {
scriptNode.disconnect(gainNode);
}
</script>
</body>
</html>