Experiment № 058 · The story
Plucked from Noise
Why I picked it
I wanted the smallest piece of code I know of that produces something genuinely startling. Karplus–Strong is it. Kevin Karplus and Alex Strong published it in Computer Music Journal in 1983, and the entire instrument is: fill a short buffer with random numbers, then read it out on repeat, and each time you read a sample, write back the average of it and its neighbour. That's the algorithm. There's no oscillator, no envelope, no sample of a real guitar hiding anywhere — I made a point of implementing it honestly here, and the wave you see in the "delay line" panel is the literal contents of that buffer, sample for sample, the same numbers that go to the speaker. The collection already has a rhythm piece; this one is about timbre, about where the character of a sound actually comes from.
What I enjoy about it
The first half-second. Watch the delay-line panel right after a pluck: it's visibly jagged garbage, and then within a few dozen trips around the loop it organises itself into a smooth, repeating shape. Averaging two neighbouring samples is the crudest low-pass filter that exists, but it's exactly what a real string does — the high partials shake themselves apart first and the fundamental is the last thing standing. I also love the flaw. The buffer has to be a whole number of samples long, so the pitch quantises; the readout shows you the requested note and the note you actually get, in cents, and the error gets worse the higher you play. Up at the twelfth fret it's audibly sour. Most implementations paper over that with a fractional-delay filter. I left it showing, because a model that tells you where it breaks is more interesting than one that pretends it doesn't. And then there's blend — Karplus and Strong's own parameter, where you randomly flip the sign of the fed-back sample. Nudge it down and the same six lines of code stop being a guitar and start being a snare drum.
Something you might take away
The pluck isn't where the note comes from. A burst of noise already contains every frequency at once — the loop doesn't create the pitch, it just decides which parts of the noise are allowed to keep coming back. Everything that isn't a whole-number multiple of "once around the buffer" cancels itself out within a few trips, and what's left is a harmonic series. I find that a useful way to look at things that seem to have a strong character: often nothing generated that character on purpose. Something noisy was fed through something forgetful, over and over, and what survived was the shape.