WaveSim3D - 3D Acoustic Wave Simulation
A comprehensive 3D acoustic wave simulation with realistic physics, binaural audio, and GPU acceleration.
Features
Realistic 3D Physics
- Temperature-dependent speed of sound: Uses accurate formula
c = 331.3 * sqrt(1 + T/273.15)with humidity correction - Frequency-dependent absorption: Implements ISO 9613-1 atmospheric absorption model
- Multiple propagation media:
- Air: Temperature and humidity-dependent properties
- Water: Bilaniuk-Wong speed of sound formula
- Metal: Steel and aluminum with proper material properties
3D Wave Simulation
- FDTD (Finite-Difference Time-Domain) wave equation solver
- 7-point stencil Laplacian for accurate 3D propagation
- CFL stability automatically maintained:
dt ≤ dx / (c * sqrt(3)) - Absorbing boundary conditions to minimize reflections
- Support for obstacles, reflectors, and custom geometries
Audio System
- Multiple source types:
- Impulse (click/clap)
- Continuous tone (sine wave)
- Chirp (frequency sweep)
- White/pink noise
- Gaussian pulse
- WAV file playback
- 3D positioned sources with real-time movement
- Binaural microphone with virtual head:
- Realistic ear spacing (~17cm)
- ITD (Interaural Time Difference) calculation
- ILD (Interaural Level Difference) modeling
- WAV file I/O for recording and playback
GPU Acceleration
- Two computation methods:
- Stencil: Traditional GPU stencil computation with shared memory tiling
- Actor: Novel cell-as-actor paradigm with message-based halo exchange and HLC
- CUDA backend for NVIDIA GPUs
- CPU fallback with Rayon parallelization
- Volumetric ray marching for real-time 3D pressure field visualization
3D Visualization
- wgpu-based rendering (Vulkan, Metal, DX12)
- Interactive camera with orbit, pan, and zoom controls
- Slice visualization: XY, XZ, and YZ plane cuts
- Color mapping: Blue-White-Red pressure visualization
- Source and listener markers
Quick Start
# Run with CPU backend
# Run with CUDA acceleration (requires NVIDIA GPU)
Controls
| Key | Action |
|---|---|
| Space | Play/Pause simulation |
| R | Reset simulation |
| I | Inject impulse at source position |
| 1 | Toggle XY slice visibility |
| 2 | Toggle XZ slice visibility |
| 3 | Toggle YZ slice visibility |
| Left Mouse | Rotate camera |
| Right Mouse | Pan camera |
| Scroll | Zoom camera |
| Escape | Quit |
Usage Example
use ;
use ;
// Create simulation with custom environment
let config = SimulationConfig ;
let mut engine = config.build;
// Add audio source
let mut audio = new;
let source = tone;
audio.add_source;
// Set up binaural microphone
let head = new;
audio.init_microphone;
// Run simulation steps
for _ in 0..1000
// Get binaural audio
if let Some = &audio.microphone
Physics Model
Wave Equation
The simulation solves the 3D acoustic wave equation:
∂²p/∂t² = c² ∇²p - α ∂p/∂t
Where:
pis pressurecis speed of sound∇²is the 3D Laplacianαis damping coefficient
FDTD Discretization
Using a 7-point stencil for the 3D Laplacian:
∇²p ≈ (p_W + p_E + p_S + p_N + p_D + p_U - 6p) / Δx²
Time stepping:
p_new = 2p - p_prev + c²Δt²∇²p
Atmospheric Absorption (ISO 9613-1)
Frequency-dependent absorption in air:
- Oxygen relaxation (dominant ~10 kHz)
- Nitrogen relaxation (dominant ~100 Hz)
- Classical absorption (molecular viscosity)
Configuration Options
Environment
Environment
Grid Size
- Recommended: 64x32x64 for real-time visualization
- Maximum frequency:
f_max ≈ c / (10 * cell_size) - For 10cm cells in air: ~343 Hz accurate simulation
Binaural Audio
- Default ear spacing: 17cm (average human)
- Sample rate: 44.1 kHz
- ITD range: ±0.6ms (full lateralization)
Benchmarks
| Configuration | Backend | Performance |
|---|---|---|
| 64³ cells | CPU (Rayon) | ~120 steps/sec |
| 64³ cells | CUDA (RTX 3090) | ~2000 steps/sec |
| 128³ cells | CPU (Rayon) | ~15 steps/sec |
| 128³ cells | CUDA (RTX 3090) | ~400 steps/sec |
Feature Flags
| Feature | Description |
|---|---|
cpu (default) |
CPU backend with Rayon parallelization |
cuda |
NVIDIA CUDA acceleration |
audio-output |
Real-time audio output via cpal |
Dependencies
- wgpu: Cross-platform graphics
- winit: Window management
- egui: GUI controls
- glam: 3D math
- hound: WAV file I/O
- rayon: CPU parallelization
- cudarc: CUDA bindings (optional)
Related Crates
ringkernel-wavesim: 2D wave simulationringkernel-cuda-codegen: CUDA kernel generation
License
Same license as the parent RingKernel project.