Published
Edited
Jun 3, 2021
1 fork
18 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
scriptUrl = URL.createObjectURL(new Blob([moduleScript], {type: "text/javascript"}));
Insert cell
Insert cell
audioContext = {
var ctx = new (window.AudioContext || window.webkitAudioContext)();
if (ctx.state !== "running") {
// The browser didn't let us start playing sound yet.
// Wait for the user to move the volume slider.
await new Promise(resolve => {
viewof volume.addEventListener('input', resolve);
});
ctx = new (window.AudioContext || window.webkitAudioContext)();
}

// Close the previous context when this cell reloads.
// This avoids playing multiple sounds at once.
invalidation.then(() => ctx.close());

await ctx.audioWorklet.addModule(scriptUrl);
return ctx;
}
Insert cell
Insert cell
whiteNoise = new AudioWorkletNode(audioContext, 'white-noise-processor');
Insert cell
Insert cell
gain = audioContext.createGain();
Insert cell
Insert cell
{
whiteNoise.connect(gain);
gain.connect(audioContext.destination);
invalidation.then(() => {
whiteNoise.disconnect();
gain.disconnect();
});
}
Insert cell
Insert cell
{
gain.gain.value = volume / 20.0;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more