# MoonBit audio library and wasm support matrix

Verified on 2026-11-26 with:

- `moon 0.1.20261119`
- `moonc v0.10.22+124d61d05`
- `moon search` against mooncakes.io
- an isolated probe module per package: `moon add <pkg>` followed by
  `moon check --target wasm` and `moon check --target wasm-gc`. Dependencies are
  compiled even when the probe package does not call them, so a passing check
  means every package in that dependency graph compiles for the target.

`wasm` below means the linear-memory WebAssembly backend, not `wasm-gc`.

## wasm-compatible packages

| Package | Decode formats | Encode formats | wasm | wasm-gc | Notes |
| --- | --- | --- | --- | --- | --- |
| `Sakuraqwq1/moonaudio` | WAV (PCM/float, μ-law/A-law, extensible, RIFX/RF64), AIFF/AIFC, AU, native FLAC | WAV, AIFF/AIFC, AU | yes | yes | Pure MoonBit, no external packages; unified `AudioBuffer` in f64 |
| `enanandesu/mp3` | MPEG-1/2/2.5 Layer III | — | yes | yes | Interleaved f32 at the original sample rate |
| `LL728/moonvorbis` | Ogg Vorbis | 16-bit WAV helper | yes | yes | Streaming `push_page`; metadata |
| `LL728/moonopus` | Ogg Opus | — | yes | yes | **CELT-only, mono, fullband config 28–31**; SILK/hybrid/stereo unsupported |
| `Xcsa-ee/moonflac` | native FLAC | — | yes | yes | RFC 9639; 4–32 bps; seek; metadata; streaming |
| `0717lee/moonflac` | native FLAC | native FLAC, Ogg FLAC | yes | yes | Works on native/JS/wasm-gc/wasm |
| `Ridge-Lab/moonwavkit` | WAV (PCM + IEEE float) | WAV | yes | yes | Input is `Array[Int32]`, not `Bytes` |
| `bw448/moon-wav` | WAV (PCM 8/16/24/32 + float) | WAV | yes | yes | Analysis and effects included |
| `cp15695540483/moontag` | — | — | yes | yes | Tags: ID3v2, APEv2, Vorbis Comment, MP4 ilst |
| `matrix486/moonflactag` | — | — | yes | yes | FLAC tags, pictures, metadata rewriting |
| `Juwan-Hwang/moon-certified/audio_processing/wav` | WAV | WAV | yes | yes | Subpackage of a larger module |
| `moonbitstack/moonmedia` | MP4/ISO BMFF, MPEG-TS, HLS, DASH containers | — | yes | yes | Containers only, no audio codec decode |
| `zmjknn/moon_sfx` | WAV | WAV | yes | yes | Also a synthesizer |
| `milkbobo/ffmpeg-moonbit/libavformat` | broad: AAC, MP3, FLAC, Opus, Vorbis, ALAC, WMA, AMR, DTS, AC-3, APE, TTA, WavPack, DSD, … | broad | yes | yes | No root package; import `libavformat`. Pure MoonBit FFmpeg port; LGPL-2.1-or-later; source-only + patent notice |

## Packages that cannot be used under wasm

| Package | Reason |
| --- | --- |
| `Milky2018/moon_rodio` | `supported_targets = "native"`; also links FFmpeg on Linux/Windows |
| `NoahLiu/ffmpeg-mbt` | `src/moon.pkg` has `supported_targets = "native"`; links system FFmpeg |
| `WangYF0829/moonmux` | `supported_targets = [ "native", "wasm-gc", "js" ]`; no `wasm` (wasm-gc passes) |
| `trkbt10/isobmff` | published with legacy `moon.mod.json`; current toolchain refuses to install |
| `CAIMEOX/midi` | published with legacy `moon.mod.json`; current toolchain refuses to install |
| `mizchi/audio` | published with legacy `moon.mod.json`; current toolchain refuses to install |

## Coexistence

A single probe module added all 14 wasm-compatible packages above. MoonBit
resolved `moonbitlang/x` to one version (`0.5.7` at probe time) and both
`moon check --target wasm` and `moon check --target wasm-gc` passed. This is the
basis for the per-backend package layout in this repository.

## Current `mbaudio` mapping

| `AudioFormat` | Backend | wasm status |
| --- | --- | --- |
| `Wav`, `Aiff`, `Au`, `Flac` | `backend/moonaudio` | tested |
| `Mp3` | `backend/mp3` | tested |
| `OggVorbis` | `backend/vorbis` | tested |
| `OggOpus` | `backend/opus` | tested (CELT-only mono) |
| `Aac` (raw ADTS) | `backend/ffmpeg` via `libavcodec` | tested; optional `full` package |
| `Mp4` (AAC or ALAC in M4A/MP4) | `backend/ffmpeg` via `libavformat` | tested; optional `full` package |
| `OggFlac` | `backend/ffmpeg` via `av_ogg_flac_open` + FLAC decoder | tested; `all` returns `UnsupportedFormat`, `full` routes to FFmpeg |

`backend/ffmpeg` is intentionally a separate package so the lightweight `all`
package does not link libavcodec/libavformat. The module still lists
`milkbobo/ffmpeg-moonbit` as a dependency, so consumers download it; importing
`all` simply does not pull it into the build. `full` uses the lightweight
backend first and falls back to FFmpeg, which also upgrades stereo Opus. The
generic facade wires AAC, Opus, and 16-bit PCM; ADTS AAC, ALAC in M4A/MOV, and
Ogg FLAC use dedicated paths in `backend/ffmpeg`.

Every format above is also available through the unified buffered
`AudioDecoder` interface: `@all.decoder(bytes)` and `@full.decoder(bytes)`
return the same `info()` / `next(max_frames)` / `seek(frame)` API.

`@all.streaming_decoder` adds a push-based interface. MP3 and Ogg Vorbis are
truly incremental; WAV/AIFF/AU/FLAC/Ogg Opus use the buffered fallback and
produce audio only after `finish`. `@metadata.read` reads ID3v2/APEv2, Vorbis
Comment, and MP4 ilst tags through `cp15695540483/moontag`.
