V‐ADPCM - waffleoRai/zeqer64 GitHub Wiki

Overview

V-ADPCM is the codec used in the N64 SDK (and thus many in-house N64 games) for audio data storage. Audio samples are stored compressed on the ROM (headerless, in the case of Zelda 64 at least) and decompressed (I believe with the help of the RSP) at runtime as they are used. This greatly saves both ROM space and RAM over the standard 16-bit PCM (a little under 1:4 or 1:8 compression ratio), which is pretty important for a machine with 4MB of memory (or 8MB if you have one of them fancy expansion paks).

This page will go over both the general logic of V-ADPCM and how to decode it. (Encoding ADPCM, at least generating a table, is a bit of a pain so I won't cover it for now).

What is ADPCM?

ADPCM is the acronym for "Adaptive Differential Pulse Code Modulation". It's kind of intimidatingly technical sounding if you are not familiar with digital audio stuff or signal processing, but basically it's just a way to compress Pulse Code Modulation (PCM) audio data (which is usually just the default encoding - each value represents a sound level so to speak at some constant point in time) by storing something resembling the difference between samples instead of the full sample values.

Normally, ADPCM data are stored in blocks where there will be 1-2 control bytes specifying parameters for the whole block, then some number of samples, each usually taking up 2,4, or 8 bits. The block control parameters will usually specify an order of magnitude (shift amount) and coefficient table index to use to derive all samples in the block. Generally to derive an uncompressed sample, the compressed value is sign extended and bit-shifted left by the shift value to increase the order of magnitude. Then it is added to or combined in some way with the sum of some number of uncompressed previous samples (I have almost always seen this be 2 previous samples) multiplied by the appropriate table coefficients.

To decode ADPCM data, you will need the specific algorithm and will almost always need the coefficient table as well. Constant coefficient tables are not uncommon (the PlayStation 1 SPU uses a constant table for example), but a lot of Nintendo games use a combination of constant and sample/stream specific tables.

(I should probably draw up a quick diagram here)

ADPCM compression encodings are very lossy, so it's not really recommended for anything where audio fidelity is important. Although other lossy audio codecs such as vorbis and mp3 exist and are generally better known to most computer users, ADPCM encoded audio does still pop up in modern games. (This is part of why I prefer to buy OSTs for games I like instead of just doing a rip myself. They are higher quality, mastered for casual listening instead of for background music, and the CDs look great on my shelf.)

How does V-ADPCM work?

Technical Info

Data Format

ADPCM Table Format

Decoding Process