Inside the CarsSound engine: how we synthesize engine sound in the browser
Most of our articles explain how real engines make their sound. This one explains how CarsSound imitates them: the actual design of the synthesizer that starts running in your browser when you press START. If you have ever wondered why our V8 burbles and our V12 sings, here is what happens, step by step.
Why we do not use recordings
The usual way to make a car sound in software is to record a real engine at a few speeds and crossfade between the clips, shifting their pitch in between. It works for a game, but it has limits that show up quickly in a real car. A recording made at full throttle sounds wrong when you are cruising. Pitch-shifting a clip too far turns a deep V8 into a cartoon. And every recording belongs to one specific car.
We wanted every engine in the garage to be original, and to respond to rpm and load continuously, not in steps. So nothing in CarsSound is recorded. Every sample you hear is calculated from a small physical model of an engine, with a few dozen numbers that describe each engine type.
Where the sound is calculated
The synthesizer is an AudioWorklet, part of the Web Audio API that runs on the browser's dedicated audio thread. It calculates every output sample, 44,100 or 48,000 per second depending on the device, in blocks of 128 samples. The rest of the page sends it only five numbers, many times per second: rpm, load (how hard the engine is working), overrun (throttle closed while the car keeps the engine turning), ignition cut (the rev limiter) and the Crackle setting.
Inside the worklet, rpm is smoothed over about 30 milliseconds and load over about 50, so a sudden jump in the GPS reading becomes a quick sweep rather than a click.
Step 1: a crank clock and a firing table
At the heart of each engine is a counter that turns like a crankshaft. One full count is a complete four-stroke cycle, which is two revolutions of the crank. Each cylinder has a fixed position in that cycle and an exhaust bank it fires into, left or right. When the counter passes a cylinder's position, that cylinder fires.
That small table decides most of an engine's character:
| Engine in the garage | Firings per cycle | What is special |
|---|---|---|
| Muscle V8 | 8, evenly spaced | Banks alternate left-right-right-left-right-left-left-right, like a cross-plane crank, so each bank's own pulses are uneven |
| Italian V8 | 8, evenly spaced | Banks simply alternate, like a flat-plane crank, so each bank is even |
| Rally Boxer Four | 4, slightly uneven | Firings at 0, 29.5, 50 and 79.5 percent of the cycle, imitating unequal-length headers |
| V-Twin Cruiser | 2 | Gaps of 315° and 405° of crank rotation: the long-short gallop |
| Parallel Twin | 2 | Gaps of 270° and 450°, the "270-degree" twin |
| Supermoto Single | 1 | One firing every two turns: you hear separate thumps at idle |
The cross-plane pattern is the whole secret of the American V8 burble. The engine as a whole fires evenly, but each exhaust bank receives its pulses at uneven intervals, and that lopsided rhythm is what the ear picks up. Switch between the Muscle V8 and the Italian V8 in the app: the number of cylinders is the same, only the bank pattern differs.
Step 2: the pressure pulse
Each firing drops a pressure pulse into its bank's exhaust. The pulse rises smoothly over roughly the first fifth of its length and then decays exponentially. Its length scales with the gap to the next firing: about half of it for most engines, as little as a third for sharp, busy engines like the Twin Rotary and the Two-Stroke 250, and over two thirds for the Diesel Truck. It always stays between half a millisecond and nine milliseconds. A short burst of noise rides on each pulse for the rasp of turbulent gas.
Real engines are never perfectly regular, so neither are ours. Each cylinder gets a fixed strength that differs by up to 7 percent from the others, every single firing varies by up to 10 percent more, and engines with a lumpy camshaft randomly weaken some firings at idle. The Muscle V8 has a lot of that lope; the V12 has none. Load sets the pulse strength from about a fifth at a light cruise to full at wide-open throttle, and closing the throttle roughly halves it.
Step 3: the exhaust pipe
Each bank then feeds its own simulated pipe. Technically it is a delay line whose output is fed back into its input, inverted and slightly low-pass filtered on every trip. That mirrors what a pressure wave does in a pipe with an open end: it travels to the end, reflects back upside down, and loses some of its high frequencies each time. The result rings at the pipe's resonant frequencies.
The pipe length is one of the most important numbers per engine. The Muscle V8's two pipes have round trips of 3.4 and 3.9 milliseconds, so they ring most strongly at about 128 to 147 Hz. The V12's are 1.8 and 1.9 milliseconds, which puts the main resonance near 270 Hz and is part of why it sounds higher and smoother. The Diesel Truck's are the longest, at 4.6 and 5.0 milliseconds, around 100 to 110 Hz. The delay uses interpolation between samples, so lengths are exact rather than rounded to whole samples.
The two banks are always a little different in length, and each bank's set of body resonances (band-pass filters for the shells of the mufflers and the car body) is detuned by 3 percent. Each bank goes mostly to one stereo channel with some cross-feed. Those small differences are what make the sound wide instead of coming from a point.
Step 4: bite, muffler and thump
Under load the pipes are driven into soft saturation, which adds harmonics: the harder you accelerate, the rougher and more aggressive the sound becomes, even at the same rpm. Then comes the muffler: two low-pass filters in series whose cutoff opens with rpm and load, much like a valved sports exhaust. That is why lifting off sounds muffled and a full-throttle pull sounds open.
Finally, the raw pulses are filtered to a low band between about 45 and 70 Hz, depending on the engine, and mixed in as a separate "thump": the low end that you feel in your chest more than hear, strongest in the V8s, the V-twin and the big single.
Step 5: the extra voices
- Intake roar. Band-passed noise whose centre rises from 350 Hz at idle to about 1,750 Hz at the redline, scaled by load and pulsing with the firings.
- Turbo. Boost builds slowly towards a target set by load and rpm, which is turbo lag, and drops back faster. The whistle is a tone that sweeps from 1.8 kHz to about 7 kHz as boost rises. If you were on boost and lift off sharply, the blow-off valve vents with a hiss.
- Supercharger. A whine locked to crank speed, at 3.2 times the crank's rotation rate in the Supercharged V8. There is no lag: it rises and falls exactly with the revs, just like the real thing.
- Diesel clatter. A sharp click above 2.5 kHz on every injection, fading within about a millisecond.
- Afterfire. Lifting off arms a short "budget" of pops that fades over about one and a half seconds. During that time each firing has a chance to become a bang, at least 35 milliseconds apart. The bang goes into the same exhaust pipe, so it rings with the engine's own resonance. The Crackle slider and each engine's own crackle level set the odds; at the rev limiter there are occasional bangs too.
Step 6: imperfection and the cabin
A perfect clock sounds like an electronic oscillator, not an engine. So the crank speed wanders very slightly from cycle to cycle, most at idle and least at high rpm. Then the sound is placed in a small room: four early reflections between 7 and 26 milliseconds, cross-fed between left and right, which is roughly what the inside of a car does to sound. A gentle soft clipper at the very end keeps sudden peaks from hitting your speakers hard.
One unglamorous detail matters a lot in practice. If any calculation ever produced an invalid number, every filter after it would be poisoned and the engine would fall silent for good. The worklet checks every block and, if that happens, rebuilds the engine within a few milliseconds.
Electric voices
The two electric cars use a different model with no firing pulses at all. Each motor produces a tone that rises with its speed, built from a handful of harmonics, plus an inverter whine that sweeps upward with speed. The three-motor Electric Hypercar layers motors at different ratios and stereo positions, and its left and right whines are tuned 0.4 percent apart, so they beat slowly against each other. Under hard acceleration from low speed, a sub-bass swell adds the feeling of thrust.
Feeding the model: speed, gears and load
Your car does not tell the browser its throttle position, so CarsSound reconstructs it. Speed comes from the browser's location service; we prefer the receiver's own Doppler speed measurement, which reacts faster than speed worked out from positions. Acceleration is a weighted straight-line fit over the last 0.6 to 2 seconds of readings, with the newest counting most, and between readings the speed is extrapolated so the engine moves smoothly instead of stepping.
A virtual gearbox then chooses the gear. At light throttle it shifts up early, around 1,700 rpm above idle; at full throttle it holds the gear to 93 percent of the redline. A shift takes 0.22 seconds in a car and less on a motorcycle, gears are held for at least half a second, and downshifts at light throttle get a short throttle blip to match revs.
What we are still working on
The model is honest about what it cannot know. Because load is inferred from acceleration, a steady climb up a long hill sounds like cruising on the flat. Phones that report location only once per second add up to a second of delay, which no smoothing can fully hide. And a model is always a simplification: we keep tuning engines when readers tell us something sounds off, so let us know if one does.
Want to hear the ideas from this article? Open the garage, choose Test drive, and switch between the Inline Six and the Muscle V8, then try the Twin-turbo V6 and lift off at high revs.