# PhysVox source code (plain text) A physical simulation of the human singing voice. Air pressure from simulated lungs drives self-oscillating vocal folds; sound travels through acoustic models of the airway, nose and lips. Every output sample is computed by the simulation. Included: the simulator, kernels, inverse network and a demo. Not included: the fitting pipeline, training data, network weights and the song's control tracks, so the Rick Astley vocal cannot be rebuilt from this code alone. Article: https://jonathanc.net/agents/physvox/ Browse (for people): https://jonathanc.net/agents/physvox/source/ Written by Claude Opus 5.5 (Claude Code), with direction from Jonathan Chang, November 2026. License: MIT (see LICENSE). Copyright (c) 2026 Jonathan Chang. ## How to get it Every file below is plain text at the listed URL. Keep the relative paths when saving them (the package imports itself as `physvox`). ## Run the demo Requires an NVIDIA GPU with CUDA 12 and Python 3.12. Save `pyproject.toml`, `examples/sing_vowel.py` and the `physvox/` files (at minimum `sim.py`, `params.py`, `kernel.cu`, `kernel_warp.cu`), then: uv sync uv run python examples/sing_vowel.py # writes sing_vowel.wav, prints the sung pitch per note ## Files ### Start here - [examples/sing_vowel.py](https://jonathanc.net/agents/physvox/source/examples/sing_vowel.py) (53 lines): Standalone demo: sings five notes on a gliding vowel with closed-loop pitch; needs no data. With --voice it uses a fitted voice file. - [physvox/voices/rick_n2A.json](https://jonathanc.net/agents/physvox/source/physvox/voices/rick_n2A.json) (218 lines): The constants fitted to Rick Astley's vocal (the values marked “fitted” in the article), as differences from params.py. The per-frame control tracks, training data and network weights are not published. - [physvox/sim.py](https://jonathanc.net/agents/physvox/source/physvox/sim.py) (151 lines): Python driver for the CUDA kernel: builds inputs, runs a batch of voices, returns audio and traces. - [physvox/params.py](https://jonathanc.net/agents/physvox/source/physvox/params.py) (208 lines): Every physical parameter (SI units) with its default and meaning; shared by Python and the kernel. ### The simulator - [physvox/kernel.cu](https://jonathanc.net/agents/physvox/source/physvox/kernel.cu) (994 lines): Reference CUDA kernel, one thread per voice: lungs, subglottal line, 8-slice body-cover folds, unsteady Bernoulli glottal flow, turbulence sources, vocal-tract line with yielding walls, orifices, nasal line and sinus, side branches, lip and nostril radiation. - [physvox/kernel_warp.cu](https://jonathanc.net/agents/physvox/source/physvox/kernel_warp.cu) (1148 lines): The same physics with one 32-lane warp per voice (the default; bit-identical output to kernel.cu). - [physvox/room.py](https://jonathanc.net/agents/physvox/source/physvox/room.py) (207 lines): Image-source room between mouth and microphone (used only for the wet comparison path). ### Learned control - [physvox/learn/__init__.py](https://jonathanc.net/agents/physvox/source/physvox/learn/__init__.py) (2 lines): Package note: every output sample still comes from the kernel. - [physvox/learn/layout.py](https://jonathanc.net/agents/physvox/source/physvox/learn/layout.py) (22 lines): Channel layout of the control frames: airway areas, closures, velum, fold opening, pressure, pitch. - [physvox/learn/net.py](https://jonathanc.net/agents/physvox/source/physvox/learn/net.py) (134 lines): Inverse network (dilated residual convolutions + bidirectional GRU): log-mel + pitch -> control frames; also the forward stand-in network. ### Analysis and fitting helpers - [physvox/loss.py](https://jonathanc.net/agents/physvox/source/physvox/loss.py) (134 lines): Batched spectral loss on GPU: harmonic amplitudes, inter-harmonic floor, ERB bands. - [physvox/artifacts.py](https://jonathanc.net/agents/physvox/source/physvox/artifacts.py) (387 lines): Detectors for clicks, breaks and other artefacts in a render. - [physvox/hnm.py](https://jonathanc.net/agents/physvox/source/physvox/hnm.py) (210 lines): Harmonic + noise analysis (diagnostics only; never used to produce audio). - [physvox/noisefeat.py](https://jonathanc.net/agents/physvox/source/physvox/noisefeat.py) (158 lines): Features separating the voice's own noise from reverberation. - [physvox/space.py](https://jonathanc.net/agents/physvox/source/physvox/space.py) (186 lines): Search space mapping bounded physical quantities to kernel inputs (vowel fits). - [physvox/render.py](https://jonathanc.net/agents/physvox/source/physvox/render.py) (66 lines): Render one candidate with traces and write diagnostic files. ### 3D acoustic solver (checks the 1D tract model) - [physvox/fdtd3d/__init__.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/__init__.py) (3 lines): Package note. - [physvox/fdtd3d/api.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/api.py) (159 lines): High-level driver: impulse runs, transfer functions, impulse responses. - [physvox/fdtd3d/solver.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/solver.py) (484 lines): Staggered-grid 3D time-domain solver (CuPy). - [physvox/fdtd3d/kernels.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/kernels.py) (198 lines): CUDA kernels for the 3D update equations. - [physvox/fdtd3d/geometry.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/geometry.py) (69 lines): Test tubes and scene generators. - [physvox/fdtd3d/tract.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/tract.py) (423 lines): Area function -> 3D airway inside a head. - [physvox/fdtd3d/voxel.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/voxel.py) (162 lines): Voxelisation of implicit geometry. - [physvox/fdtd3d/wall.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/wall.py) (127 lines): Locally reacting wall models. - [physvox/fdtd3d/response.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/response.py) (100 lines): Transfer functions, formant picking, band-limited impulse responses. - [physvox/fdtd3d/tl1d.py](https://jonathanc.net/agents/physvox/source/physvox/fdtd3d/tl1d.py) (122 lines): 1D chain-matrix reference for the 3D solver. ### Project - [pyproject.toml](https://jonathanc.net/agents/physvox/source/pyproject.toml) (27 lines): Python dependencies (Python 3.12, CuPy for CUDA 12, PyTorch). - [LICENSE](https://jonathanc.net/agents/physvox/source/LICENSE) (21 lines): MIT License.