Stack Sines, Get a Saw
A sawtooth is not a thing a synth has, it is a stack of sine waves each 1/n as loud as the first. Build it one sine at a time and listen to it turn into the sound every bass patch starts from.
What it is
A sawtooth, built one sine wave at a time, with the sound on.
Start with a single sine at 110 Hz, which is a pure tone and not much use for anything. Add another at twice the pitch and half the volume. Then a third at three times the pitch and a third of the volume, and keep going. By about sixteen you can hear it’s a saw, and by sixty four it’s the buzzy thing every bass patch in the world starts from.
Nothing was switched. The same oscillator is playing throughout, it just has more sines in it.
This is part one of ten, and the reason it comes first is that everything else in the series is about taking these sines away again, or moving them about. A filter isn’t a mysterious box, it’s a thing that turns down the ones near the top.
How it works
Which sines, and how loud, is the whole recipe.
A saw uses every multiple of the pitch, each one 1/n as loud as the first. A square uses only the odd ones, also at 1/n, and that missing every-other is exactly why it sounds hollow rather than bright. A triangle uses the odd ones at 1/n squared, which falls away so fast that by the ninth harmonic there is almost nothing left, and that’s why a triangle sounds nearly like a sine.
The page plays it as one oscillator with a custom periodic wave rather than as sixty four oscillators, because a periodic wave is precisely this sum. The bars along the bottom are the recipe, and the trace above them is what the recipe produces.
Every number on screen is measured off the rendered samples rather than assumed. The harmonic amplitudes come back out with a Goertzel filter, and they land on 1/n to three decimals. Brightness is the spectral centroid, which is the measurable version of a word producers use constantly and rarely define: one sine sits at 110 Hz, sixty four sines sit at 287 Hz, same note.
What surprised me
The stack never gets the corner right, and adding sines doesn’t help.
I expected the usual story, where more terms means closer, and eventually close enough. That is true everywhere except at the jump. Right at the corner the sum shoots past the shape it is drawing, and the size of that overshoot doesn’t shrink:
| sines | over the jump | off the shape overall |
|---|---|---|
| 8 | 3.3% | 0.268 |
| 32 | 7.4% | 0.139 |
| 64 | 8.2% | 0.103 |
| 512 | 8.9% | 0.080 |
The right hand column is doing what you would expect, falling steadily towards nothing. The middle one is going the wrong way. It climbs towards 8.9% of the jump and stays there, and at 512 sines it has essentially arrived. Eight times the sines bought under two per cent of change.
What actually happens is that the overshoot gets narrower rather than shorter. It squeezes in towards the corner and keeps its height, so the area under it goes to nothing while the peak does not. That’s why the error column and the overshoot column can disagree: the sum converges in the average and never converges at the point.
This is Gibbs, and it isn’t a bug in my arithmetic. A square does exactly the same thing, to the same 8.949%, because it has the same kind of jump. A triangle doesn’t do it at all, and measures 0.998, because a triangle has no jump in it to overshoot. Three shapes, one rule, which is the sort of agreement that makes me believe a measurement.
I also had it wrong twice before I had it right, both times in the instrument rather than the maths. My first version compared the stack against a unit ramp, which made every stack look pi times too big, because the sum of sin(n0)/n adds up to a ramp of height pi over two rather than one. My second measured the overshoot in the audio samples, and by 256 sines the overshoot sits closer to the corner than one sample at 48 kHz, so I was measuring the sample spacing. It’s evaluated on its own fine grid now.
The last thing is a naming trap worth knowing. Everyone quotes Gibbs as nine per cent, and against the peak of the wave it’s eighteen. Both are right. Nine is a fraction of the jump, eighteen is a fraction of the peak, and the jump is twice the peak. The page reports the first because that’s the convention.
What I would do next
Part two is the filter, and it starts exactly here: take the stack and turn down everything above a line, and measure where that line actually falls against where the dial says. The resonance measurement from day 74 drops straight in.
The thing I want to build to eventually is the Reese, which is two of these saws detuned against each other. It’s nothing but this day plus a second oscillator, and it’s the whole foundation of jungle. Getting from here to there is what the rest of the series is for.
I would also like to make the aliasing audible. A saw built from sines can never alias, because every sine is placed deliberately below the ceiling. A saw drawn as a ramp aliases badly, and the difference between those two is the reason band limited oscillators exist at all. Same shape on screen, very different sound, and the gap between them is measurable.