# 8-bit music: the NES, the Chipophone, and the sound of a pulse train
The finite pulse of [[Fourier Transforms]] and the pulse train that turns it into a tone are not a textbook example chosen for convenience. For a decade they were the sound of popular culture. A video-game console of the 1980s had no room for recorded music; what it had was a sound chip, a few hardware counters that switch a voltage on and off, and every melody anyone remembers from that era is a rectangular pulse train with a duty cycle. This page is the history of that sound, from the chip inside the Nintendo Entertainment System through an organ rebuilt to play it live, to the way musicians today make new music sound old, and the mathematics of the last two pages is what makes the story go.
## What is inside the NES
The Famicom (Japan, 1983) and the NES (North America, 1985) are built around the **Ricoh 2A03**, a chip that combines a MOS 6502 processor core (with its decimal mode disabled) and an **audio processing unit**, the APU. The APU runs off the CPU clock, $f_{\text{CPU}} = 1{,}789{,}773$ Hz, and it has five voices, each of them a small counter rather than anything resembling an instrument.
**Two pulse channels.** Each holds an 8-entry sequence of ones and zeros and steps through it at a rate set by an 11-bit timer $t$, one step every $2(t+1)$ CPU cycles, so one full cycle of the sequence every $16(t+1)$ cycles and a pitch of
$
f = \frac{f_{\text{CPU}}}{16\,(t+1)}, \qquad 0 \le t \le 2047 .
$
The four sequences the hardware offers, $01000000$, $01100000$, $01111000$ and $10011111$, are pulse trains with **duty** $d = \tfrac18, \tfrac14, \tfrac12, \tfrac34$: the fraction of each period the output spends *on*. The channel also has a 4-bit volume, sixteen levels from silence to full, and a sweep unit that slides the timer up or down automatically (the source of every 1980s laser and jump sound).
**A triangle channel.** Thirty-two steps through the 4-bit values $15, 14, \dots, 0, 0, 1, \dots, 15$, at one step per $t+1$ cycles, so an octave below a pulse channel with the same timer. It has no volume control at all, which is why it was nearly always the bass.
**A noise channel.** A 15-bit **linear-feedback shift register**: each clock, the register shifts right by one and the vacated top bit is filled with the XOR of bit 0 and bit 1. Started from $1$, that rule visits $2^{15} - 1 = 32767$ states before repeating, and the low bit of the register, read off as the output, is a pseudo-random bit stream. Clocked at one of sixteen rates (every 4 to 4068 CPU cycles) it is a hiss, a hi-hat, a snare. A mode flag moves the second tap to bit 6, and the period collapses to 93 (or 31) states, which turns the noise into a metallic buzz with a definite pitch; the applet below shows why.
**A sample channel.** The DMC plays 1-bit *delta* samples, a stream of up-or-down instructions driving a 7-bit counter, at a handful of fixed rates. It is a tiny amount of memory for a very crunchy drum, and the occasional sampled bass line.
Two more details make the sound of the machine. The five channels are not added: the chip's output stage is nonlinear,
$
\text{out} = \frac{95.88}{\dfrac{8128}{p_1 + p_2} + 100} + \frac{159.79}{\dfrac{1}{\dfrac{\text{tri}}{8227} + \dfrac{\text{noise}}{12241} + \dfrac{\text{dmc}}{22638}} + 100},
$
so a loud channel slightly *ducks* the others. And the music was written to a clock: a game updated its sound registers once per video frame, 60 times a second, so every change of pitch, volume or duty happens in steps of $1/60$ s. Both are part of what your ear has learned to call *8-bit*. (The PAL version of the chip, the 2A07, ran the same music from a 50 Hz frame and a slightly different clock, and games that were not adjusted came out slower and lower in pitch.)
### The pulse channel is our pulse train
Set $x$ to time and read the pulse channel as a function: on one period of length $T = 1/f$, it is $A$ for a stretch of length $dT$ and $0$ otherwise, with $A$ the 4-bit volume. That is the rectangular pulse of [[Fourier Transforms]] with half-width $L = dT/2$, repeated every $T$, and the pulse-train formula $c_n = \hat f(n\omega_0)/T$ with $\hat f(\omega) = 2AL\,\mathrm{sinc}(\omega L)$ gives the harmonic content immediately:
$
c_0 = A\,d, \qquad |c_n| = \frac{2A}{n\pi}\,\bigl|\sin(n\pi d)\bigr| \quad (n \ge 1).
$
The sinc envelope falls like $1/n$ (the pulse has jumps, so its coefficients cannot fall faster), and the zeros of the sinc land on the harmonics: $\sin(n\pi d) = 0$ exactly when $nd$ is an integer. The **square wave** ($d = \tfrac12$) is missing every even harmonic; the $d = \tfrac14$ pulse is missing every fourth; the $d = \tfrac18$ pulse every eighth. Those missing harmonics *are* the difference between the four tones the chip can make: the $\tfrac12$ wave is hollow and clarinet-like, the $\tfrac14$ is brighter and nasal, the $\tfrac18$ is thin and reedy, and $\tfrac34$ sounds exactly like $\tfrac14$, because $10011111$ is $01100000$ turned upside down and shifted, and neither operation changes $|c_n|$. Every NES composer knew these four voices by ear; the formula says why there are only three of them.
The triangle channel's Fourier series is the one from [[Fourier Series]], $|c_n| \propto 1/n^2$ on the odd harmonics, which is why it sounds so much softer than the pulses. But the chip's triangle is a staircase, and the corners of the steps put a little energy at harmonics near multiples of the step count, $n = 31, 33, 63, 65, \dots$, far above where the ideal triangle has anything. That is the faint buzz on top of every NES bass line, and it is the same phenomenon as **aliasing**: a waveform held constant for 32 steps per period is a sampled waveform, and sampling folds the spectrum back on itself.
## See it, hear it
<div class="applet" data-applet="chip-synth"></div>
The applet models one channel at a time exactly as the chip makes it. On the left is the waveform, held at each step for as long as the hardware holds it; on the right are the magnitudes $|c_n|$ of its Fourier coefficients, with the vanishing harmonics ringed. Things worth trying:
- **The four duties.** Play them in a row and watch the ringed harmonics move: every 2nd, every 4th, every 8th. Listen for $\tfrac34$ being the same tone as $\tfrac14$.
- **Tuning.** The pitch is $f_{\text{CPU}}/(16(t+1))$ for an integer $t$, so the chip cannot play 440 Hz; it plays $t = 253$, which is 440.40 Hz, 1.6 cents sharp. Slide the note upward and watch the error grow. Between $t$ and $t+1$ the pitch changes by $1200\log_2\!\bigl(1 + \tfrac{1}{t+1}\bigr) \approx 1731/(t+1)$ cents, about 7 cents at A4 but 33 cents at C7 ($t = 52$), a third of a semitone. That is one reason NES melodies rarely climb that high.
- **The envelope.** Volume changes in 4-bit steps, so a decaying note is a staircase in amplitude, sixteen levels down to silence. Play the channel *with a decaying envelope* and listen for the steps.
- **The triangle.** Compare the stair-step waveform with the ideal dashed triangle; the spectrum shows the $1/n^2$ decay of the odd harmonics and the small extra teeth near $n = 31$ and $33$.
- **Noise, both modes.** In mode 0 the register runs 32767 steps before repeating, the spectrum is flat and it sounds like noise. Switch to mode 1 and the same register repeats every 93 steps: the spectrum becomes a comb of harmonics at multiples of (clock rate)/93, and what you hear is a pitched, metallic tone. A "random" signal with a short period is not random at all; it is periodic, and the Fourier series says so.
- **The arpeggio.** With only two pulse channels there was no room for chords, so a chord was played as a very fast broken chord, one note per frame, 60 notes a second. Press *arpeggio chord* to hear the trick; it is the single most recognisable sound of the era, and it is the Chipophone's signature mode below.
- **The loop.** All four voices together: a melody on pulse 1 at $d = \tfrac14$, an arpeggiated chord on pulse 2 at $d = \tfrac18$, a bass on the triangle, a hi-hat and snare from the noise channel with the volume stepping down each hit. Nothing in it is a recording; it is a dozen seconds of counters.
## Composing inside the box
The constraints were the style. With two melodic voices, one bass and one noise, the composers of the 1980s built a vocabulary that is now instantly recognisable: pulse-width changes mid-note for timbre, a second pulse channel playing the melody a frame late and quieter for an echo, arpeggios standing in for chords, the sweep unit for percussion, and the noise channel switched between its long and short modes for kick and snare. Koji Kondo's scores for *Super Mario Bros.* (1985) and *The Legend of Zelda* (1986) and Hirokazu Tanaka's for *Metroid* (1986) and *Kid Icarus* were written this way, and so was a great deal of technically astonishing music by people like Tim Follin, whose *Silver Surfer* (1990) score runs arpeggios and echoes on every channel at once, and Sunsoft's Naoki Kodaka, whose *Journey to Silius* (1990) put its bass line on the sample channel. Japanese cartridges could add their own sound hardware, and some did: Konami's VRC6 gave *Akumajō Densetsu* (1989, the Japanese *Castlevania III*) two extra pulse channels and a sawtooth, Namco's 163 added wavetable voices, and Sunsoft's 5B carried *Gimmick!* (1992). The North American console did not mix cartridge audio in, so the US *Castlevania III* shipped without it.
The NES was not alone. The Commodore 64's SID chip (1982) had three voices with programmable waveforms and, unusually, an analog filter, and the C64 tradition of Rob Hubbard and Martin Galway runs parallel to the NES one. The Game Boy (1989) is nearly the NES with the pulse channels intact: the same four duty cycles, a 4-bit wave channel in place of the triangle, and the same kind of noise generator. It is the Game Boy, more than the NES, that carried this sound into the present.
## The Chipophone
In 2010 the Swedish programmer and musician **Linus Åkesson** took an old electronic organ, disconnected all of its original tone-generating circuitry, and wired its keyboards, pedals, knobs and switches to a pair of ATmega88 microcontrollers: one to read the organ as a MIDI controller, the other to be the synthesizer. The result, the **Chipophone**, is an 8-bit instrument you can sit down at and play. The synthesizer has eight waveform generators, each of them a pulse wave with a selectable duty cycle, a 4-bit triangle, or white noise, exactly the palette above, feeding a 12-bit line output, with ring modulation, an eight-step sequencer, and the essential chiptune feature, an **arpeggio mode**, in which keys pressed together are automatically cycled through as a fast broken chord, so that a single voice can carry a chord the way the NES did. When more arpeggios are called for than there are voices, the firmware merges the less important ones rather than dropping notes. The point of the machine is the reversal it performs: the sound of the NES was written by programmers typing register values into a table, and the Chipophone turns it back into something a musician plays with two hands and both feet, live. His write-up, with the video that made it famous, is at [linusakesson.net/chipophone](https://www.linusakesson.net/chipophone/).

## Retro today: chiptune and "fakebit"
The sound outlived the hardware, in two different ways. The first is **chiptune** as a scene: music made on the original chips, or faithful emulations of them, by people who choose the constraints on purpose. Its tools are trackers, spreadsheets of notes where each row is a frame: *Nanoloop* (1998) and *LSDJ* (2000) turn a Game Boy into a sequencer, and *FamiTracker* (2005) and its successor *FamiStudio* write real NES register data on a modern computer, which can then be played on a real console. The band Anamanaguchi mixes a NES with live guitars and drums and scored *Scott Pilgrim vs. the World: The Game* (2010); the 2007 compilation *8-Bit Operators*, chiptune covers of Kraftwerk, reached the top of the college electronic charts, and the 2014 game *Shovel Knight* had its entire score written in FamiTracker with the VRC6 expansion, three decades after that chip was new.
The second way is the one you hear everywhere now, from pop production to film scores to the ringtone aisle: music that was never near a console but is made to **sound** 8-bit. The scene sometimes calls it *fakebit* or *chipstyle*: a software synthesizer inside an ordinary digital audio workstation plays the part of the chip. The recipe is precisely the spectral fingerprint this page has been describing, and each of its ingredients is a Fourier statement:
1. **Pulse oscillators with no filter.** A plug-in like YMCK's *Magical 8bit Plug* offers duty cycles of $\tfrac18$, $\tfrac14$ and $\tfrac12$ and nothing else, and the raw sinc-with-holes spectrum is left alone. A filtered analog synthesizer sounds warm because its filter rounds off the $1/n$ tail; leaving the tail alone is what sounds *chip*.
2. **Stepped volume and stepped pitch.** Envelopes quantized to sixteen levels, vibrato that moves in discrete jumps, and changes only on a 60 Hz grid. Each step is a small discontinuity, and a discontinuity is broadband.
3. **Arpeggios instead of chords.** The 60-notes-a-second trick, now a menu item.
4. **A bitcrusher.** The one modern tool with no counterpart on the chip: it re-samples any sound at a low rate and rounds it to a few bits. Sampling folds the spectrum, as the stair-step triangle showed, so a smooth sound comes out with a comb of aliases; rounding to $b$ bits adds a staircase of error, and the error's spectrum is the rasp. A bitcrusher makes a violin sound like the NES triangle for exactly the reason the NES triangle sounds like a bitcrushed triangle.
None of this requires nostalgia to work, although nostalgia is why it sells. A pulse train with a $\tfrac14$ duty cycle is a fixed, sparse, recognisable pattern in frequency, and the ear is very good at recognising patterns in frequency. That is the whole reason a spectrum is worth computing.
## Where this connects
The chip is a physical realisation of the pulse train in [[Fourier Transforms]]: the duty cycle is $2L/T$, the volume is $A$, the harmonics are samples of Squiddy at $\omega = n\omega_0$, and the missing ones are Squiddy's roots. The triangle's staircase is the first appearance in this course of aliasing, which returns when we sample data. And the LFSR is a reminder that *random* is a claim about a spectrum: the same register, with one tap moved, goes from white noise to a note.
## The applets in code
Each applet reduced to the few lines that compute what it shows, in the four languages of the course. Fully working versions of these — with the checks against closed forms, the figures, and the sound written to WAV files — are kept in the `fourier-codes` repository (`python/`, `matlab/`, `r/`, `mathematica/`; one file per applet, named after it).
> [!example]- `chip-synth` — the NES pulse channel: duty $d$, 4-bit volume $A$, the timer-quantized pitch, $|c_n| = \tfrac{2A}{n\pi}|\sin(n\pi d)|$, and the sound
>
> > [!info]- Python
> > ```python
> > import numpy as np, matplotlib.pyplot as plt
> > CPU, d, A, midi = 1789773, 1/4, 12, 69 # NES clock, duty, 4-bit volume, the note
> > t = round(CPU / (16 * 440 * 2**((midi - 69) / 12)) - 1); f = CPU / (16 * (t + 1)) # the 11-bit timer, and the pitch it really makes
> > n = np.arange(41); c = np.where(n == 0, A * d, 2 * A * np.abs(np.sin(n * np.pi * d)) / (n * np.pi + (n == 0))) # |c_n|
> > seq = [0, 1, 1, 0, 0, 0, 0, 0] # the chip's 8-step sequence for d = 1/4
> > ts = np.arange(44100) / 44100; y = A * np.array(seq)[(ts * f * 8).astype(int) % 8] # one second of the pulse
> > plt.step(ts[:400] * 1000, y[:400], where="post"); plt.show(); plt.stem(n, c); plt.show()
> > from scipy.io import wavfile; wavfile.write("pulse.wav", 44100, (0.5 * (y - y.mean()) / A * 32767).astype(np.int16))
> > ```
>
> > [!info]- MATLAB / Octave
> > ```matlab
> > CPU = 1789773; d = 1/4; A = 12; midi = 69; % NES clock, duty, 4-bit volume, the note
> > t = round(CPU / (16 * 440 * 2^((midi - 69) / 12)) - 1); f = CPU / (16 * (t + 1)); % the 11-bit timer, and the pitch it really makes
> > n = 1:40; c = [A * d, 2 * A * abs(sin(n * pi * d)) ./ (n * pi)]; % |c_n|, n = 0..40
> > seq = [0 1 1 0 0 0 0 0]; % the chip's 8-step sequence for d = 1/4
> > ts = (0:44099) / 44100; y = A * seq(mod(floor(ts * f * 8), 8) + 1); % one second of the pulse
> > stairs(ts(1:400) * 1000, y(1:400)); figure; stem(0:40, c)
> > sound(0.5 * (y - mean(y)) / A, 44100)
> > ```
>
> > [!info]- R
> > ```r
> > CPU <- 1789773; d <- 1/4; A <- 12; midi <- 69 # NES clock, duty, 4-bit volume, the note
> > t <- round(CPU / (16 * 440 * 2^((midi - 69) / 12)) - 1); f <- CPU / (16 * (t + 1)) # the 11-bit timer, and the pitch it really makes
> > n <- 1:40; c <- c(A * d, 2 * A * abs(sin(n * pi * d)) / (n * pi)) # |c_n|, n = 0..40
> > seq <- c(0, 1, 1, 0, 0, 0, 0, 0) # the chip's 8-step sequence for d = 1/4
> > ts <- (0:44099) / 44100; y <- A * seq[floor(ts * f * 8) %% 8 + 1] # one second of the pulse
> > plot(ts[1:400] * 1000, y[1:400], type = "s"); plot(0:40, c, type = "h")
> > tuneR::play(tuneR::Wave(round(32767 * 0.5 * (y - mean(y)) / A), samp.rate = 44100, bit = 16)) # or writeWave(...)
> > ```
>
> > [!info]- Mathematica
> > ```mathematica
> > cpu = 1789773; d = 1/4; A = 12; midi = 69; (* NES clock, duty, 4-bit volume, the note *)
> > t = Round[cpu/(16 440 2^((midi - 69)/12)) - 1]; f = cpu/(16 (t + 1)); (* the 11-bit timer, and the pitch it really makes *)
> > c[0] = A d; c[n_] := 2 A Abs[Sin[n Pi d]]/(n Pi); (* |c_n| *)
> > seq = {0, 1, 1, 0, 0, 0, 0, 0}; (* the chip's 8-step sequence for d = 1/4 *)
> > pulse[tt_] := A seq[[Mod[Floor[8 f tt], 8] + 1]];
> > ListLinePlot[Table[{tt, pulse[tt]}, {tt, 0, 3/f, 1/(80 f)}], InterpolationOrder -> 0]
> > ListPlot[Table[c[n], {n, 0, 40}], Filling -> Axis, DataRange -> {0, 40}]
> > EmitSound @ Play[pulse[tt] - A d, {tt, 0, 1}]
> > ```
>
> [!quote] Attribution
> The hardware facts on this page — the duty sequences, timer formulas, the shift register and the mixer — are from the [NESdev wiki](https://www.nesdev.org/wiki/APU), and the Chipophone is Linus Åkesson's, described at [linusakesson.net/chipophone](https://www.linusakesson.net/chipophone/). The applet's see-it-and-hear-it design continues from [[Fourier Series]] and [[Fourier Transforms]], and with it the debt to Jez Swanson's *[An Interactive Introduction to Fourier Transforms](https://www.jezzamon.com/fourier/)* (source on [GitHub](https://github.com/Jezzamonn/fourier), MIT License). The loop the applet plays is an original written for this page; no game music is reproduced.