TTA Lossless Audio Codec - Format Description


Detailed description of the TTA multichannel audio data format

TTA is a simple and stable lossless audio data format for real-time compressing of digital music. Free and fully-functional for any use. It has a very simple structure. The TTA file header contains a unique format identifier, which is followed by meta-data block. Meta-data block contains minimal information which is needed for restoring the original stream (including number of channels, count of bits per sample, sample rate and overall number of samples in file, etc.) and ended by a 32-bit control sum. Following that header, we write one or more audio frames. Each frame is ended by a 32-bit control sum; a decoder may start decoding from any frame in the stream. The compressed samples of channels in a frame are located sequentially, as in a simple PCM data format.

TTA1 Header Structure

Byte numberValue (format)
Stream header
00-03Format signature with version number (ASCII, "TTA1")
04-05Audio format (binary, Little Endian)
06-07Number of channels (binary, Little Endian)
08-09Bits per sample (binary, Little Endian)
10-13Sample rate (binary, Little Endian)
14-17Data length in samples (binary, Little Endian)
18-21CRC32 block footer (binary, Little Endian)
Seek table1
22-25Seek point 1 (binary, Little Endian)
26-X0.. .. .. .. .. .. .. .. .. .. .. .. .. ..
X1-X4Seek point N (binary, Little Endian)
X5-X8CRC32 block footer (binary, Little Endian)
.. .. .. data .. .. ..

1 In TTA1 the Seek table is located at the start of the file, following the meta-data block.

TTA2 Header Structure

Byte numberValue (format)
Stream header
00-03Идентификатор формата с номером версии (символьный, «TTA2»)
04-05Number of channels (binary, Little Endian)
06-07Bits per sample (binary, Little Endian)
08-11Sample rate (binary, Little Endian)
12-19Data length in samples (binary, Little Endian, may be zero)
20-27Data size, bytes (binary, Little Endian, may be zero)
28-31CRC32 block footer (binary, Little Endian)
.. .. .. data .. .. ..
Stream footer (Seek table)
00-02End of stream signature (binary, "0xFFFFFF")
03-06Seek point 1 (binary, Little Endian)
07-X0.. .. .. .. .. .. .. .. .. .. .. .. .. ..
X1-X4Seek point N (binary, Little Endian)
X5-X8CRC32 block footer (binary, Little Endian)

The quotient of overall count of samples and "frame length" defines the total number of frames in data stream. The seek table must have a number of seek-points equal to the number of frames in the stream. Each seek-point uses 4 bytes, contains the current frame data length in bytes and can be easily transformed into the Seek point value which specifies the location of the next frame. It is possible to decode TTA file with a corrupted seek table, but in "unseekable" mode only.

TTA1 Frame Structure

Byte numberValue (format)
00-X0Frame data (bit stream)
X1-X4CRC32 block footer (binary, Little Endian)

The frame duration in the TTA1 format is fixed at about one second. Therefore, every frame in a stream has an equal count of samples, except for the last. The sample count in a TTA1 frame is a multiple to 576 (sound buffer granule). Based on this, the "frame time" is defined as a constant 1.04489795918367346939. Thus, the sample count in a regular TTA1 frame determined as:

regular TTA1 frame length = frame time * sample rate

TTA2 Frame Structure

Byte numberValue (format)
00-X0Frame data (bit stream)
X1~X3End of frame signature (bit stream, "0xFFFFFE")
X4-X7CRC32 block footer (binary, Little Endian)

In theory, the frame duration in the TTA2 format can be any length, but for ease of use is defined equal to one second. Thus, the sample count in a standard TTA2 frame determined by sample rate.

The total number of frames in TTA data stream can be calculated as a quotient of overall count of samples and standard "frame length". TTA format supports both of ID3v1/v2 and APEv2 information tags.