1D Waveguide Lab — from spring chain to sound

Every parcel of air in the bore is a bead on a chain: mass, connected to its neighbors by the "spring" of gas pressure (p' = B·s, adiabatic bulk modulus playing spring constant). Push the mouthpiece end, a compression wave races down the chain, reflects off the far end, and the standing-wave pattern that survives determines the pitch and harmonic content. The exact same finite-difference update that draws the accordion below is run at audio sample rate to make the sound.
Mental model recap (math ↔ physics ↔ code)

Displacement field ξ(i,t): parcel i's displacement from its rest position. Mass conservation → strain s = -∂ξ/∂x. Adiabatic gas law → p' = B·s (Hooke's law). Newton's law on a slab → ρ₀ξ̈ = -∂p'/∂x = B·ξ'', i.e. ξ̈ = c²ξ'', c = √(B/ρ₀).

Discretize with grid spacing dx = c·dt (Courant number = 1) and the wave equation becomes the exact leapfrog update ξ[i]ₙ₊₁ = ξ[i-1]ₙ + ξ[i+1]ₙ - ξ[i]ₙ₋₁ — no numerical dispersion, and structurally identical to a digital waveguide synth. Boundary conditions: closed end (rigid wall / lips) pins ξ=0; open end (bell) forces ∂ξ/∂x=0 via a mirrored ghost point.

Conical bore: cross-section A(x) ∝ x² measured from the cone's (virtual) apex turns the Webster equation into ξ̈ = c²(ξ'' + (2/x)ξ'). Substituting u=x·ξ makes the extra term vanish exactly — u obeys the plain wave equation, so it gets the same leapfrog update as ξ does above. The mouthpiece sits a small fixed distance from the apex (never at x=0, where the substitution divides by zero); the driven ξ there is scaled by that distance to get the equivalent u, and ξ = u/x is recovered wherever the field needs to act like a real displacement again (the far-boundary reflection, and the radiated-pressure estimate).

What you hear

output waveform (period-triggered)
spectrum — log f, amber ticks = predicted harmonics n·f₁
spectrogram — newest at top, 4 s history; same frequency axis

Geometry → code parameter map

Controls

Readout

Roadmap

Now: cylindrical or conical bore, linear (Hooke's-law) medium, prescribed mouthpiece motion. The cone uses the classic substitution u=x·ξ (x measured from the cone's virtual apex), which turns the Webster horn equation back into the plain wave equation for u — same exact leapfrog update, just solved for u instead of ξ, then divided back by x. No closed-form predicted-f₁ for the cone (its resonances solve a transcendental equation), so the harmonic overlay/snap is cylindrical-only for now.

Next: a general Webster horn equation for arbitrary A(x) (e.g. a real bell-flare profile) needs the full variable-coefficient stencil and loses the exact/dispersion-free property this sim currently has everywhere else.