Procedural engine audio

Started by
7 comments, last by raigan 1 year, 5 months ago

Hello! I'm creating a procedural engine sound generator, inspired by AngeTheGreat's engine simulator which uses a simplified physics-based simulation. He uses physics bodies to simulate the crankshaft and pistons physics, I'm going for a more simplified approach by assuming that the pistons and the crankshaft are the same thing in the system, with different timing to apply forces directly into crankshaft, using pure trigonometry maths. The idea is to have a free software that can export engine sound at variable rpms to use in any racing game, simillar to AngeTheGreat's simulator but more simple so anyone with old hardware can run it.

I succeeded to create the crankshaft and piston movement, so I moved on to create the piston movement audio signal generation, I'm trying two approaches:

  1. Using piston position, as it moves in a sine-wave simillar pattern, it generates a sine-wave audio signal, I assume is correct as I didn't add any kind of noise in the system yet, but there is a problem: If the piston stops at a position different than zero, the audio signal will be a constant non-zero value, which isn't correct, it should be zero as the piston isn't moving, so what's the correct way to generate the signal from the piston position?
  2. Using piston velocity, the velocity varies more closely to a square-wave, by slowing down fast on top and bottom positions and mantaining the same velocity magnitude while the piston slides along the cylinder. It gets really loud at higher rpms, as the velocity increases in magnitude, it increases the audio signal magnitude too.

It seens that AngeTheGreat uses a pre-recorded audio sample for the piston movement, that is just played back with frequency relative to the motor rpm, I'm going for a more realtime physics-based approach.

I ain't a sound engineer or expert at audio signal processing, so I'm trying to guess how the audio should sound like based on some knowledge on how sound propagates in the air. I guess the correct way is by using the piston position, but what's the correct way that doesn't generate a constant non-zero signal when the piston isn't moving? I should feed the piston position to another generator that uses the position variation? I'm having a bit of issues in this part.

Not so professional game developer

Advertisement

Here is my take as a “sound engineer or expert at audio signal processing.”

I imagine you want to treat each piston firing as an “explosion” sound, i.e. by playing a short clip of an impulsive sound. Then, trigger the explosion sounds to play at the correct rate for the RPM (I think each piston fires once per revolution, so if it's a V8, then multiply RPM by 8). Then, apply a low-pass filter to filter out higher frequencies that are damped by the engine, body, and sound transmission path to the driver.

This might work, but will definitely be very expensive to do in real time because there will be potentially hundreds/thousands of simultaneously playing audio clips. It's similar to granular synthesis, but with many more overlapping samples played at once. If I were to do engine sound for a game, I would probably stick with a traditional approach that would use a recording of a real engine that gets dynamically stretched/compressed based on the RPM. This will be probably hundreds of times faster than a “physically-based” approach.

@ghsoares I'm not an audio engineer NOR a gear head, so take my advice with a grain of salt ?

I think most of the sound of an engine is caused by the sudden release of compressed gas as Aressera mentioned. Since cars have multiple pistons running at high velocities, we may interpret what we hear as a constant noise instead of a series of ‘explosions’ in rapis succession. Also, we probably hear those ‘explosion’ sounds echoing off different surfaces and this could make the sound seem more continuous. Since you're interested in a first principles approach, one thought is to get an audio clip of a single piston firing (if that's possible) or a motor running at low idle and see what it looks like in an audio program like Audacity. That may provide some insight .. Is it a sine wave or a pulse waveform? Maybe you need a custom envelope to match what you actually hear?

Thanks for the replies, guys!
@Aressera For the ignition/exhaust sound, I'll be using a simplified fluid simulation, the same as AngeTheGreat used on it's engine simulator and explained in detail in this video:

He didn't specify in this video, but I assume the output he uses for the audio signal is the pressure value on each cylinder container. It creates a realistic result even without any kind of filtering, as it simulates the air being vibrated by the gas being expanded and condesed as the temperature rises rapidly on the combustion event and cools down on exhaust.

But as I explained, I want to build the complete audio generation from scratch, without any kind of sample, using pure sound physics to simulate the full engine sound, compositing different audio signals, combining motor vibration and combustion, etc. Even if the final sound seems to be really complex, it's possible to break down into smaller audio signal patterns that are mixed together to form the full sound, so the first thing I'm doing is to create the piston movement sound first, as it makes a difference in the engine sound (AngeTheGreat uses the same approach you mentioned to trigger a explosion sound to each fire event, but I didn't hear a sound for the piston and crankshaft vibration itself).

@scott8 Correct, most of the engine sound is caused by air being vibrating by air compression/decompression on ignition event and exhaust which, in teory, I wouldn't need a pre-recorded audio sample to be played back for each ignition event, instead I could use the air pressure as audio signal, but some of the audio also comes from different vibrating sounds, including piston movement, which is the first audio signal I want to create first, then add the combustion/exhaust audio signal.

So basically, speaking in terms of audio signal processing, I need some kind of signal generator that uses the “vibration” of the input signal as the output signal of the generator, which isn't exactly a sine-wave generator, because if the value doesn't change, the output should be zero (in a regular sine wave generator, if the input is, let's say, `PI/2` constant, the output will be a constant 1, when the expected value should be zero, as the input signal isn't changing), I don't know the exact name for this kind of generator, so I need some help in this specific part.

I think it's missing a demonstration video of what I have now, I forgot to add in the first post, so here is a video I created with the current state of my engine sound generator, testing with a simple v2 engine (I have reduced the output audio to 10%, as it gets quite loud in higher rpms):

As you can see in the video, in the soundwave graphic in the bottom-left corner, the signal goes beyond the [-1, 1] range at higher rpms, but it kind of sounds like a engine already.

Not so professional game developer

Going even more simpler, basically I want to simulate the audio signal generated by a speaker, if you imagine the engine piston as it were a speaker diaphragm, that oscilates back and fourth to generate sound by vibrating the air, it's the same concept I want to use to generate the piston movement sound, so how I could generate a audio signal from a oscilating piston?

Not so professional game developer

ghsoares said:
using pure sound physics to simulate the full engine sound

I doubt that this is possible with any reasonable level of compute. To do this really correctly, you would need a simulation like the finite element method (FEM) run at a very small time step (significantly shorter than an audio sample to avoid aliasing). It's not even possible to do real-time synthesis of the sounds produced by vibrating objects, except via approximations like modal synthesis, and an engine is much more complex so those approximations aren't applicable. This is an area of open research, you could get a PhD by solving this problem.

@Aressera I don't need a complete realistic audio generation, as you can see on the AngeTheGreat's engine simulator videos, it uses a simplified liquid simulation for the combustion and exhaust sound generation, without simulating hundreds of thousands of particles in a single cylinder, it instead approximate the container velocity, pressure, temperature, flow rate from one container to another, etc. And it is quite accurate because it uses a physics formula to calculate all of these variables, more specifically he uses the Ideal Gas Law to calculate the relation between pressure, volume, molecule count, ideal gas constant and temperature.

So I don't think I need a overly complex and accurate simulation, but a simple and accurate enough simulation which output sound should be good enough for racing games. Also, I don't plan to create a tool to run in runtime by the game, instead it bakes the simulation sound into a sound file that is played back in the game engine using granular audio synthesis, which each grain being the baked audio from the engine running in a specific rpm.

Not so professional game developer

I can't answer your question, but I wanted mention that there's an in-development game called Stunt Derby which is doing simulation-based engine noises; the developer (Alex Austin) might have some experience/knowledge to share if you ask him:

This topic is closed to new replies.

Advertisement