dts

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT, MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

DTS Core and XLL decoding

The decoder implementation is covered by the MIT license.

The implementation uses ETSI TS 102 114 V1.6.1 (2019-08). Core framing follows section 5.3.1. Extension substream and asset headers follow section 7. XLL common, channel-set, and navigation data follow sections 8.3 and 8.4. Figure 8-4 defines the entries stored in the NAVI index for each set. Segment totals are derived from these entries, which the fixture NAVI checksums and payload sizes also confirm. Header checksums use Annex B.

ParseFrame inspects one access unit of an elementary stream. ParsePacket requires one complete access unit. Both return the declared sample count, the PCM speaker layout, and borrowed Core and XLL payloads. Core metadata describes the primary Core presentation. The lossless format comes from the XLL channel sets when ExSS carries XLL. A Core may be present even when every XLL channel is independently coded. The XLL residual-type bits determine CoreDependent.

ExSS describes the asset's maximum PCM resolution (section 7.5.3.2). Each XLL channel set declares its own PCM resolution and storage width (section 8.3.2). The asset declaration remains the output precision when the channel sets in one frame all use fewer bits. Frame.XLLPrecision reports those values in bitstream order, and XLLPrecisionError carries the values read before a precision or profile failure.

Decoder reconstructs independent, single-band channel sets at a common sample rate using linear, Rice or hybrid Rice coding, fixed and adaptive prediction, and pairwise channel decorrelation (section 8.5). It reads segment entries in channel-set order and keeps the coding parameters separate for each set (sections 8.4.2 and 8.4.3). For a scalable band it joins the predicted MSBs and channel-planar LSBs using the split and authoring adjustment in section 8.6.1. Samples are promoted to the asset precision and returned as right-justified signed PCM in speaker order. A single applied hierarchical matrix can restore earlier channel sets with the same PCM precision and positive scales. An applied matrix for scalable channel sets uses their declared PCM precision before promoting the restored samples to the asset precision. Primary compatibility matrices and advisory non-primary matrices leave the full-channel PCM untouched.

For Core-dependent XLL, the decoder reconstructs signed integer Core PCM at the same sample rate and frame length. It applies the inverse downmix gain to the relevant Core speakers, rounds onto the scalable MSB grid, and adds the residual before reversing the embedded channel downmix. When an applied hierarchy needs prior Core history, the initial residual packet uses Core PCM at the channel-set precision. A single set can combine its first residual with the initial Core PCM. Independent packets carrying Core also advance this history.

Other applied matrix profiles, high-frequency XLL bands, and band CRCs require additional implementation.

The parser handles big-endian 16-bit Core packing and an ExSS with one active presentation and one directly mapped asset in substream zero. The decoder uses the declared XLL sync offset and initial delay to assemble frames across packets. It emits Core audio or silence during the initial delay and requires the initial XLL channel headers to determine the output format. Asset remaps and replacement channel sets require additional parsing. The CRC-checked navigation index bounds the sample payload. Up to three bytes of frame alignment are accepted after the final indexed segment. For DTS:X carriers with the observed standard trailer marker, the validated NAVI extent bounds the compatible channel-based bed. The decoder ignores the separate trailer and does not render its spatial audio.

Public-domain fixtures

The following fixtures come from the dcadec-samples public-domain corpus. The DTS files are the unmodified payloads of the upstream DTS-HD STRMDATA chunks. The WAVs are copied unchanged from its reference/ directory. The corpus's public-domain notice covers these sample files.

Local file or pattern Upstream file or pattern
testdata/core-51.dts core_51_24_48_768_0.dtshd
testdata/xll-51.dts xll_51_24_48_none.dtshd
testdata/xll-71-residual.dts xll_71_24_48_768_0.dtshd
testdata/xll-51-{L,R,C,LFE,Ls,Rs}.wav reference/xll_51_24_48_none_{L,R,C,LFE,Ls,Rs}.wav

The coreless stream has 1,024 silent lead-in samples and 2,048 reference samples per channel. The test compares each decoded sample against the corresponding 24-bit WAV sample for all six channels. The root waveform fixture remuxes the same public-domain coreless payload into Matroska without re-encoding. The 7.1 residual waveform fixture remuxes xll-71-residual.dts. The decoder test compares all of its PCM against the signed 24-bit hash from FFmpeg in bit-exact mode. The synthetic xll-core-scalable-18.dts fixture has two access units with 18-bit XLL channel sets and a 24-bit asset. It pairs the 5.1 tone Core, signalled at 48 kHz, with linear XLL residuals, variable-length LSB splits, and an applied hierarchical matrix. Its reference also comes from FFmpeg in bit-exact mode.

The precision tests modify declared bit depths in memory and recalculate the affected header checksums on these same fixtures.

ffmpeg -nostdin -v error -fflags +bitexact -f dts \
  -i internal/dts/testdata/xll-51.dts -c:a copy -fflags +bitexact testdata/matroska-dts-xll-51.mka

xll_multiset_test.go generates synthetic 48 kHz 5.1 fixtures from test PCM. They follow the two-primary-set layout described in section 8.6.2.1 and encode 24-bit L/R alongside C/Ls/Rs/LFE at 16- or 20-bit precision. The four segments exercise interleaving and per-set coding state, and every decoded sample is compared with the source plane at the shared output precision. xll_scalable_test.go uses those packet builders to verify nonzero fixed, variable, and authoring-adjusted LSBs alongside permuted MSBs. The oracle checks each 24-bit or 18-bit channel at the declared 24-bit asset precision. xll_pairwise_test.go exercises active pairs with signed coefficients, prediction history, a channel permutation, and both unsplit and scalable PCM. ETSI section 8.5.5 gives the inverse operation and its order. Nonzero authored packets decoded with FFmpeg 9.0.2 independently confirmed a three-bit shift with rounding bias four. Both authored test streams also matched the reference PCM byte for byte across 2,560 frames each. The tests use the reference values directly and run without FFmpeg.

