Victor's Devblog

If you are interested to receive those weekly articles as a newsletter, poke me offline! Automated subscription is disabled because of bots...

Otherwise, Atom feed is here!

New Car Sounds 1/2

Very tldr; because I lack time.

What Was Here

Previously I had implemented a very naive car sound synthesizer. In short, I recorded samples of car engines at 1000rpm, 2000rpm, 4000rpm, etc. then mixed them at runtime based on the car's current RPM.

This makes the pitch increase with RPM, just like with a real car, but that's about it. Sound is especially bad at low RPM and lacks any personality such as crackles when hot pipes ignite unburnt gas.

New Synthesizer

A car's sound comes primarily from:
- the explosions that occur in the engine
- the air turbulence in its exhaust pipe
- the friction of various components

Notably, the explosion's sound doesn't go faster as the car goes faster, it is just played more often:
- each of the engine's pistons is set to "ignite" at a specific angle of the crankshaft
- at low speed each explosion is distinct, but at high speed they start to overlap
- the more pistons (set at unique angles) the engine has, the more explosions are repeated and the higher its pitch becomes

So my synthesizer is parameterized just like an engine would (how many pistons, at what angle do they ignite) and, when the audio thread queries its sound buffer, it just repeats a very simple "pop" sound more or less frequently based on the car's current RPM.
This gets a low repeated pop at low speed that becomes a high pitch hiss at high speed.

In addition I added a couple of noise sounds, some tuned by the car's speed (the "friction of the car's axles") and some by RPM (the gearbox's friction, the exhaust gas), and a few filters to cut high frequencies (this models how the car's structure would alter its sound).

Finally, I made RPM lower when gears are switching and I added random pops when throttle is off or during gear shift (this represents crackles: unburnt gas igniting in still-hot exhaust pipe).

Notice around 10s, as I lower RPM to unrealistic values, how most of the audio is a simple "pop".

New Architecture

So the new synthesizer with its embedded filter was more of a proof-of-concept. I have now started the implementation (still WIP) of a new scene sound system to fix the following issues:
- the car should sound differently when the camera is inside or outside it
- the unique equalizer is difficult to tune while adding layers (intake noise, impact sounds, etc.)

My new model is the following:
- the world has an `exterior sound bus` (where sounds register themselves if they reach the outside) and a `current interior entity` (the entity, if any, that the camera currently sits inside)
- an entity with an interior has an `interior sound bus` (for sounds generated by the entity for inside itself) and an `exterior filter` (filter to apply to sounds that come from the exterior bus)
- the car is a DAG of sound emitters, filters, and buses (see below)

If camera is outside, player hears the sound from the exterior bus; if camera is inside an entity such as a car, it hears the filtered exterior sounds plus the entity's own interior sounds.

The car will now be composed of emitters inside spaces that connect to other spaces:
- engine's combustion (spawns in engine, transfers to exhaust pipe and engine bay)
- exhaust turbulence (spawns in exhaust pipe, transfers to car interior and exterior)
- gearbox whine (spawns in gearbox, transfers to car interior and exterior)
- impact sound (spawns on chassis, transfers to car interior and exterior)
- ...
And each transfer has a custom equalizer applied to it, to represent how sound would propagate between two spaces.