@audio/encode-caf
v1.1.2
Published
Encode PCM audio samples to CAF (Core Audio Format) LPCM
Readme
@audio/encode-caf
Encode PCM audio samples to CAF (Core Audio Format) LPCM. Pure JS — no WASM, no native bindings, works in both node and browser.
CAF supports files beyond WAV's 4 GB limit and stores 16-bit integer or 32-bit float LPCM in big-endian byte order.
import caf from '@audio/encode-caf';
const encoder = await caf({ sampleRate: 44100 });
encoder.encode(channelData); // buffer PCM
const buffer = encoder.flush(); // → complete CAF file as Uint8ArrayOptions
| Option | Default | Description |
|--------|---------|-------------|
| sampleRate | — | Sample rate (required) |
| bitDepth | 16 | 16 (int) or 32 (float) |
Streaming
const encoder = await caf({ sampleRate: 48000, bitDepth: 32 });
encoder.encode(chunk1);
encoder.encode(chunk2);
const file = encoder.flush(); // → Uint8Array (complete CAF file)
encoder.free();Input is Float32Array[] — one array per channel. Big-endian interleaving handled automatically.
License
ॐ

