JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="play()">Play</button>
CSS
button {
font-size: 20px;
padding: 10px 20px;
}
JavaScript
var audioContext;
var fill = function(buffer) {}
window.play = function() {
var f = 100 * Math.exp(2 * Math.random());
var a = 2 * Math.PI * f / 44100;
var b = 0.0000001 * f;
var t = 0;
fill = function(buffer) {
for (var i = 0; i < buffer.length; i++) {
buffer[i] = Math.atan(Math.sin(a*t)/(Math.cos(a*t)+Math.exp(b*t))) * 2 / Math.PI;
t++;
}
}
if (!audioContext) {
audioContext = new AudioContext();
var scriptNode = audioContext.createScriptProcessor(1024, 1, 1);
scriptNode.onaudioprocess = function(event) {
fill(event.outputBuffer.getChannelData(0));
}
scriptNode.connect(audioContext.destination);
}
}