/ simulated_instruments / aerophone
Sign in
simulated_instruments / aerophone
aerophone / README.md
8.5 KBPreviewCodeBlameHistoryRaw

aerophone#

2D wind instruments simulated as compressible air flow in the browser. A lattice Boltzmann solver (D2Q9) on WebGPU carries both the flow in the instrument and the sound it radiates into free space; a listener probe records pressure, and the recording is played back at real speed. The simulation runs slower than real time (see Speed).

npm install
npm run dev
npm run check   # tsc

Status#

Steps 1-3: free-space sound; walls, a blown mouth and a paint editor; a listener with record and playback. Presets: Stopped pipe (the default; a flue pipe with a closed end that sounds a steady, nearly pure tone, on a 448 × 128 grid cropped around it), Jet (a 10-cell windway blowing into open space) and Edge tone (the same jet hitting a 30-degree wedge 30 cells downstream), both on 512 × 256, as is Empty. Each preset sets its grid size and listener position. Tools: Pulse (click for a pressure pulse), Wall, Erase, Mouth (with a blowing direction), Listener (click or drag the white ring). Views: Combined (acoustic pressure with vorticity overlaid), Acoustic, Pressure, Vorticity, Speed. Blow ramps the mouth to the set speed, and Stop blowing back to zero, along a raised cosine lasting the Attack time (default 40 ms of simulated time). The ramp is evaluated every step on the GPU (a step counter ping-pongs between two words, selected by the bind group's parity), so it does not jump at frame boundaries; changing Speed while blowing also ramps.

Record, Play, Download WAV: the listener records its density fluctuation every step (on the GPU, up to 2^22 steps, about 7 s of sound at dx = 1 mm). On stop, the recording is resampled to 48 kHz (windowed sinc, cutoff 0.45 of the lower rate), high-passed at 20 Hz, and shown as a waveform and a spectrum (log frequency, 80 dB range, strongest peak marked with its note). Playback and the WAV are normalized to 0.9 peak; the level in Pa is reported. Levels are 2D levels (cylindrical spreading, 1/sqrt(r)), not comparable to 3D.

Planned: pitch versus pipe length, open pipes.

Model#

Checks (512 × 256)#

Speed#

Measure with aerophone.bench() in the browser console (pause first): it runs 30,000 steps without drawing and reports MLUPS and how many times slower than real time the simulation runs at the current dx.

On the laptop's Iris Xe, about 1350 MLUPS (run-to-run variation about 10%, likely thermal). At dx = 1 mm the stopped pipe (448 × 128) runs 25 times slower than real time, and the 512 × 256 presets 55 times slower. Before these changes the app ran the stopped pipe on 512 × 256 at about 85 times slower than real time. The gains:

Storing populations as 16-bit floats might gain about 1.5 times more but could add audible rounding noise to the quiet acoustic field; it is not tried. For watching waves, a few steps per frame is right; producing audio wants the maximum.

↑↓ move↵openescclose