Visualizations
252 / 500

252 · Sound

Generative Music

A self-composing synthesizer you can see, played with the Web Audio API.

A sequencer composes as it goes, picking notes from a scale over a slowly changing chord progression, and synthesizes every sound with Web Audio oscillators, filters and envelopes: no samples. Each voice is drawn as rings and ripples that bloom when it plays, and an analyser node feeds a live spectrum. It stays silent until you click, since browsers block sound until you interact.

Try it. Click (or press space) to turn the sound on or off. Move the pointer to change the mood and tempo: further right is brighter, higher is faster.

  • Web Audio synthesis
  • Algorithmic composition
  • Audio-reactive drawing

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a generative music toy with JavaScript, the Web Audio API and the HTML canvas element. It should compose a calm, pleasant piece forever and draw what it plays. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it a deep night blue.
- Browsers block audio until the user interacts, so create the AudioContext inside a click handler, show a small "Click for sound" hint until then, and let a second click mute it.
- Run a sequencer clock in sixteenth notes at about 90 bpm. Schedule notes slightly ahead on audioContext.currentTime so the timing stays tight.
- Pick a scale (D dorian is a lovely start) and loop a four-chord progression, one chord per bar, building each chord from scale degrees: root, third, fifth and seventh.
- Play three voices with oscillators and gain envelopes: a soft sawtooth pad holding the chord through a lowpass filter, a triangle bass on the root, and a plucky arpeggio cycling through the chord tones.
- Draw a ring that pulses on every note, with a different color for each voice.

Once that works, make it beautiful:
- Add a melody: write two-bar phrases that move mostly by step, land on chord tones on strong beats, repeat with small variations, and rest between phrases.
- Add a gentle kick, snare and hi-hat from oscillators and filtered noise.
- Add a reverb with a ConvolverNode whose impulse response is just stereo noise fading out over three seconds, plus a feedback delay.
- Drive the visuals from the sequencer so they run while muted, and add a live spectrum from an AnalyserNode when the sound is on.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as letting the mouse change the mode and tempo, placing notes on a circle of fifths, or recording the output to a file.
PreviousCritical PercolationOpen hexagons merge into a giant cluster the instant p crosses one half. NextSeismic ShadowQuake waves curve through a cutaway Earth, leaving the shadows that revealed its core.

Related visualizations

  • Granular CloudSound Granular synthesis made visible: every grain is a glowing droplet shaped by its window.
  • Automaton OrchestraEmergence Elementary cellular automata woven into cloth on a loom and played as music.
  • Spectrogram PainterSound Paint sound in time and frequency, then watch the real spectrogram of what you hear.
  • Modular SynthSound A eurorack case with a working signal graph and patch cables that sag and swing.
  • FM SynthesisSound A four-operator FM synth whose sidebands land exactly where Bessel functions say.
  • Xenakis GlissandiGenerative art Metastaseis-style string glissandi as ruled surfaces on graph paper, and a gas of notes.
  • TonnetzSound Euler's lattice of tones, where chords flip like cards and the plane folds into a torus.
  • Perceptual CodecSound Watch a psychoacoustic model decide which parts of the music you will never miss.
  • Bytebeat MachineSound Whole songs from one line of bit arithmetic, drawn as a tapestry of bytes.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs