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 |