Skip to content

Ambient Sound Generator ​

Press Start to hear three layers swell together. Turn off Texture and Shimmer to hear the pad alone, then bring each layer back. The root, cutoff and frequency controls work while the sound is playing.

The library composes, not just plays.

50%
Detuned chord stack — root, fifth, octave
65 Hz
White noise through a slowly breathing filter
800 Hz
Airy detuned highs in long reverb
523 Hz

How It Works ​

Pad ​

Five triangle voices play a root, a slightly sharp copy of the root, a fifth, a slightly flat octave and a twelfth. The two close pitches beat against each other. A lowpass filter softens the harmonics, and a 0.05 Hz LFO moves its cutoff over a 20-second cycle. Move Root between 55 and 110 Hz to transpose all five voices together.

Texture ​

Looped white noise passes through a lowpass filter. At 200 Hz, mostly the low rumble gets through. As you raise Filter Cutoff towards 4,000 Hz, the hiss becomes brighter. A second LFO moves this cutoff at a different speed from the pad.

Shimmer ​

Two quiet sine voices sit a fifth apart, with the upper voice detuned by seven cents. Long reverb and slow changes in level give the high notes a different rhythm from the pad. Move Frequency to retune the pair, or switch Shimmer off to hear the space it occupies in the mix.

Build a pad with a moving filter ​

This four-second preview isolates the pad technique. The first two voices drift slowly in and out of phase. The third supplies the fifth. Start it from a button so the browser can unlock audio on the first click.

html
<button id="ambient-preview">Hear the pad</button>
typescript
import { createFilterEffect, createLFO, createPolySynth, createReverb } from 'ez-web-audio'

const preview = document.querySelector<HTMLButtonElement>('#ambient-preview')!
preview.onclick = async () => {
  preview.disabled = true
  try {
    const pad = await createPolySynth({ type: 'triangle', maxVoices: 3 })
    const filter = createFilterEffect('lowpass', { frequency: 900, q: 0.6 })
    const motion = createLFO({ frequency: 0.05, depth: 0.35 })
    try {
      pad.addEffect(filter)
      pad.addEffect(createReverb({ decay: 5, preDelay: 0.03, mix: 0.45 }))
      motion.connect(filter, 'frequency', { depthUnit: 'ratio' }).start()

      const root = 65
      const volume = pad.getGainNode().gain
      const now = pad.audioContext.currentTime
      volume.setValueAtTime(0, now)
      volume.linearRampToValueAtTime(0.25, now + 1.2)
      volume.setValueAtTime(0.25, now + 3.6)
      volume.linearRampToValueAtTime(0, now + 4)
      for (const ratio of [1, 2 ** (6 / 1200), 1.5])
        pad.play({ frequency: root * ratio, gain: 0.25 })

      await new Promise(resolve => setTimeout(resolve, 4100))
    }
    finally {
      motion.dispose()
      pad.dispose() // Releases voices and attached effects.
    }
  }
  finally {
    preview.disabled = false
  }
}

To add the texture layer, use createWhiteNoise() and attach a separate lowpass filter to the returned Sound. Give the noise a much lower gain than the pad. For shimmer, use a second createPolySynth({ type: 'sine' }) so its pitch, reverb and level stay independent.

Next Steps ​