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 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?
What's the difference between a synthesizer and a regular electronic keyboard?
Does additive synthesis actually work for realistic piano emulation, or does it hit a ceiling?
Why does floating point precision cause audio problems, and how do programmers fix it?
Why do synthesizer notes use exponential frequency ratios instead of just adding hertz between each step?
Based on viewer questions and search trends. These answers reflect our editorial analysis. We may be wrong.
Source: Based on a video by Sebastian Lague — Watch 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.



