Tech

How to Build a Synthesizer From Scratch: Sebastian Lague's Guide

Tyler HoekstraSenior tech journalist covering AI, software, and digital trends4 min readUpdated April 11, 2026
How to Build a Synthesizer From Scratch: Sebastian Lague's Guide

Key Takeaways

  • Sebastian Lague built a working software synthesizer from scratch and documented every technical decision along the way in his video 'I Tried Coding My Own Synthesizer.' The project covers the full stack of audio programming problems — floating point drift, amplitude envelopes, logarithmic pitch scaling, harmonic layering, and MIDI integration — making it one of the more complete practical walkthroughs on how to build a synthesizer from scratch.
  • What starts as a sine wave generator eventually becomes a convincing piano emulator, with honest acknowledgment of where additive synthesis hits its ceiling.

Building a Synthesizer From Scratch: The Fundamentals

If you've ever wondered how to build a synthesizer from scratch at the code level, Sebastian Lague's project is a rare look at what that actually involves — not the theory, but the specific decisions that either make or break the audio output. He documents the full process in I Tried Coding My Own Synthesizer, covering everything from basic tone generation to polyphony.

The starting point is an audio buffer, a Note class to track active tones, and a sine wave function. Simple enough on paper.

Generating Basic Tones With Sine Waves

Sine waves are the atomic unit of audio synthesis. Every tone the synthesizer produces starts as a single sine wave defined by frequency and amplitude — frequency sets the pitch, amplitude sets the volume.

To visualize what's coming out, Lague uses a spectrogram analysis tool that plots frequency against time, making it far easier to diagnose problems than trying to hear them.

Handling Floating Point Precision in Long Audio Sequences

Here's a problem that doesn't show up in tutorials: if you calculate the current wave position by continuously accumulating elapsed time, floating point rounding errors stack up. Over a long session, you get audible distortion — the kind that makes you think your speakers are dying.

The fix is to track wave phase directly and reset it periodically, rather than letting a time variable grow without bound. It's a small change with a disproportionately large impact on sound quality.

Creating Natural Sound With Amplitude Envelopes

A pure sine wave at constant amplitude sounds like a fire alarm. Real instruments don't work that way — they have a characteristic shape to how they get loud and quiet, and that shape is what makes them sound like themselves.

Attack, Decay, and Release Curves for Realistic Tones

Lague implements the standard ADSR skeleton — attack (how fast the sound rises), decay (how fast it falls to its sustain level), and release (how fast it fades after the key is lifted). Linear ramps across those phases are a start, but they sound mechanical.

The more interesting move is building a custom Bezier curve editor to shape each phase. Instead of a straight line from zero to full amplitude, you get a curve you can actually tune. For performance, the curves get pre-discretized into lookup tables so the audio thread isn't doing expensive math per sample.

Making Your Synthesizer Musical: Logarithmic Frequency Ratios

Human pitch perception is logarithmic, not linear. Stepping through notes by adding a fixed number of hertz each time produces intervals that feel inconsistent — wide at the bottom, narrow at the top.

The correct approach is multiplicative: each semitep is a fixed ratio (the twelfth root of 2, roughly 1.0595). Switching from linear increments to exponential ratios is the difference between a scale that sounds wrong and one that sounds like music. This is the same math underpinning every Digital Audio Workstation on the market.

Audio Compression and Managing Multiple Notes

Play two notes simultaneously and the output amplitudes add together. Play a full chord and you're potentially clipping — the signal exceeds the maximum representable value and distorts hard.

Lague drops in an audio compressor to handle this: when the combined signal gets too loud, the compressor pulls the overall level down proportionally. It's not glamorous, but without it polyphony is unusable. The kind of engineering decision that never makes the highlight reel but breaks everything if you skip it.

Our AnalysisTyler Hoekstra, Senior tech journalist covering AI, software, and digital trends

Our Analysis: Lague gets the hard parts right — floating point drift and logarithmic pitch perception trip up a lot of first-timers, and he addresses both cleanly. The additive synthesis ceiling he hits is real: stacking sine waves gets you 80% of the way to a convincing piano, then fights you the rest of the way.

This fits neatly into a growing DIY audio programming wave, where developers are rebuilding tools from scratch instead of reaching for a library.

Procedural audio — generating sound dynamically from game or simulation state — is where this skillset gets genuinely interesting next.

Frequently Asked Questions

How do you build a synthesizer from scratch in code — where do you actually start?
The practical entry point is an audio buffer, a data structure to track active notes, and a sine wave generator — that's the minimum viable synthesizer. What Lague's project makes clear is that the hard part isn't generating a tone; it's everything that breaks when you try to make that tone sound like music rather than a test signal.
What's the difference between a synthesizer and a regular electronic keyboard?
A keyboard is essentially a controller and a sound module in one box, playing back pre-recorded or sampled sounds triggered by key presses. A synthesizer generates sound mathematically from oscillators and signal processors — which is exactly what Lague is building when he starts from a sine wave and layers envelopes and harmonics on top of it. The line blurs with modern instruments, but the distinction matters at the engineering level.
Does additive synthesis actually work for realistic piano emulation, or does it hit a ceiling?
It works up to a point, and Lague is honest that it hits a ceiling — which is worth crediting. Additive synthesis can approximate a piano's harmonic content reasonably well, but real piano tone involves inharmonicity, string resonance, and velocity-dependent timbre that pure harmonic layering can't fully replicate. For a convincing piano emulator from scratch, this approach gets you further than most tutorials suggest, but it's not a replacement for physical modeling or high-quality samples.
Why does floating point precision cause audio problems, and how do programmers fix it?
When you accumulate elapsed time as a running total to calculate wave position, tiny rounding errors in floating point arithmetic compound across thousands of audio samples — eventually causing audible distortion that's easy to mistake for a hardware fault. The standard fix, which Lague applies, is tracking wave phase directly and resetting it at cycle boundaries so the error never accumulates. It's a well-established technique in audio programming, not a novel discovery, but it's rarely explained clearly in beginner-facing resources.
Why do synthesizer notes use exponential frequency ratios instead of just adding hertz between each step?
Human pitch perception is logarithmic — each octave doubles the frequency, so equal-sounding intervals require equal multiplication factors, not equal additions. The specific ratio used is the twelfth root of 2 (approximately 1.0595), applied once per semitone, and this is the same math used in every Digital Audio Workstation on the market. Linear frequency stepping produces a scale that sounds increasingly compressed in the upper register, which most listeners will notice even if they can't identify why.

Based on viewer questions and search trends. These answers reflect our editorial analysis. We may be wrong.

✓ Editorially reviewed & refined — This article was revised to meet our editorial standards.

Source: Based on a video by Sebastian LagueWatch original video

This article was created by NoTime2Watch's editorial team using AI-assisted research. All content includes substantial original analysis and is reviewed for accuracy before publication.