Building a Real-Time Engine Simulator That Synthesizes Audio From Physics
Hook
Most racing games fake engine sounds with carefully layered audio samples. Engine-sim takes the harder path: synthesizing every pop, rumble, and growl by simulating the actual thermodynamics of combustion chambers, exhaust pulses, and intake resonance in real-time.
Context
Anyone who's ever worked on engine audio for games or simulations knows the problem: pre-recorded samples sound great until they don't. You record a real V8 at various RPMs, layer them carefully, add some pitch shifting magic, and it works—until someone builds a custom engine configuration your samples never anticipated. Want to hear what a flat-plane crank V8 sounds like versus a cross-plane? Record both. Inline-5 with unequal firing intervals? More studio time. The sample library grows exponentially with every configuration.
Ange Yaghi's engine-sim takes a fundamentally different approach: instead of playing back recordings, it simulates the physics that create engine sounds. The software models piston motion, intake and exhaust flow, combustion pressure waves, and harmonic resonance, then feeds those signals through audio processing pipelines to generate output in real-time. This means you can script virtually any engine configuration—bore, stroke, compression ratio, camshaft profiles, firing order, even asymmetric V-angles—and immediately hear how it sounds without recording anything. Originally created as a YouTube demonstration project, it exploded to over 9,000 GitHub stars as automotive enthusiasts discovered they could finally hear their dream engine builds without access to a dyno or sound studio.
Technical Insight
The architecture separates three distinct layers: the physics simulation core, the scripting engine for configurations, and the audio/visual rendering pipeline. This separation is crucial because the physics runs at a different update frequency than audio rendering, and engine definitions need to be hot-swappable without recompiling.
At the simulation core, engine-sim models each cylinder as a thermodynamic system. It calculates piston position using crankshaft geometry, determines combustion chamber volume throughout the stroke, applies gas laws to model pressure changes, and tracks exhaust gas flow as pressure waves propagating through the exhaust system. The key insight is that these pressure waves—their timing, amplitude, and interference patterns—ARE the engine sound. A V8 sounds different from an inline-4 not because of some abstract 'engine character' but because eight cylinders firing in a specific sequence create different pressure wave interference patterns than four cylinders.
Engine configurations are defined using a domain-specific language parsed with Flex and Bison. Here's a simplified example of how you might define a basic inline-4 engine:
import "engine_sim.mr"
public node my_inline_four {
alias output __out: engine;
engine engine(
name: "Custom I4",
starter_torque: 150 * units.lb_ft,
redline: 7000 * units.rpm
)
crankshaft c0(
throw: 45.0 * units.mm,
flywheel_mass: 8 * units.kg,
moment_of_inertia: 0.12,
position_x: 0.0,
position_y: 0.0,
tdc: 0 * units.deg
)
rod_journal rj0(angle: 0 * units.deg)
rod_journal rj1(angle: 180 * units.deg)
rod_journal rj2(angle: 180 * units.deg)
rod_journal rj3(angle: 0 * units.deg)
c0.add_rod_journal(rj0)
c0.add_rod_journal(rj1)
c0.add_rod_journal(rj2)
c0.add_rod_journal(rj3)
}
This scripting approach means the community can share engine files like recipes. Want to simulate a 1960s Ferrari V12? Someone's already written the script with historically accurate bore, stroke, and cam timing. The parser converts these human-readable definitions into the internal data structures the physics engine needs.
The audio rendering is where things get interesting. Instead of directly outputting the raw pressure wave calculations (which would sound thin and synthetic), engine-sim runs the signals through convolution with impulse responses that model exhaust system acoustics, intake resonance, and even microphone placement. The exhaust system acts as a complex filter—a straight pipe sounds radically different from a chambered muffler because they have different frequency response characteristics. The simulator models this by treating the exhaust geometry as a transmission line with reflections, standing waves, and resonant frequencies.
The real-time constraint forces fascinating trade-offs. Scientific engine simulation software like Ricardo WAVE uses tiny timesteps and sophisticated numerical methods to achieve research-grade accuracy. Engine-sim uses larger timesteps and simplified thermodynamic equations because it needs to maintain 60 FPS visualization while generating 44.1kHz audio. The author explicitly acknowledges sacrificing accuracy for perceptual realism—if it sounds right and responds to throttle inputs naturally, that's success even if the pressure curves don't match dyno data.
The visualization layer uses SDL2 for both windowing and audio output, with a custom immediate-mode rendering system for the dyno graphs and engine animation. The architecture keeps this layer completely independent from the simulation, communicating through a clean interface that passes RPM, torque, and per-cylinder state. This means you could theoretically swap the renderer entirely—maybe integrate it into a game engine—without touching the physics code.
Gotcha
The build process is a nightmare if you're not on Windows with Visual Studio already configured. The dependency chain includes SDL2, Boost, Flex, and Bison, and getting everything to link correctly requires following a specific build guide. The author acknowledges this explicitly in the README, and while there are community efforts to improve cross-platform support in the forked 'community edition,' macOS and Linux builds remain fragile.
More importantly, understand what this tool isn't: it's not an engineering tool. The author includes multiple warnings that engine-sim should not be used for actual engine tuning, design validation, or scientific research. The simplified physics models, larger timestep requirements for real-time performance, and focus on audio characteristics over thermodynamic accuracy mean the output is 'inspired by reality' rather than 'representative of reality.' If you need to actually predict how an engine modification affects power output, you need professional simulation software that costs thousands of dollars and runs magnitudes slower. Engine-sim will give you a rough feel, but don't machine pistons based on its dyno curves. The community has documented cases where the simulated horsepower numbers are off by 15-20% compared to real-world results for the same configuration. That's fine for entertainment and education, but disastrous if you're making engineering decisions.
Verdict
Use if: you're building audio systems for games and want to understand physics-based sound synthesis, creating automotive YouTube content that needs accurate engine sounds for hypothetical builds, teaching thermodynamics or mechanical engineering in an interactive way, or just deeply curious about how engine configurations affect sound and want an endlessly tweakable playground. The scripting system and immediate audio feedback make this an incredible exploration tool. Skip if: you need actual engineering data for design decisions (get Ricardo WAVE or GT-Power instead), require cross-platform deployment without friction (the Windows-centric build is a real limitation), or want polished software with professional support (remember, this started as a demo project and the codebase reflects that origin). Also skip if you're looking for a complete vehicle simulator—this is purely engine-focused with no transmission, drivetrain, or vehicle dynamics modeling.