Signal and Sensation

The Click Is Not the Note

A pure 55 Hz sine has one frequency in it, and it still clicks when the note starts. How much depends on where the wave was at that instant, by 19 dB. The click is the envelope, and the attack is a filter on it.

Open fullscreen →

What it is

A sub bass line made of nothing but sine waves, at 55 Hz and below. There is exactly one frequency in each note and nothing above it.

It clicks. Every note starts with a tick that has no business being there, and the spectrum along the bottom shows it: energy at 300 Hz, at 1 kHz, at 3 kHz, from a note with none of those in it. Switch the start point and the click changes by 19 dB. Add a few milliseconds of attack and it goes.

The click isn’t the oscillator. It’s the envelope, the switch that turns the note on, and this part of the series is about what that switch does to the sound.

How it works

Turning a sine on instantly is multiplying it by a step, and a step has energy at every frequency. So does the note, from that moment, however pure the oscillator is. The attack control on an envelope replaces the step with a ramp, and a ramp of length T has a spectrum that’s the step’s with nulls cut into it at every multiple of 1/T. The attack is a lowpass filter on the click, and its first null is at one over the attack time.

Everything on screen is measured off a rendered note rather than drawn from that formula. The bars are the note’s spectrum at forty four frequencies from 100 Hz to 6 kHz, read out with a Goertzel filter, and the dashed line behind them is the same note switched on hard at the zero crossing, the quietest start there is.

The measurement that checks the formula divides the spectrum of a ramped note by the spectrum of a hard switched one. The sustained sine cancels out, being identical in both, and what is left is what the ramp did to the click. Against the maths, with both shifted copies of the envelope’s spectrum included, the worst disagreement over 100 to 4000 Hz is 0.002. The first null lands at 2004 Hz for a 0.5 ms attack, 1006 Hz for 1 ms and 515 Hz for 2 ms, against 2000, 1000 and 500.

The sound is the same nodes the page draws from. A fresh oscillator per note starts at the zero crossing, a cosine wave starts it at the peak, and the gain ramps linearly for the attack. Rendered offline and measured, the real Web Audio note agrees with the maths to 0.1 dB in every case I tried.

What surprised me

I went in to measure the null and came out with a different finding, which is that a pure sine clicks by an amount set by where the wave happened to be when the note started.

Started at the zero crossing, the note begins at zero, so there is no step in value, only in slope, and the click falls away at 40 dB a decade. Started at the peak there is a full step and it falls at 20. That’s a factor of ten in amplitude for every factor of ten in frequency, and above 300 Hz it adds up to a click 18.9 dB louder from the same note with the same envelope. Any start phase that isn’t a zero crossing gives the 20 dB slope. The zero crossing is the special case, not the peak.

That’s the actual reason a synth’s click varies from note to note. A free running oscillator gated by an envelope starts wherever it happens to be, so some notes start near a crossing and barely click and some start near a peak and knock, and the difference is 19 dB with nothing changed. Synths with an oscillator reset option are fixing exactly this.

The attack ramp then behaves differently depending on which of those you have. From a peak start it does what the formula says, and quickly: the click above 300 Hz drops 4.8 dB at 1 ms, 12 dB at 2 ms, 22.5 dB at 5 ms. From a zero crossing start there is barely a click to remove, and a short ramp puts a second kink in at the end of the attack that wasn’t there before. It gets slightly worse before it gets better, up 3.3 dB at 1 ms, and only pulls ahead past 5 ms.

The other thing I got wrong first was the theory. The spectrum of an enveloped sine is the envelope’s spectrum shifted onto the note, once each side, and at 55 Hz the two copies overlap for everything above a few hundred hertz. My first version kept only one and disagreed with the measurement by a few per cent everywhere. Keeping both closed the gap to 0.002, and it is the interference between the two copies that makes the start phase matter in the first place.

What I would do next

Part four is detune, two of the saws from part one against each other, and it’s the Reese.

The obvious extension here is the release. The note ending is a switch as well, and an exponential release has no corner at all, so it should have no click and no nulls, and that is a measurement I haven’t made. Nor have I measured the real thing this is about, an 808, whose click is partly this and partly a deliberate transient that producers layer in on purpose. Separating the two on a real sample would say how much of a knock is the envelope.