Afterglowscreensavers

Generative Music Box Screensaver

A free screensaver that draws a music box — a rotating pinned cylinder plucking a comb of tuned steel teeth — and plays a tune generated live in your browser by a seeded random walk on a scale. Sound starts only after your first click or key press, because browsers block audio until then; until that moment the screensaver runs silently. Press ESC to exit.

Live preview

Generative Music Box screensaver — A pinned cylinder plucks a comb of tuned teeth, live.

Press ESC to leave fullscreen. Settings are saved in your browser only.

How the Generative Music Box screensaver works

The cylinder has 14 lanes, one per tooth, and 32 steps around its circumference. The pin pattern is generated from a seeded random walk over the lanes of the chosen scale: at each step the walk may place a pin, moving a few scale degrees up or down from the previous one, with pins more likely on strong beats. The same seed and scale always give the same opening tune.

The cylinder turns once per 32 steps, and the tune loops. Every turn, depending on the Mutation setting, one or two pins are moved a lane, removed or added, always on the hidden back of the cylinder, so the tune drifts slowly. A real music box never changes; this is a deliberate departure. The counter on screen reports how many pins have been re-set.

A pin that reaches the bottom plucks the tooth in its lane. Each tooth sounds a sine at its tuned pitch, plus faint, shorter higher partials, with a decay that is longer for lower notes, and it visibly vibrates. Tooth lengths are drawn roughly in proportion to 1 over the square root of frequency, as a simple cantilever model suggests; real combs also vary thickness and weighting.

All sound is synthesised in the browser with the Web Audio API and passed through a small generated reverb and a compressor used as a limiter, at a low master level. The scheduler looks ahead on the audio clock so steps stay even. Sound starts only after your first click or key press, because browsers block audio until then; until that moment the screensaver runs silently.

Where the comb and cylinder come from

The comb-and-cylinder music box is credited to Antoine Favre-Salomon, a Geneva clockmaker, in 1796, who replaced a stack of bells with a comb of pre-tuned metal teeth worked by a pinned barrel (Wikipedia, Music box). Pins on the rotating cylinder lift and release the teeth, which then ring at their tuned pitches.

This saver borrows that mechanism for a drawing and a generator. The scale choices are standard note sets; Hirajoshi has the interval pattern 2-1-4-1-4 semitones (Wikipedia, Hirajoshi scale).

No existing melody is used. The tune is whatever the seeded walk produces, and it can wander into patterns that are not musically ideal.

A worked example

With the defaults (major pentatonic, 100 bpm, seed 7) one step is an eighth note, 0.3 s, so a turn of 32 steps lasts 9.6 s. The lowest tooth is G4, about 392 Hz, and the 14 teeth span a little under three octaves of the scale. Because the seed is fixed, the first turn is the same every time you start; with Mutation at 0 each turn then repeats exactly.

Settings & tips

Frequently asked questions

Is this a recording of a real music box?
No. The tune is generated by an algorithm and the tones are synthesised live; no samples or audio files are used.
Does a real music box change its tune?
No. The pins are fixed. Here the pattern mutates slowly on purpose, and the picture shows the changed pins.
Why is it silent?
Browsers block audio until you click or press a key. Until then the cylinder turns silently.
What is a seeded random walk?
A random walk steps up or down the scale by small random amounts; seeding the random numbers means the same seed always produces the same walk.
What is the Hirajoshi scale?
A Japanese scale with steps of 2, 1, 4, 1 and 4 semitones, adapted by Yatsuhashi Kengyo for tuning the koto.
Are the tooth lengths accurate?
Only roughly. They follow a simple model in which lower notes need longer teeth; real combs also use thickness and weights, so treat it as illustration.
Will it be loud?
No. The master level is low and a limiter prevents clipping, but you can mute with a click or by pressing M.

← All Ambient screensavers