# chromaprint-wasm

WASM bindings for [rusty-chromaprint](https://github.com/darksv/rusty-chromaprint). Uses preset test2 (AcoustID/fpcalc compatible).

## Build

```bash
# Install wasm-pack if needed: cargo install wasm-pack
wasm-pack build --target web
# Or for Node: wasm-pack build --target nodejs
```

Output in `pkg/`: `.wasm`, `.js` glue, and (with wasm-pack) TypeScript definitions.

## API (from JS)

- **`new Fingerprinter()`** – create a fingerprinter
- **`.start(sampleRate, channels)`** – e.g. `44100`, `1` or `2`
- **`.consume(samples)`** – `samples` is an `Int16Array` (interleaved if stereo)
- **`.finish()`** – call when all samples have been fed
- **`.getFingerprint()`** – returns `Uint32Array` (raw)
- **`.getCompressedFingerprint()`** – returns base64 string (AcoustID format)

- **`fingerprintFromSamples(sampleRate, channels, samples)`** – one-shot; returns `{ raw: Uint32Array, compressed: string }`

- **`matchFingerprints(raw1, raw2)`** – both `Uint32Array`; returns array of `{ start1, end1, start2, end2, duration, score }` (times in seconds)

## Audio input

Decode in the browser (e.g. `decodeAudioData`), get channel data as Float32, convert to i16 (e.g. `samples[i] = Math.max(-32768, Math.min(32767, channelData[i] * 32768))`), then pass as `Int16Array` to `consume()` or `fingerprintFromSamples`.
