DSP & Cleanroom IP
Inside QuaAudio's reversible 3-shear IntMDCT, 6-stage blank elision, QAA-Spatial binaural VBR, 3-stream Lazy LZ77 + rANS, and Cleanroom provenance.
QuaAudio (@quajs/quaaudio / quaaudio) is an original cleanroom implementation derived from first-principles mathematics and classical public-domain literature. It contains zero third-party codec libraries, zero copied tables, and zero patent-encumbered mechanisms (see CLEANROOM.md).
1. Deterministic reversible IntMDCT (lossless)
Instead of running time-domain LPC alone, mode: 'lossless' defaults to an exact reversible Integer Lapped Cosine Transform (IntMDCT):
- 3-shear Givens lifting: Each rotation is quadrant-normalized into (guaranteeing shear multipliers ) and factored into three integer triangular shear steps, guaranteeing algebraic reversibility: .
- Deterministic
Q24polynomial trigonometry: Twiddle rotations evaluate fixed-pointQ24integer polynomials oni64, eliminating platformlibmdivergence acrossx86_64,aarch64, andwasm32.
Multi-stage blank and redundancy elision
Before entropy coding, each lossless cluster passes through deterministic compaction stages evaluated by real compressed byte cost:
- Silence trimming & zero clusters: Leading/trailing digital silence collapses into
u64header counters; silent mid-stream clusters emitCLUSTER_FLAG_ALL_ZERO. - Reversible Mid/Side lifting: Computes , and elides zero Side channels (common in centered dialogue recordings) in 1 bit.
- LSB zero bitplane stripping & 32-band mask: Strips unused zero LSB planes and omits completely empty spectral bands.
- Per-channel mode competition: Chooses the smallest compressed representation across Direct
IntMDCT(CH_MODE_SPECTRAL), 2-tap Pre-EmphasizedIntMDCT(CH_MODE_PREEMPH_SPECTRAL), and Levinson-Durbin Order-8 IntegerLPC(CH_MODE_WAVE_DELTA). - Spectral prediction & micro-tuplet packing: Applies integer backward/forward
AR(2)sinusoidal predictors and pitch-warpedLag-2, elides all-zero residual bands, and packs low-magnitude residuals as Base-3 quintets / Base-5 triplets.
2. Full-bandwidth psychoacoustics & QAA-Spatial (VBR)
With mode: 'lossy' and a configurable targetRatio:
- Adaptive Princen-Bradley TDAC switching: Combines
2048-sample Long windows (FRAME_SAMPLES = 1024) and8 × 256Short transient windows (SHORT_SAMPLES = 128) connected via aliasing-free bridge windows (). - Full Nyquist bandwidth: Analytical Bark/Terhardt simultaneous masking and
< 10 kHztemporal post-masking leave10–24 kHzair bands unmasked, paired with energy-conserving coherent HF fine-structure restoration to eliminate metallic "birdies". - Binaural Spatial Stereo (
QAA-Spatial):- Locks exact Mid/Side phase below
2.6 kHzto preserve Interaural Time Difference (ITD); - Delta-codes Gram-Schmidt orthogonalized panning (
alpha) and orthogonal diffuse Side energy (ortho_rms) above2.6 kHzto preserve both Interaural Level Difference (ILD) and Interaural Coherence (IC) without collapsing ambient width to mono.
- Locks exact Mid/Side phase below
- Global two-pass Lagrangian bisection: Solves
q_dbto match the user-requested compression ratio closely.
3. 3-stream demux, Lazy LZ77 + rANS & .qaab solid banks
Both standalone .qaa clusters and cross-track .qaab solid chunks (512 KiB default structured budget, 1 MiB LZ77 window) split structured syntax from raw thermal remainder bits:
s0(meta/ctrl): Headers, predictor choices, band activity masks, and scale parameters;s1(quot): Golomb-Rice quotients;s2(micro): Base-3 quintet and Base-5 triplet streams;rem: Uniform Golomb-Rice remainder bits (stored unpolluted outside LZ77/rANS).
Each structured stream is compressed using 1-step Lazy LZ77 with a 3-slot repeat-offset stride LRU (rep0, rep1, rep2) followed by multi-context 32-bit rANS (including 8-bucket logarithmic mag_ctx8). Across tracks in .qaab, QuaAudio extracts 32-band Bark spectral fingerprints, orders tracks via Greedy Nearest-Neighbor TSP within (mode, channels, sample_rate) groups, and optionally trains a shared 256-entry LBG spectral envelope codebook so voices and instruments with matching timbre sit adjacent inside the 1 MiB dictionary.