Webtar Simulation Documentation
Physics Model
The core simulation solves the wave equation:
utt=c2uxx−2σut
Where:
- u(x,t) is the displacement of the string.
- c is the wave speed.
- σ is the damping coefficient.
Discretization
The string is discretized into N segments. The update equation for each point i at time step n+1 is:
uin+1=(2−2C2)uin+C2(ui+1n+ui−1n)−uin−1
Where C is the Courant number (C=cΔt/Δx).
This method accurately reproduces physical phenomena such as:
- Traveling Waves: Excitation creates two pulses traveling in opposite directions.
- Reflections: Waves invert upon reflection at fixed boundaries (bridge/nut).
- Interference: Standing waves emerge from the superposition of traveling waves.
Features
1. Damping Profile Editor
The interface includes a “Damping Profile” editor in the HUD. This allows you to draw a curve representing the damping factor along the length of the string.
- X-Axis: Represents the position along the string (Left = Bridge, Right = Nut).
- Y-Axis: Represents the damping intensity.
- Bottom (0.0): Standard sustain (Base Damping).
- Top (1.0): Maximum damping (Mute).
This allows for simulating techniques like Palm Muting (drawing a hump near the left side) or preparing the string with specific decay characteristics.
2. Reverb
A global reverb is applied using a ConvolverNode. The impulse response is generated procedurally by creating a buffer of white noise with an exponential decay, simulating a large, diffuse space. The mix is controlled by the reverbMix parameter in AUDIO_CONFIG.
3. Interaction
The instrument supports multi-touch and mouse interaction:
- Pluck: Click or tap to excite the string.
- Drag: Move across strings to continuously excite them (bowing/scraping effect).
- Velocity: The speed of interaction determines the amplitude.
- Acceleration: Sudden changes in velocity affect the spectral brightness.
4. Composition
- Strings: Adjustable from 1 to 24 strings.
- Layout: Strings are arranged randomly across the viewport (“Mikado” style) when count > 1.
- Tuning: Uses a 12-TET ratio system relative to the base frequency.
Architecture
The codebase is structured into three main modules:
VirtualString: Encapsulates the FDTD physics engine and Web AudioScriptProcessorNodefor sound generation. It maintains the state arrays (u,uprev,unext) and the damping profile.StringComposer: A Factory/Builder that manages the ensemble, generating string layouts and tuning ratios.InteractionManager: Handles input events (Mouse/Touch), calculates velocity/acceleration vectors, and dispatches excitation commands to the strings.
Usage
- Start: Click anywhere to unlock the AudioContext.
- Play: Swipe or click on the strings.
- Modify: Use the HUD sliders to change physical properties.
- Damp: Draw on the “Damping Profile” canvas to create custom decay envelopes.
- Reset: Click “Reset Instrument” to generate a new random layout.
Based on the “The Vibrating String” model by Francisco Esquembre et al. and “StringWave” by Paul Falstad.