default

Sun/NeXT audio (.au / .snd) file header encoding and decoding.

Examples

Round-trip a 16-bit stereo header

import { assertEquals } from "@std/assert";
import { auHeader, AU_ENCODING, AU_MAGIC } from "@binstruct/au";

const coder = auHeader();
const header = {
  magic: AU_MAGIC,
  dataOffset: 24,
  dataSize: 1024,
  encoding: AU_ENCODING.LINEAR_16,
  sampleRate: 44100,
  channels: 2,
  annotation: new Uint8Array(0),
};

const buffer = new Uint8Array(24);
const written = coder.encode(header, buffer);
const [decoded, read] = coder.decode(buffer);

assertEquals(written, 24);
assertEquals(read, 24);
assertEquals(decoded.sampleRate, 44100);
assertEquals(decoded.channels, 2);
assertEquals(decoded.encoding, AU_ENCODING.LINEAR_16);

Functions

f
auHeader(): Coder<AuHeader>

Creates a coder for a Sun/NeXT .au file header.

Interfaces

Variables

v
AU_DATA_SIZE_UNKNOWN: 4294967295

Sentinel dataSize meaning the sample count is not recorded in the header and the audio runs to the end of the file.

v
AU_ENCODING: { MULAW_8: number; LINEAR_8: number; LINEAR_16: number; LINEAR_24: number; LINEAR_32: number; FLOAT_32: number; FLOAT_64: number; ALAW_8: number; }

Encoding values used by the .au encoding field.

v
AU_HEADER_SIZE: 24

Size in bytes of the fixed portion of an .au header, before the annotation field. Also the minimum legal value of dataOffset.

v
AU_MAGIC: 779316836

The .au magic number — the ASCII bytes .snd read as a big-endian 32-bit integer (0x2e736e64).