audio

@audio/decode-ac31.0.0

Decode AC-3

Decode AC-3 (Dolby Digital) audio with liba52 WASM

Status
calibrated
Updated
Family
decode, 24 packages under it
Category
codecs
Licence
GPL-2.0-or-later
Bundles
liba52
Dependencies
none
Downloads
593,386 last month
Tests
at least 88 in audiojs/decode's CI, passed at 58c36d8,

Decode AC-3 (Dolby Digital) to PCM float samples.
liba52 compiled to a single-file WASM ES module — no side files, loads from any CDN, Node, workers and AudioWorklets.

Superseded by @audio/decode-eac3, which decodes AC-3 as well as E-AC-3 with FFmpeg's LGPL-2.1-or-later decoder. @audio/decode and its container packages use that one; this GPL-2.0-or-later package stays published for those who depend on it.

import decode, { decoder } from '@audio/decode-ac3'

let { channelData, sampleRate } = await decode(ac3Bytes)

let dec = await decoder()
let head = dec.decode(chunk1)   // synchronous; partial frames carry over
let tail = dec.flush()
dec.free()

Input is a raw AC-3 frame stream (.ac3, or the frames a container demuxer extracts — @audio/decode-mp4, @audio/decode-webm and @audio/decode-avi route their AC-3 tracks here). The stream's own layout is kept, up to 5.1; channels come out in WAV order: FL, FR, FC, LFE, BL, BR (surround-only or mono as present). Output level is full scale, no dialnorm applied.

E-AC-3 (Dolby Digital Plus) is a different codec and is not decoded.

API

decode(src: Uint8Array | ArrayBuffer): Promise<AudioData>

Decode a complete stream.

decoder(): Promise<AC3Decoder>

Synchronous streaming decoder: decode(chunk) returns the samples of every complete frame in the data so far, flush() drops a trailing partial frame, free() releases WASM memory. errors counts frames that failed to decode.

AudioData

{ channelData: Float32Array[], sampleRate: number }

License

ॐ · GPL-2.0-or-later, inherited from the bundled liba52.