# lane/dts: ec-dts, DTS Coherent Acoustics decoder ## Result New crate `crates/ec-dts` (`#![forbid(unsafe_code)]`, depends only on ec-core). `DtsDecoder` implements `ec_core::Decoder` and outputs interleaved F32 (value = 24-bit integer * 2^-23, lossless in f32). Verification against ffmpeg's dca decoder (integer path, `-flags +bitexact`), differing samples: | Stream | Result | |---|---| | 4 committed fixtures from ffmpeg's dca encoder (stereo tone 48k, 5.1 noise with ADPCM 48k, mono sweep 32k, 5.1 tones 44.1k) | 0 differing samples | | Same stream in LE16, BE14, LE14 word orders | identical to BE16 (and to ffmpeg) | | FATE dcadec-suite (external, not committed): core 5.1 x2, XCH 6.1, X96 5.1, X96+XCH 6.1, DTS-ES, plus the cores of an XBR, an XLL and a 7.1 master-audio stream (450048 samples) | 0 differing samples, 8/8 vectors | | 400 rounds of corrupted frames | no panic | Against ffmpeg's default float path (different arithmetic, not the gate): the non-LFE channels differ by about 33 to 38 LSB at 24-bit (145 on one noise channel); the LFE channel differs by a large gain-related amount because the float LFE normalisation differs. Not investigated further; the integer path is what the decoder implements and matches exactly. Gate: `cargo clippy --workspace --all-targets -- -D warnings` clean; `EC_REQUIRE_FIXTURES=1 cargo test -p ec-dts` passes (5 + 1 tests; the FATE test skips when the vectors or ffmpeg are absent, `EC_DTS_FATE` selects the directory). ## Supported - Core: 5.1 and all `amode` layouts 0..9, all sample rates, 16/20/24-bit source, subband ADPCM, HF VQ, joint intensity, LFE (64x decimation), sum/diff, perfect and non-perfect QMF, 32-band synthesis. - Stream words: 16-bit BE/LE and 14-bit BE/LE, converted to canonical (`to_canonical`). - XCH (6.1, incl. ES downmix undo). X96 (96 kHz), both in-core and in an EXSS asset; reported sample rate is doubled. - DTS-HD: EXSS header/asset parse (sync 0x64582025); the core is always output. - Channel layouts: named (Mono/Stereo/5.1/7.1) where they match, else Custom. ## Not supported - XLL (lossless): not decoded. Flagged in `FrameInfo.xll`; `Options { refuse_xll: true }` makes it `Error::Unsupported` naming XLL. Default outputs the core. - XXCH, XBR, LBR: ignored (flag `hd_extensions_ignored`). EXSS without a core is `Unsupported`. - LFE with 128x decimation (LFF=1): implemented with a float FIR, untested (no stream or reference). - Downmix flags, dialnorm, DRC ignored (as requested). The `.dtshd` file wrapper (DTSHDHDR/STRMDATA chunks) is not parsed by the crate; `examples/dec.rs` does it for dev use. - No public DTS-HD MA sample was needed beyond the FATE xll/master-audio cores; a hand-built EXSS+XLL packet is tested. ## Public API `parse_frame_header(&[u8]) -> FrameHeader` (frame size, stream frame size, sample rate, channels, samples per frame, amode, bit rate, ...), `frame_size`, `find_sync`, `to_canonical`, `exss::parse_exss`, `DtsDecoder`, `Options`, `FrameInfo`. ## Provenance and licensing `src/tables_data.rs` is generated by `tools/gen_dts_tables.py` from the numeric tables in FFmpeg libavcodec (`dcadata.c`, `dcahuff.c`), which carry the public data of ETSI TS 102 114 (QMF windows, quantizer steps, scale factor tables, ADPCM and VQ codebooks, Huffman code lengths). Only numeric constants were taken; the decoder logic is a Rust implementation written against the spec structure with ffmpeg's integer path as the numerical reference (fixed-point arithmetic chosen to match it). FFmpeg is LGPL-2.1+; constants of a public standard are data, but if the project wants a clean-room table source this generator is the single place to replace. FATE samples (fate-suite.ffmpeg.org/dts) are used only as external, uncommitted test vectors. The 4 committed fixtures (~83 KB) are synthetic, generated with `ffmpeg -c:a dca -strict -2`. ## What edith's engine needs - Wire `CodecId::Dts` to `ec_dts::DtsDecoder::new()` (`impl Decoder`, one call per packet; a packet may be core only or core + EXSS). - Containers: the second agent's commit maps DTS in matroska/mp4/mpegts/riff and adds raw `.dts` and DTS-in-WAV to ec-probe (0492f7a6); packets must be whole core(+EXSS) frames. Raw `.dts` sniffing uses `parse_frame_header`/`find_sync`. - `.dtshd` files need a chunk walker (extract STRMDATA) before feeding frames. ## Dev tooling `crates/ec-dts/devscripts/` (ffmpeg comparison scripts), `examples/dec.rs`, `fuzz/` (decode_stream, parse_header, `seed.sh`).