audioJS

@audio/encode-caf

Status calibrated

npm1.3.2licenseMIT

Encode PCM audio samples to CAF (Core Audio Format) LPCM

Overview

Install
Updated
Family
encode, 14 packages under it

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 Uint8Array

Options

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.

Streaming output

stream: true: the header goes out with the first samples, the data chunk size -1 (the CAF spec's "unknown, runs to the end"). After flush(), head() returns the exact header to write over the start of a file. With frames (the exact length, known upfront) the header goes out exact and head() has nothing to add.

License

MIT

ॐ