Wacky Knobs

← Lab / Understanding audio DSP code, sorry it’s only math :)

· 10 min read

Reverb in code: comb filters, allpass and RT60

← Filters in code

When you clap in an empty hall you do not hear one echo but thousands. The sound bounces off the walls, the floor, the ceiling and every object, and each reflected wave reaches you a little later and a little quieter. A reverb pedal builds that from parts you already know: a delay with feedback and filters. Here is the version Manfred Schroeder described back in 1962, in the form known as Freeverb. The first digital reverb units and many of today’s pedals are built on the same idea.

What happens in a room

The sound in a room has three parts. First the direct sound arrives, straight from the amp to the ear. A few tens of milliseconds later the first echoes arrive, from the nearest walls. They are sparse and can be told apart. Then the echoes multiply, because each one keeps bouncing, and soon there are so many that they melt into a tail that slowly dies away.

Two numbers describe a room best. PRE-DELAY is the time between the direct sound and the first echoes. The farther the walls, the longer it is, so the ear uses it to guess how big the space is. RT60 is the time it takes the tail to drop 60 dB, roughly from loud to barely audible. In a room that is about half a second, in a concert hall two, and in a cathedral as much as eight. It is the DECAY knob on every reverb pedal.

The comb filter: one wall

The delay with feedback from the first article is already a small reverb. The sound goes round and comes back a little quieter each time, like a ball bouncing between two walls. For a room that is not enough, because the echoes come back at perfectly regular intervals. With a short delay that sounds like a metallic flutter, and in the spectrum it makes a comb of peaks, the same comb filter as in the flanger. That is why this block is called a comb filter.

Schroeder’s trick is to use several comb filters at once, with different lengths, and add up their outputs. Freeverb has eight, from 25 to 37 ms long. The lengths are chosen so that their echoes almost never line up. One comb gives a regular train of echoes; eight together give a pile of echoes that seems random. That is how a room works too: every wall is at its own distance.

The allpass: smearing the echoes

Eight comb filters give plenty of echoes, but still not dense enough. On a short sound, like a click or a palm mute, you still hear a grainy, metallic tail. That is why four allpass filters follow, in series.

An allpass is a strange filter. It passes every frequency equally loud, so its response is a flat line and it does not change the tone. But it smears the sound through time: it turns one click into a train of quickly fading echoes. With four of them in a row, every echo from the combs falls apart into dozens of smaller ones. Within a few tens of milliseconds the tail is so dense that the ear no longer hears single echoes, only “space”.

What to try in the simulator

  • Click. Play “Click” and watch the top picture: after the pre-delay a few sparse echoes come first, then more and more. That is all a reverb does.
  • No allpass. “No allpass (metallic)” turns the diffusion off. The tail gets sparse and flutters. Switch ALLPASS on and it is smooth at once.
  • DECAY. Turn DECAY and watch the bottom picture: the curve always crosses −60 dB right at the time you set.
  • DAMP. On “Chord”, compare “Plate (bright)” and “Cathedral”. The plate has little DAMP and its tail is bright and hissy. In the cathedral the highs die fast, so the tail is dark and soft.
  • Pre-delay. “Long pre-delay” on the riff: the note stays clean and the space opens up only after it. That is why singers and guitarists like 20 to 60 ms of pre-delay: the sound stays up front instead of drowning in the tail.
  • Stereo. Put on headphones. The right channel’s lines are 23 samples longer, so the echoes on the left and right differ and the sound is wide.

DECAY: how much feedback for how many seconds

Each comb filter has its own feedback g. Over one round of COMB[i] samples the echo gets g times quieter. To drop by 60 dB, that is 1000 times, in DECAY_S seconds, it has to be:

g = 10^(−3 × COMB[i] / (DECAY_S × sampleRate))

A shorter comb makes more rounds per second, so it gets a slightly bigger g. A longer one makes fewer rounds, so it gets a smaller one. That way all eight die away at the same speed and the tail does not change color as it fades. (The original Freeverb gives them all the same g, so instead of DECAY in seconds it has a ROOM SIZE knob.) For a DECAY of 2 s and the longest comb, g is about 0.88. For 10 s it is 0.975. The closer to 1, the longer the tail. At 1 or more it would grow forever, just like the feedback in a delay.

DAMP: air and curtains swallow the highs

In a real room high frequencies die faster than low ones. The air absorbs them, and curtains, people and furniture even more. That is why a big hall has a dark tail, while a small room with bare walls sounds harsh. In code this is done by the same one-pole lowpass as the smoothing in the tremolo, only placed inside the loop of every comb. So the highs lose a little more on every round. After ten rounds much less of them is left than of the bass.

The code, line by line

  1. Feedback from DECAY. Eight numbers g[i], from the formula above. They are worked out only when a knob moves.
  2. Pre-delay. A plain delay without feedback, as in the first article. The input is also turned down, because the outputs of the eight combs add up.
  3. Comb filters. Each reads what comes back to it (y), passes it through the lowpass (DAMP) and writes back the input plus the quieter echo. All eight outputs are added up in s.
  4. Allpass filters. Four, one after the other, with a fixed feedback of 0.5. They do not change the tone, they only smear the echoes.
  5. MIX. The dry signal plus the reverb. The right channel does the same with slightly longer lines.

And inside a pedal?

Reverb is the effect that needs the most memory. This one, in stereo and with a 120 ms pre-delay, holds about 33,500 samples, roughly 130 KB of float numbers. That fits easily in an STM32H7. The Spin FV-1 has 32,768 samples of memory, about one second, and was made precisely for reverb. Keith Barr designed it after years of work on Alesis reverb units, and that is why it is in so many affordable reverb pedals.

What you hear here is the classic reverb of the seventies and eighties. Today’s high-end pedals (Strymon, Eventide, Meris) use more advanced networks (a feedback delay network). There the echoes from all the lines mix with each other, and the line lengths drift slowly with an LFO, as in the chorus, so the tail does not sound “frozen”. Shimmer adds a pitch shifter in the loop, so the tail climbs an octave. A convolution reverb makes no echoes at all; it multiplies the sound by a recorded response of a real hall. That sounds the most natural, but it takes a lot of computing.

The spring reverb in a Fender amp and the plate reverb in a studio are not algorithms but real springs and metal plates. Digital pedals simulate them, and the spring is the hardest: it has that “boing” because high and low frequencies travel through it at different speeds.

That covers the basic building blocks of digital effects: delay, modulation, volume, distortion, filters and reverb. Almost every digital pedal is some combination of these six. How such code runs on a real chip, with DMA and a double buffer, is in how it looks on real hardware.

More in Understanding audio DSP code, sorry it’s only math :)

← Lab