resonance

the race-car obsession turned into an engine simulator

im really into race cars and how they work, beamng modding is part of that, the sound is another huge part, individual throttle bodies, straight-cut gears, the interruption on a flat upshift and all the rattling around it, i wanted a program where i could get into those things and change them

change the pipe length and hear what the different pipe does, lift the throttle and have the gas exchange and drivetrain react, i wanted to get the sound from the simulated machine and play with the things causing it

this writeup is behind the code, the architecture below comes from the 23 september 2026 build, ive since implemented the things that used to be on the wishlist, theres a quick update below, the newer build needs its own proper writeup

architecture · engine and pipes · drivetrain · debugging by ear · since september

like patternforge its an ai-assisted build, i use coding tools and spend a lot of time driving it, listening and changing settings, quite a lot of the feedback was basically that sounds like a laser or why is that brown noise, then trying to figure out what was actually causing it

how the september build worked

the interface is where i drive and tune it, the audio callback advances the simulation and fills the next buffer, the engine also runs without the interface using repeatable control traces so i can render files and analyse them

keyboard and tuning controls
             |
             v
ecu, throttle, spark, fuel, cuts
             |
             v
cylinders + crank motion
  |                  ^
  |                  |
  |          drivetrain load
  |          clutch / gears / tyres
  v                  |
intake and exhaust   | mesh / impacts
waveguides           |
  |                  |
  v                  v
engine stems      gearbox stem
  |                  |
  +---------+--------+
            |
            v
listener, mix, output limiting
            |
            v
audio device / recorded wavs

in car mode the clutch, gearbox, shafts and vehicle put load back onto the crank, in dyno mode a controller holds the speed i choose, so i can either drive it or sit at one operating point and investigate

the main pieces in the source
partresponsibility
config/ and control/load and validate toml engine definitions, turn scripted time, rpm and throttle points into offline inputs
engine/cylinder state, valves, combustion, crank dynamics, intake runners, exhaust pipes and conversion into audio stems
ecu/per-cylinder spark and fuel commands, idle control, rev limiting, shift cuts, overrun and launch behaviour
drivetrain/clutch, sequential gearbox, backlash, shaft compliance, tyre slip and vehicle motion, gear whine, rattle and impacts
dsp/ and audio/buffers, delay lines, filters, resampling, listener models, offline rendering, audio-device access and wav files
realtime/ and app/connect the models, exchange controls, save settings and recordings, and present the command-line tool or windows interface

its c++20 with cmake and ninja, miniaudio for output, dear imgui for the interface, toml++ for settings and doctest for tests, the windows app uses win32 and directx 11, python tools turn the renders into waveforms and spectrograms

from a cylinder to a sound

the v6 config has a separate gas state for each cylinder, piston position changes the volume, the model tracks mass and energy through the valves, compression, expansion and heat from combustion, a wiebe curve approximates the burn after ignition, its a simplified single-zone cylinder model

pressure acts on the piston and produces crank torque, the crank calculation includes rotational inertia, reciprocating mass, friction and the load, so the other parts have pressure, flow, torque and acceleration to work with as well as rpm and throttle

the intake has individual runners, butterflies and open trumpets, exhaust goes through ports, primaries, collectors, secondaries and the tailpipe, digital waveguides carry the pressure-wave behaviour, i can change lengths, temperatures, junctions and losses and hear what happens

a stem processor turns changes in the intake and exhaust flows into separate audio signals, the september block channel used torque ripple through provisional resonant modes, it was a placeholder and normally muted in that build, the newer structural model came after this

the gearbox and drivetrain

i wanted to hear the mechanical behaviour, clutch capacity, the sequential dog box, clearance between parts, shaft stiffness and damping, then tyre slip between wheel speed and the speed of the car

gear-mesh phase follows shaft rotation, tooth count and load affect the whine, backlash and free gears give impacts and rattle, a shift cuts torque, disengages the dogs, goes through neutral, engages and takes load again, the sound follows those events

one problem was a big rpm bounce after an upshift, separating wheel rotation from vehicle speed and adding tyre slip changed how it settled, i like chasing something i hear back into what the model is doing

ecu and afterfire

the ecu sends spark and fuel commands to each cylinder, idle control, rotating limiter cuts, shift cuts, overrun fuel cut and two-step launch, an exhaust reactor tracks unburnt fuel and air to generate heat-release events, these are still experimental and need more comparison with real recordings

keeping the audio running

rebuilding the model can mean allocating buffers and settling its state, the interface thread builds and warms up a replacement, hands it over with an atomic pointer and takes the old one back for deletion, that work stays outside the sample loop

four substeps at 48 khz output gives a 192 khz internal step rate, filters bring the flow signals back down to the output rate, i can change substeps to trade quality against cpu use, the callback can skip updating the display telemetry if the interface is busy with it

offline renders use scripted traces, explicit random seeds and hashes so they can be repeated, tests compare output across buffer sizes and wav analysis checks levels and invalid samples, the source has tests around the cylinders, exhaust, listeners, drivetrain, driving sequences and settings too

the command-line renderer in this snapshot doesnt include the live drivetrain or gearbox, the app records those through its own path, separate mix, exhaust, intake and gearbox files, being able to isolate them helps a lot

the "laser" problem

there was this short pew sound on flat upshifts that kept bothering me, sounded like a laser, knowing i didnt like it was easy, finding where it came from took a lot longer

we split the recording into stems, tried mic positions and pipe settings and looked at the spectrogram, a few plausible ideas went nowhere, the september notes picked up that the exhaust got louder during the combustion cut, with this octave-heavy tone dropping in pitch, next thing to investigate was the balance between firing blowdown and pumping without combustion

four development spectrograms showing exhaust, gearbox, intake and full-mix sound around an upshift
an original diagnostic figure from that investigation, frequency runs vertically and time horizontally, the full-mix panel uses a different excerpt from the three stem panels, full-size image

i like this part as much as getting the first build working, hear something wrong, try to isolate it, see if the numbers explain what im hearing, sometimes the explanation takes a while to catch up

whats changed since september

all of this used to be listed here as stuff i wanted to do, its since been implemented, as of november 2026

ill get into how those parts work when i update this page from the latest code, the september diagrams and debugging notes above are still from that earlier version

references and related projects

ange yaghis engine simulator was source-study material for this, thats his separate project, and beamng.drive is the game the telemetry adapter connects to

the detailed architecture and diagnostic figure come from the september source, handover, model notes and tests, the november update is where the project has got to since then, more of my audio stuff in patternforge, afterimage and the music page