Decode DTS (DTS Coherent Acoustics core) audio with FFmpeg's dca decoder, WASM
Decode DTS (DTS Coherent Acoustics) to PCM float samples.
FFmpeg's dca decoder, a slim LGPL-2.1-or-later libavcodec build (no GPL components), compiled to a single-file WASM ES module: no side files, loads from any CDN, Node, workers and AudioWorklets.
import decode, { decoder } from '@audio/decode-dts'
let { channelData, sampleRate } = await decode(dtsBytes)
let dec = await decoder()
let head = dec.decode(chunk1) // synchronous; partial frames carry over
let tail = dec.flush()
dec.free()
Input is a raw DTS core frame stream (.dts, or the frames a container demuxer extracts — @audio/decode-mp4, @audio/decode-webm and @audio/decode-avi route their DTS tracks here). The stream's own layout is kept (tested up to 5.1); channels come out in WAV order: FL, FR, FC, LFE, BL, BR (surround-only or mono as present), FFmpeg's native layout order. Output level is full scale: the stream's dynamic range coefficients are not applied.
DTS-HD Master Audio and High Resolution streams decode through their lossy core; the extension substreams are skipped. 14-bit and little-endian sync variants are handled.
API
decode(src: Uint8Array | ArrayBuffer): Promise<AudioData>
Decode a complete stream.
decoder(): Promise<DTSDecoder>
Synchronous streaming decoder: decode(chunk) returns the samples of every complete frame in the data so far, flush() drops a trailing partial frame, free() releases WASM memory. errors counts frames that failed to decode.
AudioData
{ channelData: Float32Array[], sampleRate: number }
License
ॐ · LGPL-2.1-or-later, inherited from the bundled FFmpeg dca decoder (built without --enable-gpl; see build.sh and LICENSE.ffmpeg). Corresponding source: FFmpeg 7.1.5 (release/7.1 at commit 3978a28), with build.sh and src/dts_glue.c.