White noise has equal energy at all frequencies. Pink noise has equal energy per octave. Brown noise emphasizes lower frequencies. These are not marketing terms. They are precise mathematical descriptions of frequency distributions.
White noise
White noise has equal energy at every frequency. It sounds like TV static or a waterfall.
function whiteNoise(audioCtx, duration) {
const sampleRate = audioCtx.sampleRate;
const buffer = audioCtx.createBuffer(1, sampleRate * duration, sampleRate);
const data = buffer.getChannelData(0);
for (let i = 0; i < data.length; i++) {
data[i] = Math.random() * 2 - 1;
}
return buffer;
}
Each sample is independently random. Because there are more high frequencies than low frequencies in any given bandwidth, white noise sounds "bright" or "hissy."
Pink noise
Pink noise has equal energy per octave (not per frequency). Because each octave covers a wider frequency range as you go higher, pink noise has less energy at high frequencies. It sounds like steady rainfall or wind through trees.
function pinkNoise(audioCtx, duration) {
const sampleRate = audioCtx.sampleRate;
const buffer = audioCtx.createBuffer(1, sampleRate * duration, sampleRate);
const data = buffer.getChannelData(0);
let b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0;
for (let i = 0; i < data.length; i++) {
const white = Math.random() * 2 - 1;
b0 = 0.99886 * b0 + white * 0.0555179;
b1 = 0.99332 * b1 + white * 0.0750759;
b2 = 0.96900 * b2 + white * 0.1538520;
b3 = 0.86650 * b3 + white * 0.3104856;
b4 = 0.55000 * b4 + white * 0.5329522;
b5 = -0.7616 * b5 - white * 0.0168980;
data[i] = (b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362) * 0.11;
b6 = white * 0.115926;
}
return buffer;
}
This uses the Voss-McCartney algorithm to approximate a 1/f power spectral density from white noise through a series of first-order filters.
Brown noise
Brown noise (also called Brownian or red noise) is generated by integrating white noise. It emphasizes low frequencies heavily and sounds like rumbling thunder or a strong wind.
function brownNoise(audioCtx, duration) {
const sampleRate = audioCtx.sampleRate;
const buffer = audioCtx.createBuffer(1, sampleRate * duration, sampleRate);
const data = buffer.getChannelData(0);
let lastOut = 0;
for (let i = 0; i < data.length; i++) {
const white = Math.random() * 2 - 1;
data[i] = (lastOut + (0.02 * white)) / 1.02;
lastOut = data[i];
data[i] *= 3.5; // Compensate for volume
}
return buffer;
}
Use cases
- Focus and sleep: Pink and brown noise mask distracting environmental sounds. Research shows pink noise may improve deep sleep quality.
- Audio testing: White noise is used to test speaker frequency response and room acoustics.
- Sound design: Noise generators are foundational building blocks in synthesizers, used as raw material for percussion sounds, wind effects, and textures.
- Tinnitus relief: Many tinnitus sufferers use noise generators to mask the ringing.
For generating and playing different noise types with volume control, I built a generator at zovo.one/free-tools/noise-generator. It runs in the browser using the Web Audio API, supports white, pink, and brown noise, and requires no downloads.
I'm Michael Lip. I build free developer tools at zovo.one. 500+ tools, all private, all free.
Top comments (0)