| Crates.io | ringkernel-wavesim3d |
| lib.rs | ringkernel-wavesim3d |
| version | 0.4.0 |
| created_at | 2025-12-11 09:33:28.275416+00 |
| updated_at | 2026-01-25 21:30:18.505594+00 |
| description | 3D acoustic wave simulation with realistic physics, binaural audio, and GPU acceleration |
| homepage | https://github.com/mivertowski/RustCompute |
| repository | https://github.com/mivertowski/RustCompute |
| max_upload_size | |
| id | 1979427 |
| size | 583,543 |
A comprehensive 3D acoustic wave simulation with realistic physics, binaural audio, and GPU acceleration.
c = 331.3 * sqrt(1 + T/273.15) with humidity correctiondt ≤ dx / (c * sqrt(3))# Run with CPU backend
cargo run -p ringkernel-wavesim3d --bin wavesim3d --features cpu
# Run with CUDA acceleration (requires NVIDIA GPU)
cargo run -p ringkernel-wavesim3d --bin wavesim3d --features cuda
| 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 |
use ringkernel_wavesim3d::simulation::{
SimulationConfig, SimulationEngine, Environment, Position3D
};
use ringkernel_wavesim3d::audio::{AudioSystem, AudioSource, VirtualHead};
// Create simulation with custom environment
let config = SimulationConfig {
width: 64,
height: 32,
depth: 64,
cell_size: 0.1, // 10cm cells
environment: Environment {
temperature_c: 20.0,
humidity_percent: 50.0,
medium: Medium::Air,
..Default::default()
},
prefer_gpu: true,
computation_method: ComputationMethod::Stencil, // or ComputationMethod::Actor
..Default::default()
};
let mut engine = config.build();
// Add audio source
let mut audio = AudioSystem::new(Default::default());
let source = AudioSource::tone(
0,
Position3D::new(3.2, 1.6, 3.2), // Source position
440.0, // Frequency (Hz)
1.0, // Amplitude
);
audio.add_source(source);
// Set up binaural microphone
let head = VirtualHead::new(Position3D::new(3.2, 1.6, 5.0));
audio.init_microphone(head, engine.grid.params.time_step);
// Run simulation steps
for _ in 0..1000 {
engine.step();
if let Some(mic) = &mut audio.microphone {
mic.capture(&engine.grid);
}
}
// Get binaural audio
if let Some(mic) = &audio.microphone {
let (left, right) = mic.get_samples(1024);
// Process or save stereo audio...
}
The simulation solves the 3D acoustic wave equation:
∂²p/∂t² = c² ∇²p - α ∂p/∂t
Where:
p is pressurec is speed of sound∇² is the 3D Laplacianα is damping coefficientUsing 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
Frequency-dependent absorption in air:
Environment {
temperature_c: 20.0, // Temperature in Celsius
humidity_percent: 50.0, // Relative humidity
pressure_pa: 101325.0, // Atmospheric pressure (Pa)
medium: Medium::Air, // Air, Water, or Metal
}
f_max ≈ c / (10 * cell_size)| 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 | Description |
|---|---|
cpu (default) |
CPU backend with Rayon parallelization |
cuda |
NVIDIA CUDA acceleration |
audio-output |
Real-time audio output via cpal |
ringkernel-wavesim: 2D wave simulationringkernel-cuda-codegen: CUDA kernel generationSame license as the parent RingKernel project.