Numeric kernel of atools: FFT, STFT codec and phase reconstruction, compiled to WASM for direct browser use
moon/ source (this directory) → scripts/moon.ts → moon/_build/…/dsp.wasm
app/lib/dsp.ts host loader: kernelUrl() folds the asset path to an absolute URL, then fetch,
handshake, typed-view slicing| Layer | Lifetime | Where | Notes |
|---|---|---|---|
| Plan tables | process, per window size | plan.mbt | read-only: bit-reversal, twiddles, Hann window. Cached by win, never moved. |
| Session slots | one long computation | session.mbt | fixed-size workspace + the plan tables it binds to. Pool of max_slots (6) — you must return it. |
| Job arenas | one job | arena.mbt | a job owns its arrays: one Double buffer + one Byte segment, addressed by a handle. |
| File | Role |
|---|---|
| engine.mbt | ABI version + the boot-time probe that proves the host/guest addressing convention |
| plan.mbt | per-window tables: bit reversal, twiddles, Hann window |
| session.mbt | session slot pool |
| pair.mbt | two real transforms packed into one complex transform (halves the FFT count of RTISI) |
| fft.mbt | complex FFT (dsp_fft, plus inverse for tests) and real_ifft — the one-sided → conjugate-symmetric inverse that the host's exact path and RTISI's inner loop both call |
| arena.mbt | job arenas (variable-size, one per job) |
| rtisi.mbt | RTISI-LA phase reconstruction (the whole iterative loop) |
| pghi.mbt | PGHI phase initialisation: the magnitude spectrum in, a phase guess out |
| stub.mbt | the barcode "stub" at the bottom of a spectrogram: pure integer encode/decode |
When an exported function returns a FixedArray, the integer the host receives is the address of its data area. The reverse does not hold — a Float64Array passed in from the host arrives as a bare i32 and will read out of bounds.
bun run build:wasm # compile this directory → moon/_build/…/dsp.wasm (--force = full rebuild)
bun run test:kernel # white-box tests: moon test --release --deny-warn --target wasm
bun run bench:kernel # kernel benchmarks: moon bench --release --deny-warn --target wasm
bun run moon:ports # moon check --target js / native (proves "standard library only")fn pghi_open(frames : Int, bins : Int, win : Int, hop : Int, gamma : Double, tol_hi : Double, tol_lo : Double) -> Intfn rtisi_open(frames : Int, bins : Int, win : Int, hop : Int, samples : Int, iters : Int, has_warm : Int, has_band : Int, budget : Double) -> IntInstall
Download zipNumeric kernel of atools: FFT, STFT codec and phase reconstruction, compiled to WASM for direct browser use