npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@audio/decode-mpc

v1.0.0

Published

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

Readme

@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.