Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
hybhens authored Sep 26, 2023
1 parent 0d0bfda commit 4745336
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,33 @@ <h1>JumpFall Bytebeat</h1>
</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(audioCtx.destination);
scriptNode.connect(gainNode);
}

function stopByteBeat() {
scriptNode.disconnect(audioCtx.destination);
scriptNode.disconnect(gainNode);
}
</script>
</body>
Expand Down

0 comments on commit 4745336

Please sign in to comment.