The DTS-HD container
A .dtshd or .dtsma file (as the DTS-HD Master Audio Suite and other
tools write it) is a sequence of chunks. The first is DTSHDHDR. A chunk is an 8-byte
identifier, a 64-bit big-endian size, and that many bytes of data; there is no padding.
| Chunk | Holds |
|---|---|
DTSHDHDR | the file header: the first chunk |
FILEINFO | text about the file (the program that made it, settings) |
BUILDVER | text: the version of the tool |
AUPR-HDR | the audio presentation, below |
CORESSMD, EXTSS_MD | metadata of the core substream and of the extension substreams |
NAVI | a navigation index of the stream |
TIMECODE | a time code |
STRMDATA | the stream: core frames and extension substreams, as in a bare file; the last chunk |
AUPR-HDR
| Offset | Bytes | Field |
|---|---|---|
| 0 | 3 | not described in the sources used |
| 3 | 3 | the sampling rate in Hz |
| 6 | 4 | the number of frames |
| 10 | 2 | the number of samples in a frame |
| 12 | 5 | the number of samples in the stream (a 40-bit value) |
| 17 | 2 | the channel mask, as the extension substream gives it (below) |
| 19 | 2 | the codec delay in samples: the first this many samples are not part of the sound |
The last frame of a DTS-HD stream is often a “blackout” frame, a core frame with no extension substream after a run of frames that have one; decoders drop it, and a player that stops at STRMDATA’s end does not reach any bytes after the chunk.
The extension substream header
An extension substream (EXSS) follows a core frame, or stands alone in a stream of DTS-HD. It
starts with the sync word 64582025 and a header whose end is covered by a CRC-16.
| Field | Bits | Meaning |
|---|---|---|
| sync word | 32 | 0x64582025 |
| user defined | 8 | free for the user |
| substream index | 2 | which extension substream this is |
| wide header flag | 1 | when 1 the next two sizes are 12 and 20 bits wide, else 8 and 16 |
| header size | 8 or 12 | the header’s size in bytes, minus 1 |
| substream size | 16 or 20 | the substream’s size in bytes, minus 1 (a multiple of 4) |
| static fields | 1 | whether the fields below, which describe the whole stream, are present |
| static fields | … | a reference clock code and frame duration, an optional time code, the number of audio presentations and assets (each minus 1), which substreams each presentation uses, and the mixing metadata: a count of mixing configurations and the speaker layout of each |
| asset sizes | 16 or 20 each | the size of each asset’s data, minus 1 |
| asset descriptors | … | one for each asset, below |
| CRC-16 | 16 | after padding to a byte boundary |
Asset descriptor
An asset is one coded audio signal. Its descriptor gives its own size (9 bits, minus 1), an index (3 bits), and, when the static fields are present: optional type, language and text descriptors, the PCM bit resolution (5 bits, plus 1), the maximum sampling rate (a 4-bit code), the total number of channels (8 bits, plus 1) and the loudspeaker layout: a flag for a one-to-one map of channels to speakers, flags for an embedded stereo and an embedded 5.1 downmix, and a speaker activity mask (below) with optional remapping sets. Then come the dynamic range and dialogue normalisation codes, the mixing metadata and the coding mode (2 bits): 0 for several components, 1 for lossless without a core, 2 for low bit rate, 3 for an auxiliary codec. Mode 0 gives a 12-bit mask of the components present and the size of each:
| Mask bit | Component | Size field |
|---|---|---|
| 4 | core | 14 bits, minus 1, and a sync distance |
| 5 | XBR | 14 bits, minus 1 |
| 6 | XXCh | 14 bits, minus 1 |
| 7 | X96 | 12 bits, minus 1 |
| 8 | LBR | 14 bits, minus 1 |
| 9 | XLL | a size (as wide as the substream size, minus 1), a flag, and with it a decoding delay in frames and the offset of the first XLL sync word |
The XLL entry is the one that tells how the lossless data is laid out. Its size is the bytes of XLL data in this substream. When the sync flag is set, a 4-bit field the format does not describe is followed by the width of the delay (5 bits, plus 1), the decoding delay in frames, and the byte offset of the first XLL sync word from the start of the XLL data. With the offset 0 and the delay 0 every substream begins with a frame. When the lossless data of a frame runs on into the next substream (peak bit rate smoothing), a decoder that joins the stream there finds no sync word at the start: it skips to the offset, and the delay says how many substreams to wait before the buffered frame is complete enough to use. A 3-bit stream identifier follows the component sizes. A change of the identifier means a new stream, and the decoder forgets what it buffered. The XLL data itself is described under XLL.
The components follow the header in that order, each at the byte offset the sizes give (a multiple of 4). The sampling rate codes are 8, 16, 32, 64, 128, 22.05, 44.1, 88.2, 176.4, 352.8, 12, 24, 48, 96, 192 and 384 kHz.
Speaker masks
A speaker activity mask has one bit for each speaker or pair: bit 0 C, 1 L R, 2 Ls Rs, 3 LFE, 4 Cs, 5 Lh Rh, 6 Lsr Rsr, 7 Ch, 8 Oh, 9 Lc Rc, 10 Lw Rw, 11 Lss Rss, 12 LFE2, 13 Lhs Rhs, 14 Chr, 15 Lhr Rhr. The channel count of a mask counts a pair as two.
DTS in other containers
In MP4 a sample is one frame (the core frame, then the
extension substream when there is one), with the sample entry dtsc (core), dtsh
(core and extensions), dtsl (XLL only) or dtse (LBR only), and a
ddts box (sampling frequency, maximum and average bit rate, the source depth and a
packed description with the frame duration, the stream construction, the core layout and size and
the channel layout). Some muters write DTS as mp4a with the object type 0xA9
(core), 0xAA (core and extensions), 0xAB (XLL only) or 0xAC (LBR only). In
Matroska the codec is A_DTS (core, with the extension
substream after it for DTS-HD) or A_DTS/LOSSLESS (the lossless layer alone), one frame to a block.
In a WAVE file the codes 0x0008, 0x0190 and 0x2001 hold frames
in the data chunk; an ordinary 16-bit stereo file may instead hold IEC 61937 bursts: the words
F872 4E1F, a code word whose low five bits are the data type (11, 12 or 13 for a core
of 512, 1,024 or 2,048 samples; 17 for DTS-HD), a length word and then the frame, which fills one
burst period of the stereo stream. In MPEG-TS DTS is the stream
types 0x82 (core), 0x85 (DTS-HD) and 0x86 (DTS-HD Master Audio).