ITU-T G.711 defines two ways to fit telephone audio into 8 bits per sample, at 8,000 samples a second: µ-law, used in North America and Japan, and A-law, used elsewhere. Small values get finer steps than large ones. A raw file of telephone audio is just these bytes, and many container formats use them too.
Bit layout
After undoing the bit inversions described below, a code is:
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Field | s, sign | e, segment | m, mantissa | |||||
µ-law
Stored bytes have every bit inverted, so XOR the byte with 0xFF. Then, if
s is 1 the value is negative, and the magnitude, in 14-bit units, is:
y = (33 + 2m) × 2^e − 33
Values run from 0 to ±8,031. Silence is the stored byte FF; both
FF and 7F decode to 0. To express the result in 16 bits,
multiply by 4, which gives ±32,124 at most.
| Stored byte | After XOR | s | e | m | y (14-bit) |
|---|---|---|---|---|---|
FF | 00 | 0 | 0 | 0 | 0 |
8F | 70 | 0 | 7 | 0 | 33 × 128 − 33 = 4,191 |
00 | FF | 1 | 7 | 15 | −(63 × 128 − 33) = −8,031 |
A-law
Stored bytes have their even-numbered bits inverted, so XOR the byte with
0x55. Then the sign bit is 1 for positive and 0 for negative, the
opposite way round from µ-law, and the magnitude, in 13-bit units, is:
y = (16 × min(e, 1) + m + 0.5) × 2^max(e, 1)
No code decodes to exactly zero. Silence is the stored byte D5, which
decodes to +1. To express the result in 16 bits, multiply by 8, which gives ±32,256 at
most.
| Stored byte | After XOR | s | e | m | y (13-bit) |
|---|---|---|---|---|---|
D5 | 80 | 1 | 0 | 0 | +0.5 × 2 = +1 |
AA | FF | 1 | 7 | 15 | +31.5 × 128 = +4,032 |
2A | 7F | 0 | 7 | 15 | −4,032 |
Variants in the explorer
The Law option offers the G.711 reading and one variant for each code:
| Code | ITU G.711 | Without the inversion |
|---|---|---|
| µ-law | the byte is inverted (XOR FF); then the top bit set is negative | the byte is used as it stands: top bit set is negative, so 00 is 0 and 80 is −0, 7F is +8,031 and FF is −8,031 (14-bit units) |
| A-law | XOR 55; then the top bit set is positive | no XOR: 80 is +1 (13-bit units) and 00 is −1 |
Software that stores the codes in the order a magnitude-first reader expects, and some hardware dumps, use the variants. Try both laws and keep the one whose waveform is smoother.
Acorn VIDC
The Archimedes’ sound chip takes a logarithmic byte of its own, which FFmpeg names
vidc. Bit 0 is the sign (1 is negative) and bits 7 to 1 are a 3-bit segment
and a 4-bit mantissa, which give the same magnitudes as µ-law after undoing its
inversion: y = (33 + 2m) × 2^e − 33, from 0 to 8,031 in 14-bit
units. So 00 and 01 are 0, 02 is +8 (in 16-bit units) and 03 is −8,
and FE is +32,124. The explorer builds this from that rule and its test compares all 256 codes of µ-law,
A-law and VIDC with FFmpeg’s decoders: every value is equal.
Source: ITU-T Recommendation G.711 (Blue Book Fascicle III.4 extract, 1988 and 1993), clauses 2 to 3 and Tables 1a, 1b, 2a and 2b (the decision values, intervals and decoder output values, with the character signals in bit order and the mid-point rule of their Note 3). The page’s formulas, the examples and all 256 codes of each law were rebuilt from those tables by script and are equal. The factors 4 and 8 that widen the 14-bit and 13-bit values to 16 bits are the usual reference decoders’ convention, not part of G.711. The Acorn VIDC reading comes from FFmpeg’s decoder, not from Acorn’s documentation.