A TTA file begins with a fixed header and a seek table, then its frames. ID3v2 data may come before the header, and ID3v1 or APEv2 tags after the frames. Numbers are little-endian. This page follows the format description published by the codec’s authors, and FFmpeg’s reader.
TTA1 header
| Offset | Size | Type | Field | Meaning |
|---|---|---|---|---|
| 0 | 4 | char[4] | Signature | TTA1 |
| 4 | 2 | uint16 | Audio format | See below |
| 6 | 2 | uint16 | Channels | Number of channels |
| 8 | 2 | uint16 | Bits per sample | 8, 16 or 24; 32 for floating point |
| 10 | 4 | uint32 | Sample rate | In hertz |
| 14 | 4 | uint32 | Data length | Samples per channel in the file |
| 18 | 4 | uint32 | CRC-32 | Of the first 18 bytes |
| Audio format | Meaning |
|---|---|
| 0 | Read like 1 by libtta and FFmpeg; no tool writes it |
| 1 | Simple |
| 2 | Encrypted: decoding needs the password |
| 3 | Floating point (ttaenc 3.2 and 3.3): each float is two integer channels |
FFmpeg’s demuxer refuses a file with a sample rate of 0 or above 1,000,000 or with no samples; its decoder refuses 0 channels, more than 16 channels, a rate above 8,388,607 (so that 256 × rate fits in 32 bits) and more than 24 bits. Bits per sample are rounded up to whole bytes by the coder: the variants page has the table.
The CRCs
Every CRC in a TTA file is the usual CRC-32 of zip and PNG: polynomial 0xEDB88320
(reflected), register starting at 0xFFFFFFFF, final result xor-ed with
0xFFFFFFFF, stored as 4 bytes little-endian. The header’s covers bytes 0 to 17, the seek table’s
covers its entries, and each frame’s covers the frame’s bytes up to its CRC. None of them covers anything
else, so a damaged header field shows as a wrong header CRC and a damaged tag does not show at all.
In the example below the header CRC is the bytes FA E4 62 99, the number 0x9962E4FA.
Frame length and count
The frame length is fixed by the sample rate. The published frame time is 1.04489795918367346939 seconds, which is 256/245:
frame length = 256 × sample rate ÷ 245
last frame = data length mod frame length
frame count = data length ÷ frame length, plus 1 if the last frame is not empty
The division rounds down. The common rates give:
| Sample rate | Frame length (samples) | Sample rate | Frame length (samples) |
|---|---|---|---|
| 8,000 | 8,359 | 44,100 | 46,080 |
| 11,025 | 11,520 | 48,000 | 50,155 |
| 16,000 | 16,718 | 88,200 | 92,160 |
| 22,050 | 23,040 | 96,000 | 100,310 |
| 32,000 | 33,436 | 176,400 / 192,000 | 184,320 / 200,620 |
The last frame holds what is left: data length − (frames − 1) × frame length
samples, which is a whole frame when the length divides evenly. A file whose header has 0 samples
has no frames and a seek table of only its CRC (4 bytes). All of these were checked on files
written by FFmpeg’s encoder at each of these rates, and with 1, 2, 255, one less than, equal to and one more than a
frame, and two frames and 7 samples.
Seek table
The table follows the header directly.
| Offset | Size | Type | Field | Meaning |
|---|---|---|---|---|
| 22 | 4 × frames | uint32[] | Seek points | The compressed size in bytes of each frame, including its CRC |
| after those | 4 | uint32 | CRC-32 | Of the seek points |
Each frame’s position is the end of the table plus the sizes of the frames before it. A file whose table is damaged can still be decoded, but not seeked: a decoder that finds the table’s CRC wrong can decode the frames one after another, since each frame ends where its last value ends (padded to a byte) plus 4 bytes of CRC. ttaenc does this and the explorer does too, and says so. The table has exactly one entry for each frame the header calls for: a file that ends inside the table has fewer, and the frames cannot be placed from it.
The sizes are of the frames as stored, so the sum of them is the length of the frame area. What lies beyond that, up to the end of the file, is tags (see the tags page) or damage.
Worked example
The start of luckynight.tta (from the MPlayer sample collection; 6,595,217 bytes):
00000000: 54 54 41 31 01 00 02 00 10 00 44 AC 00 00 A0 B2 28 00 FA E4 62 99
TTA1 fmt 1 2 ch 16 bit 44100 Hz 2,667,168 CRC 0x9962E4FA
00000016: 28 40 01 00 0A 9C 01 00 BA CB 01 00 1C D8 01 00 2D C7 01 00 …
81,960 105,482 117,690 120,860 116,525 the sizes of frames 0 to 4
The frame length is 256 × 44100 ÷ 245 = 46,080 samples. 57 frames hold 2,626,560 samples and
leave 40,608 for the last, so there are 58 frames. The table is 58 × 4 + 4 = 236 bytes (its CRC
is 0x37FE098E), and frame 0 starts at offset 22 + 236 = 258 and ends at 258 + 81,960 =
82,218 with its own CRC-32, 36 7D D7 05. The explorer shows each of these as a node of the tree
and each frame as a row of its Frames table.
A second real file, inside.tta (FFmpeg’s test suite), has 524,277 samples: 11 frames of 46,080
and a last of 17,397, so 12 frames.
Draft TTA2
Two different layouts start with TTA2. The 2003 development version of ttaenc writes a
20-byte header with a compression level and no CRC (described on the variants page).
The authors’ description on their wiki gives another, marked as in development: no file or tool
that writes that one is known. The variants page has the
channel mask values and the rest of what is described; the wiki’s header is:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Signature | TTA2 |
| 4 | 2 | Channels | Number of channels |
| 6 | 2 | Bits per sample | |
| 8 | 4 | Sample rate | In hertz |
| 12 | 4 | Channel mask | Channel locations: 15 bits |
| 16 | 8 | Data length | In samples; may be 0 |
| 24 | 8 | Data size | In bytes; may be 0 |
| 32 | 4 | CRC-32 | Of the first 32 bytes |
In TTA2 a frame ends with an end-of-frame signature, then a CRC-32. The wiki writes the signature as the value 0xFFFFFE and libttaR as the bytes FE FF FF; the TTA variants page has the details. The seek table is a footer: the signature FF FF FF, the seek points, then a CRC-32.