Public
Edited
Dec 17, 2023
Insert cell
Insert cell
function generateWhiteNoise(duration = 2) {
let context = new AudioContext();
let bufferSize = context.sampleRate * duration; // Set buffer size
let buffer = context.createBuffer(1, bufferSize, context.sampleRate); // Create an audio buffer
let data = buffer.getChannelData(0); // Get channel data

// Fill the buffer with white noise
for (let i = 0; i < bufferSize; i++) {
data[i] = Math.random() * 2 - 1;
}

let noise = context.createBufferSource();
noise.buffer = buffer;
noise.connect(context.destination);
return noise;
}

Insert cell
Insert cell
Insert cell
{
playButton;
generateWhiteNoise(duration.value)
.start(0);
}

Insert cell
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