Inside a music synthesizer built from scratch, there is no sound — only functions, evaluated 48,000 times per second. This is a tour of the mathematics that lives in one, written for people who like their trigonometric identities load-bearing.
Every design decision in a synthesizer answers to a single, slightly unreasonable client: the human auditory system. Before any engineering, two of its habits set the rules of the game.
First habit: the ear hears ratios, not differences. The musical interval between 110 Hz and 220 Hz sounds identical to the interval between 1,760 Hz and 3,520 Hz — both are “one octave,” a doubling. Pitch perception is logarithmic, so music divides the octave not into equal frequency steps but into equal ratio steps. Western music uses twelve of them, which makes the frequency of MIDI note n:
This exponential appears everywhere in the synth. When a player bends a note by s semitones, the engine multiplies frequency by 2s/12. When two oscillators are detuned by c cents (hundredths of a semitone), their ratio is 2c/1200. The filter’s cutoff knob sweeps exponentially, because a linear sweep would feel like it spends ten seconds in the treble and a millisecond in the bass.
Second habit: the ear performs harmonic analysis in hardware. The cochlea is a coiled, fluid-filled frequency analyzer: different positions along its basilar membrane resonate at different frequencies, so what the brain receives is not the pressure waveform itself but something close to its spectrum. Two waveforms that look wildly different on an oscilloscope can sound identical if their spectra match. This means the natural domain for thinking about timbre is not time — it is frequency. Which brings us directly to the patron saint of this whole project.
The engine at the heart of this synth is a wavetable oscillator: one period of a wave, stored as 2,048 numbers, read in a loop at whatever speed produces the desired pitch. Everything interesting about it is a corollary of Fourier’s theorem.
Any reasonable periodic function decomposes into a sum of sines at integer multiples of the fundamental:
Play with the recipe below. Adding harmonics one at a time, you can watch a pure sine sharpen into a sawtooth — the buzzy, brassy backbone of most electronic music. This is the Fourier series converging in front of you, Gibbs ripples and all.
A wavetable is simply this series, pre-summed and sampled: 2,048 points of one period. But the synth doesn’t store one wave — it stores a whole family of them, and lets the player morph continuously along the family while playing. Morphing is implemented as pointwise linear interpolation between neighboring family members — a homotopy between waveforms, heard as timbre in motion. The professional libraries this synth imports (from instruments like Serum) are exactly such families: 256 waveforms per file, each 2,048 samples, each one frame of a timbral animation.
Digital audio replaces a continuous pressure wave with a list of numbers — samples of the waveform taken 48,000 times per second. That this loses nothing is one of the great surprises of 20th-century mathematics.
The Nyquist–Shannon sampling theorem: a signal containing no frequencies above B is completely determined by samples taken at any rate above 2B. Not approximated — determined, exactly, via an interpolation formula built from sinc functions:
At the standard studio rate of 48,000 samples per second, everything below 24 kHz — comfortably past the edge of human hearing — survives the trip into numbers and back untouched. The catch is the hypothesis: no frequencies above B. Violate it and the theorem doesn’t merely degrade politely. It retaliates.
Sample a frequency above the Nyquist limit and it doesn’t disappear — it comes back wearing a disguise. The disguise is arithmetic modulo the sample rate.
A sampled sinusoid at frequency f is indistinguishable from one at f + k·fs for any integer k, because the samples land on identical values: sin(2π(f + k fs)(n/fs)) = sin(2π f n/fs + 2πkn). Every frequency therefore gets projected — folded — into the band below Nyquist, reflecting off the boundary like a billiard ball:
Why does a wavetable synth care? Because a sawtooth’s recipe is Ah = 1/h — harmonics forever. Play a stored sawtooth at a high pitch and its upper harmonics sail past Nyquist and fold back as inharmonic garbage: frequencies unrelated to the note, heard as a metallic sourness that no equalizer can remove. Naïve digital oscillators sound cheap for precisely this reason.
This synth’s solution is mip-mapping, borrowed in spirit from computer graphics. For each waveform, it precomputes a ladder of eleven band-limited versions: the full wave with 1,024 harmonics, then 512, then 256… down to a bare sine. The construction is pure Fourier surgery, done once at load time:
At play time, the engine computes how many harmonics fit under Nyquist for the current pitch (H = ⌊fs / 2f⌋) and reads from the rung of the ladder that fits — actually from a smooth blend of two adjacent rungs, so that a gliding pitch never audibly “switches.” The blend must lean on the safer rung: mixing in any table whose harmonics exceed Nyquist, even at 10% amplitude, reintroduces the crime.
A table holds 2,048 points, but a playing note needs the wave’s value at position 1371.640625. Interpolation — and the choice of interpolant is audible.
Nearest-neighbor lookup produces staircase error rich in high-frequency images. Linear interpolation — connecting the dots — is better, but its error spectrum still leaks audible ghost frequencies; in graphics you’d see it as jaggies, in audio you hear it as a faint fizz. This synth reads through a Catmull-Rom spline: the cubic through four neighboring points whose slope at each sample is the centered difference of its neighbors,
The payoff is in the error orders: linear interpolation’s error is O(h²), the cubic’s is O(h⁴) with smooth first derivatives — and its spectral images fall below the −100 dB alias floor the project enforces elsewhere. Numerical analysis, in service of not annoying the ear.
The most beloved control on any synthesizer — the filter cutoff — is a knob on a second-order ODE. Sweep it and you are continuously re-parameterizing a damped harmonic oscillator while it runs.
Analog synth filters were literal circuits: capacitors integrating currents. The canonical state-variable filter is, in continuous time, exactly the mass-spring-damper equation with the input as forcing:
One equation, three outputs for free: y is the low-pass, ÿ-side gives the high-pass, and ẏ the band-pass — which is why the synth offers all three modes from a single structure.
To run this on samples, the integrators become sums — this synth uses the trapezoidal rule, which in the signal world goes by bilinear transform. It has a beautiful geometric character: it is the Möbius map s = 2fs(z−1)/(z+1), which carries the entire imaginary axis of the analog frequency plane onto the unit circle of the digital one. Stability is preserved exactly (left half-plane → inside the disc), but frequency gets nonlinearly compressed near Nyquist. The distortion is known in closed form, so you cancel it in advance — pre-warping:
One more subtlety separates a textbook digital filter from a musical one. The trapezoidal integrator makes the filter’s feedback instantaneous — output depends on this very sample’s input. Naïve implementations insert a one-sample delay in the loop and drift out of tune at high cutoffs; the correct approach (called “zero-delay feedback” in the trade) solves the implicit equation algebraically, the same move as an implicit ODE solver. This synth’s filter is exact in that sense, which is why its resonance stays stable and in tune even while being violently modulated — there is a unit test that whips the cutoff across four octaves at audio rate and asserts the state stays bounded.
Here is the most surprising thing this project taught its author: the human ear can hear differentiability class. Not metaphorically — operationally, reproducibly, at levels far below what a waveform plot reveals.
Every note is shaped by an envelope: a function that fades the sound in at key-press and out at release. This synth’s envelopes are exponential approaches — the solution of ẏ = (target − y)/τ, computed as the recurrence y[n+1] = y[n] + k(target − y[n]) — one multiply-add per sample, the discrete shadow of an RC circuit.
Exponentials are lovely, but an ADSR envelope is piecewise exponential, and at each junction the derivative jumps. During development, listeners reported a faint tick at chord changes — yet the recorded waveform, zoomed to the sample level, showed no jump at all. The signal was continuous. Its slope was continuous. The bug was hiding one derivative deeper, and the instrument that found it was a bank of finite differences:
The repair is a classic from analysis: convolve the envelope with a smoothing kernel — a mollifier, in practice a 0.5-millisecond one-pole — which rounds every corner and lifts the output from C⁰ to effectively C∞ at the junctions. Applied to the control signal only, never the audio: at steady state the smoother is the identity, so timbre is untouched by construction.
To make a sound “growl,” synths deliberately push it through a nonlinearity. The one used here is tanh — a smooth soft-clipper. Nonlinearity manufactures new harmonics; new harmonics can exceed Nyquist; Section 4’s villain returns. The escape is one of the prettiest tricks in modern audio DSP, and it is essentially the Mean Value Theorem run in reverse.
The problem: applying tanh sample-by-sample is applying it to the sampled signal, and the distortion products fold. The insight (Parker et al., 2016 — “antiderivative anti-aliasing”): instead of evaluating the nonlinearity at each sample, output its average over the inter-sample interval. For that, you don’t need the signal between samples — the fundamental theorem of calculus hands it to you from the antiderivative alone:
When consecutive samples nearly coincide, the divided difference degenerates to 0/0 — and its limit, by the very definition of the derivative, is F′ = tanh at the midpoint. The code contains that limit as a branch. L’Hôpital, shipped to production.
The first implementation used 32-bit floats and developed a strange rasp at heavy drive — noise injected by the anti-noise stage. The diagnosis is textbook catastrophic cancellation: at a drive of +36 dB the inputs reach |x| ≈ 150, where F(x) ≈ 149.3 and a 32-bit float’s spacing (ULP) is 1.5×10⁻⁵. Subtracting two such values for a small Δx leaves almost pure rounding error, then the division amplifies it — up to 30% per sample. The same computation in 64-bit floats errs at one part in 10⁸. Two lines changed; a whole class of error extinguished.
The “supersaw” — the huge sound under most modern dance leads — is one note played by up to eight copies of the oscillator, each mistuned by a few cents. Everything you hear in it is interference.
Two sines detuned by δ obey the sum-to-product identity:
Spreading the copies across the stereo field uses constant-power panning: each copy’s left/right gains are (cos θ, sin θ) for a pan angle θ — so gL² + gR² = 1 identically, and loudness (which tracks power, not amplitude) is invariant as a copy sweeps across the image. The Pythagorean identity, employed as a conservation law.
Summing N copies raises a normalization question with a probabilistic answer. The copies start at random phases, so they add like independent random variables: amplitudes don’t sum — variances do, and the ensemble’s RMS grows as √N. The engine therefore divides by √(Σ aₖ²), keeping perceived loudness constant whether the choir has one voice or eight. (A subtle bug lived here once: with an even number of copies, the “center” weight was handed to one off-center copy, tilting the stereo image 2.5 dB leftward and biasing the ensemble’s mean pitch flat. Symmetry restored it: even choirs now split the center weight between the two middle voices.)
Reverberation — the sound of a room — is a linear operator with an enormous, decaying impulse response. Simulating it honestly would convolve every sample with a few seconds of response. The classic alternative, running in this synth, builds a room from feedback loops and a small miracle of complex analysis.
The atom is the feedback comb filter: a delay line of D samples feeding back with gain g. One impulse in, a geometric series out — echoes at spacing D, amplitudes g, g², g³… Exponential decay for free; the “room size” knob simply sets g. Its frequency response, though, is a picket fence — resonances at every multiple of fs/D — so one comb sounds like singing into a pipe. The design (Schroeder, 1962; refined as “Freeverb”) runs eight combs in parallel with carefully chosen, near-coprime delay lengths (1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 samples), so their resonance fences almost never align — the sum’s response is dense and roomlike. Number theory, deployed against flutter echo.
Then the miracle: the parallel combs feed four allpass filters in series,
An operator that is audibly “transparent” in the frequency domain yet dramatically active in the time domain — students meet allpass filters and assume they do nothing. Rooms are built out of them.
The synth’s display shows a live spectrum — a Fourier transform of the last thousand samples, recomputed dozens of times per second. Doing this honestly means negotiating with an uncertainty principle.
The discrete Fourier transform of a finite window is really the transform of the signal times the window — and by the convolution theorem, the spectrum you see is the true spectrum smeared by the window’s own transform. A rectangular window has vicious sidelobes (−13 dB): energy from one loud partial “leaks” across the whole display. The synth uses a Hann window, w[n] = ½(1 − cos 2πn/N), trading a slightly wider main lobe for sidelobes at −31 dB and falling fast.
Underneath sits the real constraint, formally identical to Heisenberg’s:
The same discipline shapes the project’s test suite: test tones are chosen to land exactly on FFT bins (frequencies of the form k·fs/N), so harmonics occupy single bins and any energy elsewhere is provably artifact. Measurement theory first; assertions second. The whole quality story of this synth — the −100 dB alias floors, the click taxonomy, the cancellation hunt — rests on knowing what the measuring instrument itself distorts.
Zoom out, and one note on this synthesizer is a stack of mathematics executing in real time.
Press a key: an exponential map turns note number into frequency. Eleven Fourier projections stand ready so the harmonic series never crosses Nyquist. A C¹ cubic reads between samples. A trapezoidally-integrated second-order ODE colors the tone, its cutoff pre-warped through a Möbius map’s tangent. The Mean Value Theorem averages a hyperbolic tangent so distortion can’t fold. Mollified exponentials shape the loudness so no derivative jumps loudly enough to hear. Sum-to-product identities shimmer the choir; the Pythagorean identity conserves its power; √N normalizes its loudness. Near-coprime geometric series build the room, and flat-magnitude Möbius atoms densify it. All of it, per sample, forty-eight thousand times a second, with a hard real-time deadline and no permission to allocate memory or throw an error — because a single missed deadline is itself a Δ¹ discontinuity, and Section 7 explains exactly how that sounds.
The part that might please a mathematician most: almost every bug worth telling a story about was found not by reading code but by measurement against theory — an FFT that knew where harmonics must lie, a finite difference that knew what smoothness requires, a floating-point model that knew where subtraction goes to die. The theory did not decorate the engineering. It was the debugger.