@audio/decode-mod

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

Decode tracker modules — MOD, XM, S3M, IT, MPTM and more — with libopenmpt WASM

原始使用文档
文档目录7 节
  1. API
  2. decode(src: Uint8Array | ArrayBuffer, opts?): Promise<Audio…
  3. info(src: Uint8Array | ArrayBuffer): Promise<ModuleInfo>
  4. decoder(opts?): Promise<ModDecoder>
  5. AudioData
  6. Notes
  7. License

@audio/decode-mod

Decode tracker modules — MOD, XM, S3M, IT, MPTM, and everything else libopenmpt reads — to PCM float samples.
libopenmpt compiled to a single-file WASM ES module — no side files, loads from any CDN, Node, workers and AudioWorklets.

npm install @audio/decode-mod

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

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

let meta = await info(modBytes)
// { title, artist, type, typeLong, tracker, message, duration, channels, patterns, orders, instruments, samples }

A tracker module is a small program (samples + patterns + a playback sequence), not raw audio — libopenmpt is the mixer that renders it. Render params follow libopenmpt's public C API (libopenmpt/libopenmpt.h): openmpt_module_create_from_memory2, openmpt_module_read_float_{mono,stereo,quad}, openmpt_module_set_render_param. A module is a whole file, not a stream — there's no meaningful partial parse of a truncated MOD/XM/S3M/IT, so decode() always needs the complete file. repeat_count is fixed at 0 (play once); duration is a render-length cap for songs that loop or whose estimated length is impractically long.

let { channelData } = await decode(bytes, {
  sampleRate: 44100,
  channels: 1,           // mono / stereo / quad (L,R,RL,RR)
  duration: 30,           // seconds — cap for endless/looping songs
  interpolation: 2,       // 0 internal default, 1 hold, 2 linear, 4 cubic, 8 windowed sinc
  stereoSeparation: 150,  // percent, [0,200]
  gain: -6,                // dB
})
ParamDefault
sampleRate48000Output sample rate, Hz
channels21 mono, 2 stereo, 4 quad (L,R,RL,RR)
durationlibopenmpt's estimate, capped at 600sSeconds to render; hard cap for endless/looping songs
interpolation8OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH — 0 internal default, 1 zero-order hold, 2 linear, 4 cubic, 8 windowed sinc (8 taps)
stereoSeparation100Percent, [0,200]
gain—Master gain, dB

API

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

Render a complete module.

info(src: Uint8Array | ArrayBuffer): Promise<ModuleInfo>

Read title/artist/format/duration/channel-and-pattern counts without rendering audio.

decoder(opts?): Promise<ModDecoder>

{ decode(chunk), flush(), free() }. decode(chunk) expects (and renders) a complete file in one call — a module can't be parsed from a partial buffer. flush() returns empty (nothing carries over); free() is a no-op (no WASM state outlives a single decode() call). Matches @audio/decode-qoa's whole-file shape.

AudioData

{ channelData: Float32Array[], sampleRate: number }

Notes

  • MO3 (a separately-compressed OpenMPT container) is not supported: it needs either an external unmo3 or the bundled minimp3/stb_vorbis/miniz fallback decoders, none of which ship here (see build.sh) to keep the WASM small.
  • No volume-ramping/click suppression beyond libopenmpt's own mixer — that's libopenmpt's job, not this package's.
  • Format reference: ProTracker MOD, FastTracker II XM, Scream Tracker 3 S3M, Impulse Tracker IT; libopenmpt's own C API docs.

Use when: playing back tracker-format chiptunes/game music in the browser, or converting a .mod/.xm/.s3m/.it library to PCM/WAV in bulk.


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

License

ॐ · BSD-3-Clause, same as the bundled libopenmpt.

版本与发布记录

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

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

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

@audio/decode-mod 是什么?

Decode tracker modules — MOD, XM, S3M, IT, MPTM and more — with libopenmpt WASM

如何安装 @audio/decode-mod?

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

@audio/decode-mod 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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

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

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