JA EN
LearnGenerative Models
·★ MEMBER·PAPER·9 min read

Music and Audio Generation from Scratch — Sound as Tokens

A three-minute song is more than 15 million numbers. The history of music generation is largely the history of folding that sequence down to something a model can hold. Codec tokens, the fork between autoregressive and diffusion approaches, how text conditioning actually bites, and how to reconstruct the shape of Suno-style products from published parts — no prior knowledge assumed.

ModalitytextTaskgeneration

Simple and Controllable Music Generation


A three-minute song is 15 million numbers

Producing three minutes of CD-quality audio (44.1 kHz, stereo) means putting roughly 15.88 million numbers in a convincing order — 44,100 measurements per second, twice over for two channels.

Compare that to text. A 3,000-word article is a few thousand tokens. Audio is four orders of magnitude away. Worse, neighbouring samples are tightly correlated, so a single wrong value doesn't blur into the background — it arrives at your ear as an audible click.

Which is why the history of music and audio generation is, for the most part, the history of folding those 15.88 million numbers down. Get the arithmetic straight before worrying about architectures.

The analogy: write notes, or write catalogue numbers

There were two long-standing ways to do the folding.

The first is the score approach. "Play a C for half a second on piano" — three minutes becomes a few thousand symbols. MIDI-generating models live here, and they are genuinely cheap to run. But turning symbols back into sound is where the singing voice, the grit of an overdriven guitar, and the room's reverb all fall out. A score records what to play, never how it actually sounded.

The second is the waveform approach. Generate the air pressure itself and you can represent anything — but the sequence is hopeless, as above. OpenAI's Jukebox took this route in 2020 and produced songs with vocals, at the cost of hours per track.

What dominates today sits in between: the catalogue approach. Slice the audio into short frames and replace each frame with an integer — "which entry of the codebook does this look most like?" As short as a score, as expressive as a waveform. That sequence of integers is what we call codec tokens, and "sound as tokens" means exactly this substitution.

Counting per second — why tokens make this tractable

The payoff shows up immediately in the arithmetic. The token count is a plain product.

N=TfnqN = T \cdot f \cdot n_q
(1)

In words: seconds × frames per second × how many integers you stack per frame. Here TT is duration, ff is the frame rate (how finely a second is chopped), and nqn_q is the number of stacked codes per frame — the number of residual quantization stages.

MusicGen uses a 32 kHz EnCodec with f=50f = 50 and nq=4n_q = 4. Three minutes is 180×50×4=36,000180 \times 50 \times 4 = 36{,}000 tokens. The 15.88 million became thirty-six thousand — the same ballpark as a long document.

The same ingredients give you the bitrate.

R=fnqlog2KR = f \cdot n_q \cdot \log_2 K

That is, frames per second × stages × bits needed to write one index. With a codebook size KK of 2048, each index costs 11 bits, so 50×4×11=2,20050 \times 4 \times 11 = 2{,}200 bps — about 2.2 kbps.

Why stack several codes per frame instead of one — residual quantization — is covered in neural audio codecs. The only premise you need here is one line: audio can be turned into a finite sequence of integers, and turned back.

FIG 1Quantization is exactly this nearest-neighbour lookup. The point you drag is the vector the encoder emitted, the surrounding points are codebook entries, and the index of the closest one becomes the token — and just as here, changing the distance metric changes which entries win

Fork one: autoregression — keep guessing the next index

Once audio is a sequence of integers, it behaves like text. Predict the next index, append it, repeat. The same machinery that produces sentences produces songs.

Audio adds one wrinkle text doesn't have: each frame carries four indices stacked vertically. A text token is one symbol per position, so there is nothing to decide; audio has to emit four codebook entries for the same instant.

The two obvious answers both hurt. Flatten the four stages into one stream and the sequence gets four times longer, so generation gets four times slower. Emit all four independently and the stages stop agreeing with each other — stage 1 commits to a piano while stage 2 adds the residual of a distorted guitar.

MusicGen's compromise is the delay pattern: shift stage backwards by frames. By the time stage 2 is emitted, stage 1 for that instant is already decided and can be conditioned on — and the sequence barely grows in length.

What's behind this

§

Members-only from here

371 walkthroughs, 26 textbook chapters, 48 student units and 6 close readings — all included for $4.99/mo, with three new explainers every day. Cancel any time; access runs to the end of the period.

Already a member? Sign in to keep reading

References

  1. Simple and Controllable Music Generation. arXiv:2306.05284Paper page·PDF
  2. MusicLM: Generating Music From Text. arXiv:2301.11325Paper page·PDF
  3. AudioLM: a Language Modeling Approach to Audio Generation. arXiv:2209.03143Paper page·PDF
  4. Fast Timing-Conditioned Latent Audio Diffusion. arXiv:2402.04825Paper page·PDF
  5. AudioLDM: Text-to-Audio Generation with Latent Diffusion Models. arXiv:2301.12503Paper page·PDF
  6. Jukebox: A Generative Model for Music. arXiv:2005.00341Paper page·PDF
  7. Fréchet Audio Distance: A Metric for Evaluating Music Enhancement Algorithms. arXiv:1812.08466Paper page·PDF

This article is written from the source paper above. Where they differ, the original is authoritative.

Comments

Sign in to comment