{"_id":"@audio/decode-mpc","name":"@audio/decode-mpc","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@audio/decode-mpc","version":"1.0.0","description":"Decode Musepack (MPC, SV7 and SV8) audio with libmpcdec WASM","type":"module","main":"decode-mpc.js","types":"decode-mpc.d.ts","exports":{".":"./decode-mpc.js","./audio":{"types":"./audio.d.ts","default":"./audio.js"},"./package.json":"./package.json"},"publishConfig":{"access":"public"},"scripts":{"build":"bash build.sh","prepack":"npm run build","test":"node test.js"},"devDependencies":{"tst":"^9.2.2"},"engines":{"node":">=18"},"keywords":["mpc","musepack","mp+","mpck","sv7","sv8","audio","decode","decoder","wasm","libmpcdec"],"license":"BSD-3-Clause","author":{"name":"audiojs"},"homepage":"https://github.com/audiojs/decode/tree/main/packages/decode-mpc","repository":{"type":"git","url":"git+https://github.com/audiojs/decode.git","directory":"packages/decode-mpc"},"bugs":{"url":"https://github.com/audiojs/decode/issues"},"audio":"./audio.js","sideEffects":false,"funding":"https://github.com/sponsors/audiojs","gitHead":"c227363046dc3a0308c95ee112f22795c0ac04ca","_id":"@audio/decode-mpc@1.0.0","_nodeVersion":"25.9.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-oRHDBSHNW8sDjz0QvqlF6gHRh4Gz0zgwqLxc0MBE9hLOBlwshiJ4LuA7XKasRxF3V/zPgYTLOQHhUaWwor7e4w==","shasum":"6d95853e1d20c1ddcbdaacca769864a8617e37ac","tarball":"https://registry.npmjs.org/@audio/decode-mpc/-/decode-mpc-1.0.0.tgz","fileCount":9,"unpackedSize":67336,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDj5P23ihMF4iQ/s2zzHo7tO3DJLRXYLqfNHM/HiI0ISgIgQfCn4iF9iGHvAOeEacvIRrGnweR52uz3PuZRgqVNTJw="}]},"_npmUser":{"name":"dy","email":"df.creative@gmail.com"},"directories":{},"maintainers":[{"name":"jamen","email":"jamenmarz@gmail.com"},{"name":"dfcreative","email":"df.creative@gmail.com"},{"name":"dy","email":"df.creative@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/decode-mpc_1.0.0_1787966907931_0.09933900797482931"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-29T01:28:27.771Z","1.0.0":"2026-08-29T01:28:28.071Z","modified":"2026-08-29T01:28:28.366Z"},"maintainers":[{"name":"jamen","email":"jamenmarz@gmail.com"},{"name":"dfcreative","email":"df.creative@gmail.com"},{"name":"dy","email":"df.creative@gmail.com"}],"description":"Decode Musepack (MPC, SV7 and SV8) audio with libmpcdec WASM","homepage":"https://github.com/audiojs/decode/tree/main/packages/decode-mpc","keywords":["mpc","musepack","mp+","mpck","sv7","sv8","audio","decode","decoder","wasm","libmpcdec"],"repository":{"type":"git","url":"git+https://github.com/audiojs/decode.git","directory":"packages/decode-mpc"},"author":{"name":"audiojs"},"bugs":{"url":"https://github.com/audiojs/decode/issues"},"license":"BSD-3-Clause","readme":"# @audio/decode-mpc\n\nDecode Musepack (MPC) to PCM float samples.<br>\n[libmpcdec](https://svn.musepack.net/libmpc/) (mirrored at [evpobr/libmpc](https://github.com/evpobr/libmpc)) compiled to a single-file WASM ES module — no side files, loads from any CDN, Node, workers and AudioWorklets.\n\n[![npm install @audio/decode-mpc](https://nodei.co/npm/@audio/decode-mpc.png?mini=true)](https://npmjs.org/package/@audio/decode-mpc/)\n\n```js\nimport decode, { decoder } from '@audio/decode-mpc'\n\nlet { channelData, sampleRate } = await decode(mpcBytes)\n\nlet dec = await decoder()\nlet head = dec.decode(chunk1)   // synchronous; returns whatever the bytes seen so far allow\nlet tail = dec.flush()\ndec.free()\n```\n\nDecodes 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.\n\n## API\n\n### `decode(src: Uint8Array | ArrayBuffer): Promise<AudioData>`\n\nDecode 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).\n\n### `decoder(): Promise<MpcDecoder>`\n\nStreaming 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).\n\n### `AudioData`\n\n```ts\n{ channelData: Float32Array[], sampleRate: number }\n```\n\n## Streaming\n\n`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.\n\nWhat that means in practice differs by version:\n\n- **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.\n- **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.\n\nEither 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.\n\n## Measured\n\n- 50,773 bytes WASM (libmpcdec `7d04739`, `-Oz -flto`, single-file ES module).\n- ~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).\n- ~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).\n\n## License\n\n[ॐ](https://github.com/krishnized/license/) · [BSD-3-Clause](./LICENSE), matching the bundled [libmpcdec](./LICENSE.libmpcdec).\n\n---\n\nPart of [@audio/decode](https://github.com/audiojs/decode) — the decode family umbrella.\n","readmeFilename":"README.md","_rev":"1-80e90b71c449868a99a16042ba7aa723"}