This page produces sound. Lower your system volume before pressing play, especially if you are using headphones. Every play button on this page requires a click before any audio is created, so nothing autoplays.

Essay, 2026

How a synthesizer actually works.

A synthesizer is one of the cleanest pieces of applied mathematics in everyday consumer electronics. It is also one of the most rewarding to build. This essay starts with a single pure tone and ends with a playable polyphonic instrument, with the spectrum visible at every step. The whole engine runs on the Web Audio API, in this browser tab, with no samples and no libraries.

Reading time about twenty minutes. Five interactive figures, all gated behind explicit play buttons. Keyboard, screen reader, and reduced motion supported.

Begin reading

Part one

A pure tone.

The simplest sound is a sine wave. Air pressure at the listener's ear varies as p(t) = A sin(2πft), where f is the frequency in hertz and A is the amplitude. A frequency of 440 hertz is the A above middle C, which is the standard tuning reference. Doubling the frequency raises the pitch by one octave. The ear hears that doubling as the same note, an octave higher, because the two waves repeat against each other in a clean integer ratio.

The figure below produces a single sine wave through the Web Audio API. The top canvas shows the waveform in time. The bottom canvas shows the spectrum in frequency, measured by a 2048 point fast Fourier transform. The first thing to notice about the spectrum is that a pure sine has a single spike at its frequency and nothing else. That property is what makes it the building block of everything that follows.

Figure 1. One oscillator, one frequency.

Waveform · time domain

A live time-domain plot of the oscillator output. With a pure sine wave it appears as smooth repeating curves.

Spectrum · frequency domain

A live spectrum analyser. A pure sine wave shows a single peak at its fundamental frequency.

Two practical observations. First, very low frequencies, below about 30 hertz, are felt rather than heard, and your speakers probably cannot reproduce them well. Second, the perceptual loudness scales logarithmically with amplitude, which is why audio engineers measure level in decibels. The slider in this figure is linear in amplitude, which is the natural unit for the mathematics but the unintuitive unit for the ear.

Part two

Adding harmonics.

Real instruments do not produce pure sines. A bowed violin string vibrates not only at its fundamental but at every integer multiple of that fundamental, each with its own amplitude. The same is true of a clarinet, a trumpet, and a human voice. The set of these integer multiples is called the harmonic series, and the amplitudes of the harmonics are most of what determines the timbre of an instrument.

Joseph Fourier proved in 1807 that any periodic function can be written as a sum of sines and cosines of integer frequencies. This is the Fourier series. The figure below lets you build a periodic waveform by hand, harmonic by harmonic, up to the eighth partial. The two presets show two classical results. A square wave is a sum of only odd harmonics with amplitudes 1/n. A sawtooth wave is a sum of all harmonics with amplitudes 1/n. The shapes you remember from oscilloscopes fall out as soon as you assemble those coefficients.

Figure 2. Additive synthesis.

Waveform

Spectrum

The visual identity between the picked harmonic amplitudes and the spectrum peaks is the point of the figure. The frequency domain is not an abstraction layered over the waveform. It is the same data described differently. Fourier's theorem is what allows you to choose either representation depending on which one makes your work easier.

Part three

An envelope.

A real note has a beginning, a middle, and an end. A plucked string has a fast attack and a long decay. A bowed string can be held indefinitely. A piano lies in between, with a fast attack and a sustained body that decays slowly. The mathematical structure that controls this shape over time is called an envelope, and the standard envelope used in commercial synthesizers has four parameters.

Attack is the time from key press until the note reaches full volume. Decay is the time from full volume to a steady sustain level. Sustain is that steady level, expressed as a fraction of full volume, held for as long as the key is held. Release is the time after key up for the note to decay to silence. The figure below draws the envelope as you adjust the four sliders, and lets you trigger a single note through that envelope so you can hear what each parameter does to the same waveform.

Figure 3. The ADSR envelope.

Envelope shape

A plot of amplitude against time showing the attack, decay, sustain, and release segments of the envelope.

Spectrum during last note

Part four

Filters.

If additive synthesis builds a tone up from nothing, subtractive synthesis carves a complex tone down. The instrument is the filter. A filter is a two pole, two zero biquad function applied to the signal, controlled by a cutoff frequency and a resonance value, conventionally called Q. A low pass filter passes frequencies below the cutoff and attenuates those above it. A high pass filter is the mirror. A band pass passes a window around the cutoff.

The figure below routes a sawtooth oscillator, which is rich in harmonics, through a biquad filter, and plots the filter's transfer function as a Bode plot. The transfer function tells you exactly which frequencies the filter passes and which it attenuates. Sweep the cutoff and listen to the timbre change. Raise Q and the filter rings at the cutoff, the resonance peak you can both see in the plot and hear in the sound.

Figure 4. A biquad filter.

Bode plot · filter response

A plot of the filter gain in decibels against frequency on a logarithmic axis. Resonance appears as a peak at the cutoff.

Spectrum · filtered output

Part five

A playable instrument.

The pieces from the four previous parts assemble into a real instrument. The oscillator is the harmonic recipe from part two, configurable. The envelope is the ADSR from part three. The filter is the biquad from part four. The keyboard below is two octaves of piano, addressable by the mouse, by touch, and by the home row of the computer keyboard. The mapping follows the convention of trackers and digital audio workstations: a is the lowest C, w is the C sharp above, s is D, and so on. Multiple keys held simultaneously play a chord.

For screen reader users, the keyboard renders as a single composite widget with roving tabindex. Left and right arrow keys move chromatically. Home and end jump to the first and last key. The Hold toggle latches notes on, so a chord can be built one note at a time without needing to hold three keyboard keys down simultaneously.

Figure 5. A polyphonic synthesizer.

Use Left and Right arrow keys to move chromatically once focused on the keyboard. Press Space or Enter to trigger the focused key. Home and End jump to the lowest and highest key.

Press a key on the screen or on the computer keyboard to play.

The chain at this point is short. Each pressed key creates a new voice. The voice contains an oscillator at the right frequency, mixed against its harmonics, run through a shared filter, gated by an ADSR. When the key is released the voice's release phase begins, the voice's amplitude smoothly approaches zero, and the voice is destroyed. There is no sample, no model, no machine learning. A few hundred lines of arithmetic and a graph of audio nodes are enough to play music.

Colophon

All audio runs on the Web Audio API. Oscillators use the built-in OscillatorNode for the standard waveforms, and a PeriodicWave constructed from harmonic coefficients for the additive figure. Spectra are computed by AnalyserNode at 2048 points and rendered to a canvas. The biquad in part four uses BiquadFilterNode. All gain envelopes are applied through GainNode automation, scheduled with setValueAtTime and setTargetAtTime. The master volume in the page header is the final node in the graph.

Sources: Oppenheim and Schafer (2009), Discrete-Time Signal Processing, third edition, for the underlying theory. Smith (2007), Introduction to Digital Filters with Audio Applications, available online from CCRMA, on biquads. The Web Audio API specification at the W3C, for the implementation contract.

Built as a portfolio piece. The full source is on GitHub.