audioJS

@audio/encode-wavpack

Status calibrated

npm1.0.2licenseBSD-3-Clause

Encode PCM audio samples to WavPack (.wv) with libwavpack WASM

Overview

Install
Updated
Family
encode, 14 packages under it

Encode PCM audio samples to WavPack (.wv)

import wavpack from '@audio/encode-wavpack'

libwavpack (the reference WavPack 5 implementation, David Bryant) compiled to a single-file WASM ES module, encode-only (no file-input/decode side, no DSD — a leaner build than the full library). Lossless by default; hybrid/lossy on request. Block boundaries are decided purely by cumulative sample count, so output is byte-identical no matter how the input is chunked across encode() calls.

let enc = await wavpack({ sampleRate: 48000, channels: 2, bitDepth: 16 })
let chunk = enc.encode(channelData)  // → Uint8Array (any WavPack blocks this chunk completed)
let tail = enc.flush()               // → Uint8Array (final block + APEv2 tag; frees the encoder)
// concatenate chunk + tail for the complete .wv file
Option Default
sampleRate — Required
channels 1
bitDepth 16 16, 24, 32 (integer) or 'float' (32-bit IEEE-754)
hybrid false Bitrate-per-sample (< 24, e.g. 4 ≈ 4 bits/sample) or kbps (≥ 24) — enables lossy hybrid mode. No .wvc correction file.
extraProcessing 0 0-6, libwavpack's extra-processing level (xmode)
highQuality false
veryHigh false Implies highQuality
fast false
blockSamples library default Fixed WavPack block size, 16-131072 samples
meta — APEv2 tags: title, artist, album, albumartist, composer, genre, year, track, disc, comment, copyright, isrc, publisher, software, lyrics, pictures: [{mime, description, data}] (written as Cover Art (Front))

Streaming

let enc = await wavpack({ sampleRate: 44100, channels: 1, bitDepth: 16 })
let a = enc.encode(chunk1)  // → Uint8Array (blocks completed so far, maybe empty)
let b = enc.encode(chunk2)
let c = enc.flush()         // → Uint8Array (final block + tag)
// complete file = concat(a, b, c)

encode() returns whatever WavPack blocks were completed by that call — often nothing, since a block only closes once it has enough samples (blockSamples, or a size the library picks from the sample rate). flush() finalizes the last partial block, writes the APEv2 tag if meta was given, and frees the encoder — it must be the last call.

License

ॐ · BSD-3-Clause, inherited from the bundled libwavpack.