Skip to content

Instantly share code, notes, and snippets.

@transfluxus
Last active September 11, 2022 09:46
Show Gist options
  • Save transfluxus/ae85c5388c3d7e6bad858ae13f60f4a2 to your computer and use it in GitHub Desktop.
Save transfluxus/ae85c5388c3d7e6bad858ae13f60f4a2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Noise</title>
</head>
<body>
<button id="resume_button">resume</button>
<script>
let context = new AudioContext();
let source = context.createBufferSource();
let frames = 3 * context.sampleRate;
source.buffer = context.createBuffer(1, frames, context.sampleRate);
for (let channel = 0; channel < source.buffer.numberOfChannels; channel++) {
for (let i = 0; i < frames; i++) {
source.buffer.getChannelData(channel)[i] = 2 * Math.random() - 1;
}
}
source.start();
// source.connect(context.destination)
gain = context.createGain();
source.connect(gain);
gain.connect(context.destination);
document.querySelector("#resume_button").addEventListener("click", () => {
console.log("resume")
context.resume();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment