@audio/decode-tta

中文文档
2.0.0发布于 2026/09/29MITTypeScriptES Module零依赖近 30 天下载 54.6万

Decode TTA (True Audio) lossless audio to PCM samples

原始使用文档
文档目录6 节
  1. API
  2. decode(src: Uint8Array | ArrayBuffer): AudioData
  3. decoder(): TTADecoder
  4. AudioData
  5. CRC32
  6. Notes

@audio/decode-tta npm MIT

Decode TTA (True Audio) lossless audio to PCM samples, in pure JavaScript

npm install @audio/decode-tta
import decode, { decoder } from '@audio/decode-tta'

TTA1 is Alexander Djourik's lossless codec: per channel, an adaptive two-state Rice coder feeds an 8-tap sign-sign-LMS "hybrid" filter and a fixed first-order predictor; multichannel streams decorrelate the last channel against the rest with a cascading half-sum/difference. Written from the TTA project and the BSD-licensed reference decoder — Djourik & Zhilin, True Audio Software (2004): ttadec.c / filter.h / ttadec.h / ttalib.h, via Rockbox's libtta port which retains the original license — see LICENSE.ttadec. Decodes exactly what ffmpeg -c:a tta writes: 8/16/24-bit PCM, mono through 16 channels.

let { channelData, sampleRate } = decode(ttaBytes)

let dec = decoder()
let head = dec.decode(chunk1)   // synchronous; header/seek-table/frame boundaries carry over
let tail = dec.flush()
dec.free()

API

decode(src: Uint8Array | ArrayBuffer): AudioData

Decode a complete stream.

decoder(): TTADecoder

Synchronous streaming decoder. decode(chunk) returns the samples of every complete frame in the data so far — frame byte lengths are known from the seek table, so a chunk boundary anywhere (even mid-header) just carries over to the next call. flush() drops a trailing incomplete header/seek-table/frame. free() releases state and is idempotent. errors counts frames dropped for a CRC32 mismatch.

AudioData

{ channelData: Float32Array[], sampleRate: number }

CRC32

TTA1 checksums the header, the seek table, and every frame independently. A header or seek-table mismatch throws — those describe the stream's shape and can't be decoded around. A frame mismatch is not fatal: since each frame resets its filter/predictor/Rice state from scratch, one bad frame can't corrupt its neighbors, so that frame's samples are dropped, errors increments, and decoding continues.

Notes

  • Only format 1 (plain PCM) is decoded; format 2 (password-encrypted TTA) throws.
  • Channel order is kept exactly as encoded — TTA does not reorder channels the way AC-3/DTS do, so channelData[i] is stream channel i.
  • A leading ID3v2 tag (some encoders other than ffmpeg prepend one) is detected and skipped before the TTA1 signature; a trailing APEv2 tag is ignored.
  • A truncated file loses its final incomplete frame silently, matching flush()'s "drop the partial" behavior in the other atoms in this umbrella.
  • 60 s of 44.1 kHz stereo decodes in ~225 ms on a current laptop (~265× real-time).

Use when: opening .tta files, or decoding a TTA track pulled out of a container.


Part of @audio/decode — the decode family umbrella.

MIT © audiojs, algorithm ported from the BSD-licensed TTA reference decoder — see LICENSE.ttadec

版本与发布记录

@audio/decode-tta 共发布 2 个版本,首次发布于 2026/08/29;过去 12 个月发布了 2 个版本。

版本发布日期距今
2.0.0latest2026/09/291 个月前
1.0.02026/08/292 个月前

关于 @audio/decode-tta 的常见问题

@audio/decode-tta 是什么?

Decode TTA (True Audio) lossless audio to PCM samples

如何安装 @audio/decode-tta?

在项目目录运行 npm install @audio/decode-tta,或使用 pnpm add / yarn add / bun add。

@audio/decode-tta 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@audio/decode-tta 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@audio/decode-tta 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@audio/decode-tta 可以商用吗?

@audio/decode-tta 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@audio/decode-tta 的下载量有多少?

根据 npm 官方下载统计,@audio/decode-tta 在 2026/10/07 – 2026/11/05 这 30 天内被下载 546,398 次,日均约 18,213 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@audio/decode-tta 还在维护吗?

最新版本 2.0.0 发布于 2026/09/29(1 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。