Hierarchical inverse downmix

Applied downmix is reversed after reconstructing the channel sets and before publishing speaker planes. Table 8-4 and section 8.6.2.4 define the matrix and target set order. Annex C.9 combines each signed Q15 coefficient with the Q16 inverse scale, and each resulting source contribution is rounded and subtracted separately.

The two numeric columns in xll_downmix_tables.go were transcribed from Annex D.11. The 241 Q15 values packed as little-endian uint16 have SHA-256 d753f8567df08e20aefc005d1e8a2bc8416ff8e00777f4468a5e75da3afab523. The 201 Q16 values packed as little-endian uint32 have SHA-256 2ecc54090b8ed588563e13ca9dc7e321b26fe14ae407767287c98d9e2a16b9b8.

xll_downmix_test.go builds a nonzero 24-bit 5.1 vector with both positive and negative coefficients and a common -3 dB scale. It compares every restored sample with the SHA-256 of an interleaved s24le decode of the same vector by FFmpeg 9.0.2. To reproduce the reference, write the DTS packet returned by xllMatrixVector(true, 0x1d9) and decode it as follows.

ffmpeg -nostdin -v error -f dts -i xll-matrix.dts -c:a pcm_s24le -f s24le xll-matrix.s24le

Core reconstruction

Annex D.10 describes two codebooks without publishing the complete values. D.10.1 has 4,096 four-coefficient ADPCM entries in Q13. D.10.2 has 1,024 high-frequency vectors of 32 signed elements. The printed tables for scalar quantization and synthesis allow a Core slice to proceed with explicit rejection when a packet invokes either omitted book.

For full Core reconstruction, obtain both books from a source with documented redistribution rights. Audit their entry order and scaling and record source revisions, dimensions, and checksums. A permissively labelled package with unidentified table sources cannot establish that provenance. Use independently authored single-tool vectors with the public reference PCM to verify Core prediction, high-frequency VQ, and the fixed-point filter bank before relying on its samples for residual XLL.

Documentation

Overview

The scale books and RMS table adapt the published ETSI rows transcribed by OxideAV. See CORE.md and LICENSE.md for source and attribution.

Package dts inspects DTS Core and DTS-HD Master Audio access units and decodes self-contained, single-band XLL channel sets.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid     = errors.New("invalid DTS frame")
	ErrUnsupported = errors.New("unsupported DTS frame")
)

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reconstructs PCM from a supported DTS Core or XLL stream.

func NewDecoder

func NewDecoder(packet []byte) (*Decoder, error)

NewDecoder inspects the first packet of a DTS stream. Pass the first packet to Decode to reconstruct its samples.

func (*Decoder) Decode

func (d *Decoder) Decode(packet []byte) (any, error)

Decode reconstructs one DTS packet. The PCM planes are borrowed until the next Decode call and use the order reported by PCMFormat.

func (*Decoder) PCMFormat

func (d *Decoder) PCMFormat() audio.Format

PCMFormat returns the rate, sample encoding and speaker order for Decode.

type Frame

type Frame struct {
	Fmt           audio.Format
	Samples       int
	Core          []byte
	XLL           []byte
	CoreDependent bool
	// contains filtered or unexported fields
}

Frame describes one encoded access unit. The payloads borrow from the input. Fmt describes the nominal PCM format in BeatGlow's conventional speaker order. CoreDependent identifies an XLL frame whose samples require Core PCM.

func ParseFrame

func ParseFrame(data []byte) (Frame, int, error)

ParseFrame inspects the first access unit in data and returns its byte length. When a complete Core frame ends at the end of data, it is classified as Core.

func ParsePacket

func ParsePacket(packet []byte) (Frame, error)

ParsePacket inspects a packet containing exactly one DTS access unit.

func (Frame) XLLPrecision

func (f Frame) XLLPrecision() XLLPrecision

XLLPrecision returns the bit depths declared by an inspected XLL frame. The return value is empty for a Core-only frame.

type XLLChannelSetPrecision

type XLLChannelSetPrecision struct {
	Channels    int
	PCMBits     int
	StorageBits int
}

XLLChannelSetPrecision describes the original PCM precision and storage width declared by one XLL channel-set header.

type XLLPrecision

type XLLPrecision struct {
	AssetBits       int
	ChannelSetCount int
	Sets            []XLLChannelSetPrecision
}

XLLPrecision reports the ExSS asset's declared maximum PCM resolution and the XLL channel-set resolutions in bitstream order. On an error, Sets may contain fewer entries than ChannelSetCount.

type XLLPrecisionError

type XLLPrecisionError struct {
	Precision XLLPrecision
	// contains filtered or unexported fields
}

XLLPrecisionError adds numeric XLL header diagnostics to a parsing or decoder profile error. Unwrap preserves the original error classification.

func (*XLLPrecisionError) Error

func (e *XLLPrecisionError) Error() string

func (*XLLPrecisionError) Unwrap

func (e *XLLPrecisionError) Unwrap() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL