Skip to content
Justin SilverTECHNOLOGY, TRAVEL & EVERYTHING IN BETWEEN
Libraries & Tools
Audio & acousticsTypeScriptnpmLean 4

electroacoustics

Dependency-free TypeScript solvers for low-frequency loudspeaker design, distributed ducts, DSP headroom, and impedance fitting. Certified solvers emit 160-bit dyadic certificates that replay independently inside the Lean 4 kernel.

@0xdoublesharp/electroacoustics v0.2.0 social card showing a continuous-band interval envelope and Lean 4 kernel verification badge

Verification and capability matrix

Every public solver has a written accuracy contract in docs/CONTRACTS.md. The test suite runs 208 tests across 16 files with 100% statement, branch, function, and line coverage. The Lean 4 workspace audits 629 theorems across 17 library modules and 24 checks in ElectroacousticsReplay, allowing only the standard axioms propext, Classical.choice, and Quot.sound.

Verification and capability matrix for @0xdoublesharp/electroacoustics showing all seven solver domains, 160-bit dyadic checks, Lean 4 kernel replays, and ecosystem comparison

From enclosure geometry to a kernel proof

  1. Size and simulate the cabinet

    Pass SI Thiele-Small driver parameters, net volume, air properties, and a sealed, lumped-vented, passive-radiator, or multi-section tapered duct model to createCircuit or sweepCircuit.

  2. Bound continuous headroom across the band

    Run analyzeBandOutputLimit over a closed interval [minHz, maxHz] with analog LR24/BW24 and digital biquad stages. Adaptive interval subdivision tightens around EQ peaks, impedance dips, and duct poles until the gap is within 0.1 dB.

  3. Verify certificates in TypeScript

    Resolved band, duct-tuning, peak-velocity, and impedance-fit results attach JSON-serializable certificates. Independent 160-bit dyadic verifiers check each certificate against the original request and fail closed on tampering.

  4. Replay in the Lean 4 kernel

    Convert any supported JSON certificate to exact binary rationals with the replay scripts and prove the bound inside Lean 4 using decide +kernel. npm run verify:formal tests eight certificates extracted directly from the installed npm archive.

Continuous-band headroom and distributed ducts

Sampled sweeps can miss a narrow filter peak or an interior standing-wave antinode between grid points. On a 51 Hz peaking EQ with Q = 60 and a 20 V RMS amplifier ceiling, a coarse sampled grid overstates the safe input voltage by 36%. analyzeBandOutputLimit encloses every frequency in the band and returns either a certified voltage ceiling with a BandOutputCertificate or an unresolved result listing the remaining spans alongside any partial bounds confirmed by dyadic replay.

Voltage ceiling plot across 30 to 80 Hz showing a 51 Hz Q=60 peaking EQ where a sampled grid overstates safe drive by 36% while interval boxes enclose the continuous ceiling within 0.1 dB

For distributed vents, the solver evaluates cascaded straight, conical, and exponential Webster sections with inlet and outlet corrections, signed junction inertances, and reactive boundary-layer factors. boundDuctPathTuning brackets the first positive pole-free tuning back to DC, and boundDuctPathPeakVelocityRatio bounds the peak particle speed across every section interior and junction.

Two-panel loudspeaker plot comparing sealed and vented small-signal SPL at 2.83 V RMS above the vented single-tone output ceiling with active cone, voltage, and thermal limits

Certify a vented enclosure with DSP

import {
  analyzeBandOutputLimit,
  verifyBandOutputCertificate,
  ventLengthForTuning,
  type CircuitInput,
} from '@0xdoublesharp/electroacoustics'

const driver = {
  fsHz: 25, vasM3: 0.08, qes: 0.45, qms: 8,
  reOhms: 6, leHenries: 0.0007, sdM2: 0.05,
}
const medium = { densityKgM3: 1.2041, soundSpeedMps: 343 }
const areaM2 = 0.012
const volumeM3 = 0.07

const vented: CircuitInput = {
  driver, medium, volumeM3, voltageRms: 2.83,
  leakageQuality: 15, absorptionQuality: 30,
  port: {
    areaM2,
    effectiveLengthM: ventLengthForTuning(areaM2, volumeM3, 35, medium.soundSpeedMps),
    quality: 7,
  },
}

const band = analyzeBandOutputLimit(vented, {
  minHz: 14, maxHz: 120,
  xmaxMeters: 0.012,
  ratedPowerWattsPerDriver: 180,
  maxPortMach: 0.07,
  maxAmplifierVoltageRms: 45,
  filter: {
    highpassHz: 23, highpassType: 'BW24',
    digital: {
      sampleRateHz: 48000,
      stages: [{ kind: 'peaking', frequencyHz: 52, gainDb: 4, q: 2 }],
    },
  },
})

if (band.status === 'resolved' && band.certificate) {
  const valid = verifyBandOutputCertificate(vented, { minHz: 14, maxHz: 120, /* ... */ }, band.certificate)
  console.log(band.safeInputVoltageRms, band.errorBoundDb, valid)
}

Impedance fitting with exact dual-dyadic derivatives

fitDriverImpedance fits six Thiele-Small parameters from paired free-air and added-mass or sealed-box sweeps, and fitEnclosureImpedance fits caller-selected cabinet parameters while holding the driver fixed. At the returned point, 160-bit forward-mode automatic differentiation encloses the exact residuals, Jacobian, projected KKT gradient, and either a preconditioned Gram full-rank proof or a weak-direction witness.

Fits report six explicit statuses: residual-target, stationary, bound-constrained, poorly-identified, stalled, and iteration-limit. Driver fits and sealed, lumped-vented, and passive-radiator enclosure fits replay in Lean 4; distributed-duct fits verify in the 160-bit dyadic TypeScript checker.

Paired free-air and added-mass impedance sweeps with synthetic measurement noise, initial and fitted model curves, and relative fit residuals from 8 to 300 Hz

Install and run formal verification

npm install @0xdoublesharp/electroacoustics

# From a source checkout with Elan installed:
npm run check
npm run verify:formal