@audio/decode-mpc

中文文档
1.0.0发布于 2026/08/29BSD-3-ClauseTypeScriptES Module零依赖近 30 天下载 54.6万

Decode Musepack (MPC, SV7 and SV8) audio with libmpcdec WASM

原始使用文档
文档目录7 节
  1. API
  2. decode(src: Uint8Array | ArrayBuffer): Promise<AudioData>
  3. decoder(): Promise<MpcDecoder>
  4. AudioData
  5. Streaming
  6. Measured
  7. License

@audio/decode-mpc

Decode Musepack (MPC) to PCM float samples.
libmpcdec (mirrored at evpobr/libmpc) compiled to a single-file WASM ES module — no side files, loads from any CDN, Node, workers and AudioWorklets.

npm install @audio/decode-mpc

import decode, { decoder } from '@audio/decode-mpc'

let { channelData, sampleRate } = await decode(mpcBytes)

let dec = await decoder()
let head = dec.decode(chunk1)   // synchronous; returns whatever the bytes seen so far allow
let tail = dec.flush()
dec.free()

Decodes both stream generations: SV7 (MP+ magic, 1999–2006 era encoders) and SV8 (MPCK magic, current). The demuxer (container framing, APEv2/ID3v1 tags, seek tables) runs inside libmpcdec itself; this package only feeds it bytes. Mono or stereo, whatever the stream declares. Built with MPC_FIXED_POINT off, so libmpcdec hands back native float samples — no fixed-point requantization step.

API

decode(src: Uint8Array | ArrayBuffer): Promise<AudioData>

Decode a complete stream. Throws if the input never parses as Musepack (no MP+/MPCK magic, or a header that still won't parse after a generous budget).

decoder(): Promise<MpcDecoder>

Streaming decoder: decode(chunk) returns the samples of every complete frame the data seen so far allows, flush() decodes anything a safety margin was withholding at the true end of stream, free() releases WASM memory. errors counts frames abandoned after a bitstream desync (see Streaming below — this stops the decoder, it does not resync and skip).

AudioData

{ channelData: Float32Array[], sampleRate: number }

Streaming

decode(chunk) feeds bytes into a growable buffer inside WASM and retries mpc_demux_init() on every call until the header parses — libmpcdec's mpc_reader callback interface has no "not enough data yet" signal distinct from "end of stream," and a frame decode that runs out of buffered bytes mid-frame leaves the bitstream position permanently desynced (no retry). So frames are only decoded once at least 4352 bytes (MAX_FRAME_SIZE, libmpcdec's own worst-case compressed frame size) are buffered ahead of the reader's cursor — safe for any chunk size, including 1 byte at a time.

What that means in practice differs by version:

  • SV7 streams genuinely progressively. Its header is a fixed ~30 bytes with no forward references, so decoder() starts emitting frames as soon as the first chunk carries that much.
  • SV8 streams keep their seek table near the end of the file — mpcenc can only patch the header's pointer to it once encoding finishes and the final byte offset is known — and libmpcdec reads that table during mpc_demux_init(). In practice an SV8 decoder() buffers (close to) the whole stream before the first frame comes out. decode(chunk) never blocks or throws while this is happening; it just returns nothing until the header resolves.

Either way the input buffer is never discarded (the SV8 seek-table read can jump backward to any earlier offset), so streaming does not save memory for SV8 — only latency-to-first-decode for SV7.

Measured

  • 50,773 bytes WASM (libmpcdec 7d04739, -Oz -flto, single-file ES module).
  • ~86–89 dB SNR vs ffmpeg -i x.mpc -f f32le - on SV8 fixtures generated with mpcenc; 57–58 dB on an independent SV7 sample from the FFmpeg FATE suite (own encode vs. own decode of the exact same bits, so the higher SV8 number just reflects less inter-decoder disagreement, not different codec fidelity).
  • ~1250× realtime (a 0.5 s clip decodes in ~0.4 ms; a 5.8 s clip in ~4.6 ms; Apple M-series, Node 25).

License

ॐ · BSD-3-Clause, matching the bundled libmpcdec.


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

版本与发布记录

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

版本发布日期距今
1.0.0latest2026/08/292 个月前

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

@audio/decode-mpc 是什么?

Decode Musepack (MPC, SV7 and SV8) audio with libmpcdec WASM

如何安装 @audio/decode-mpc?

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

@audio/decode-mpc 支持 TypeScript 吗?

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

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

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

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

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

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

@audio/decode-mpc 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

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

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

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

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