Coding a Guitar Sound in C - Computerphile

ComputerphileComputerphile
Education3 min read15 min video
Mar 5, 2026|38,364 views|2,539|214
Save to Pod

Key Moments

TL;DR

Nonlinear distortion shapes harmonics to color sound in code.

Key Insights

1

Distortion arises from nonlinear behavior in audio processing, creating harmonics that alter timbre and perceived bass.

2

Simple mathematical operations (e.g., squaring, cubing) generate specific harmonic patterns: even harmonics (2f, 4f) and odd harmonics (3f, 5f) in distinct ways.

3

Symmetry and sign handling affect the harmonic content: asymmetrical operations tend to push certain harmonics differently, while preserving or manipulating sign can reshape the spectrum.

4

Distortion can trick the brain to perceive bass on small speakers by adding harmonics that imply lower frequencies even when the fundamental is weak or absent.

5

Practical DSP techniques—clipping, squaring, square-rooting, and alternative power laws—paired with gates, delays, and EQ can build compact, musical effects with few lines of code.

LINEAR VS NONLINEAR BEHAVIOR IN AUDIO

The speaker illustrates a fundamental distinction in audio processing: linear systems respond predictably to changes in input, while nonlinear systems introduce distortions that generate new frequency content. The discussion leans on a real-world example using Formula VST, emphasizing that distortion—not just volume increase—changes how signals are molded as they pass through a device. Nonlinearities produce harmonics, which can color sound from pleasant warmth to aggressive grit. This concept underpins much of audio engineering and digital sound design.

HOW NONLINEARITIES CREATE HARMONICS

By demonstrating operations like input times input (squaring) and higher powers, the speaker shows how new frequencies emerge. Squaring a 1000 Hz tone yields a strong 2000 Hz component (the second harmonic) and, with further operations, introduces 3000 Hz (the third harmonic) and beyond. The visual aid of a harmonic analyzer helps explain why even powers tend to suppress the original fundamental while adding higher multiples. This wave shaping is the essence of many distortion effects.

EVEN VS ODD HARMONICS AND SYMMETRY

The talk distinguishes how even and odd harmonics behave under distortion. Squaring tends to generate even harmonics and can push energy away from the fundamental, sometimes creating an asymmetrical waveform. Conversely, manipulations that preserve symmetry or reintroduce the sign can alter which harmonics dominate. The speaker further demonstrates how manipulating sign can transform an asymmetrical distortion into a more symmetrical one, revealing how subtle coding choices shape the resulting timbre.

WAVE SHAPING EXPERIMENTS AND PRACTICAL OPERATIONS

Beyond squaring, the speaker experiments with other operations such as cubing and taking higher nth powers, showing how different mathematical manipulations craft distinct harmonic patterns. Additional techniques like clipping (hard-limiting the peaks) and even sqrt-based distortions yield very different tonal flavors. The demonstration connects these operations to practical outcomes: creating perceived bass, enhancing transients, or making drums and guitars sound more aggressive or polished depending on the chosen curve.

BUILDING A SIMPLE DISTORTION CHAIN IN CODE

The tutorial showcases a compact plugin chain implemented with a few lines of C code: distortion, a dry/wet mix, and a basic signal path, augmented by a gate, delay, and a bit of EQ. This serves as a concrete example of how developers can experiment locally to sculpt tone, push transients, and shape the spectral content. The speaker emphasizes that such minimal code can still yield surprisingly musical results, especially when paired with practical processing like gating and subtle EQ adjustments.

REAL-WORLD APPLICATIONS: DRUMS, GUITAR, AND PERCEPTION

The discussion applies these concepts to a guitar and a drum track, illustrating how distortion interacts with transients, harmonics, and room/frequency response. Drums with subtle distortion can gain punch, while guitars benefit from controlled clipping and delay. The speaker notes that real-world devices often rely on a mix of harmonic enrichment and transient control to achieve perceived loudness and bass response, sometimes leveraging harmonic content to compensate for speaker limitations on smaller systems.

Distortion Quick Reference Card

Practical takeaways from this episode

Do This

Start with a clean signal to observe how nonlinearity changes the spectrum.
Use a dry/wet mix to control the amount of distortion you hear.
Experiment with squaring, cubing, and higher powers to shape harmonic content.
Clipping is a simple, classic distortion; compare it with soft/clipped variants.
Add transient-focused processing (e.g., gentle delay or gate) to accompany distortion without overwhelming the signal.

Avoid This

Don’t over-distort; excessive distortion can mask the original signal and reduce intelligibility.
Don’t neglect transients and dynamic content when applying distortion.
Don’t rely on distortion to create real bass content on devices that can’t reproduce sub-bass.
Don’t assume the same harmonic effect will translate identically across all playback systems.

Common Questions

Nonlinear distortion occurs when the input-output relationship is not proportional, which generates new frequencies called harmonics. The video explains that nonlinearities in audio produce distortion and harmonics, which can be used creatively or sound unpleasant depending on how they’re applied. This is demonstrated through examples with simple signal manipulations in a plugin like Formula VST.

Topics

More from Computerphile

View all 11 summaries

Found this useful? Build your knowledge library

Get AI-powered summaries of any YouTube video, podcast, or article in seconds. Save them to your personal pods and access them anytime.

Try Summify free