Search Unity

Vehicle engine sound

Discussion in 'Audio & Video' started by Deleted User, Mar 1, 2017.

  1. Deleted User

    Deleted User

    Guest

    Hi i'm making a car controller and I need help for the engine sound.
    The controller works well(nothing too complicated) and it has a gear system,RPM,torque based on the gear...
    I would like to have a realistic engine sound, but I'm not an expert in audio.
    I thought that simply taking an engine sound loop and changing the pitch would work, but it doesn't sound so good. So, my question is: there is another way to do it?
     
  2. rakifsul

    rakifsul

    Joined:
    Mar 30, 2014
    Posts:
    47
    maybe add a ignition and stall engine sound. you can also play sound when the gear changes. ideally, the engine sound should be emitted when player throttles the engine in neutral gear.

    different engine, different sound. if the engine uses turbo, there should be a turbo sound (like puffing sound).

    you could check my thread for reference:
    https://forum.unity3d.com/threads/p...cs-and-ai-for-racing-and-combat-genre.459219/
     
  3. CrashBang

    CrashBang

    Joined:
    Mar 6, 2017
    Posts:
    3
    I
    I'm working on this currently...generally these are my two approaches.
    1)Use a Rev'ing sound as a One-shot tied to acceleration (RPM) threshold. After the threshold is reached, trigger a high rev sound that is looped. The audio edit of the high rev engine must be seamless to sound good. After RPM reaches a low threshold trigger idle sound effect.

    2) Connect pitch of the High Rev to RPM for engine accel / decel. After RPM reaches a low threshold trigger idle sound effect.
     
  4. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    If you try to do this with only one sound sample then it's going to sound terrible because the rpm changes too much. You can alter the pitch of a given sample by some amount and it still sounds good, but beyond that it's bad. A sample recorded at 5,000 rpm will sound good at 4,000 rpm or 6,000 rpm, but not 1,000 rpm or 10,000 rpm.

    If you're going to use samples instead of procedurally generated audio, looping engine sounds is the way to go. I would forget one-shots. The trick with looping is to use multiple samples recorded at lots of different engine rpms and fade between them so any given sound's pitch isn't being changed too much . That's what I'm doing here:



    This uses a set of seven different wave files recorded at different engine speeds from idle all the way up to the highest rpm for when you're on throttle, then another seven when you're off throttle. At any given time there are up to maybe four sounds playing at the same time (two on throttle, two off), at different volumes. This is how most of the big name car games work too, more or less.

    It's not cheap to get a set of samples like this though, especially if they're new recordings. They need to be made by a pro who knows what he's doing and specializes in this type of thing.

    The other option besides samples is to use procedurally generated sound. I've written a few experimental procedurally generated audio systems as over the years. Here's the latest one from three years ago or so (more vids on the channel). This is a real time car engine simulation producing audio from the exhaust gas dynamics that doesn't use any sound files at all. It's all computed on the fly so there's no degradation as rpm changes and there's no mixing between samples because there aren't any samples. It doesn't matter if the engine is spinning at 1 rpm or 50,000. It still works.



    Unfortunately it's extremely computationally heavy (runs at 500,000Hz, computations are in the tens of billions per second just for one engine) so it's only possible to do in a compute shader and then you're making some big trade offs with the rest of the game. So some day this might become a more feasible thing as GPU tech continues to evolve, but right now I still use samples.
     
    Last edited: Mar 29, 2017
  5. slaczky

    slaczky

    Joined:
    Sep 26, 2015
    Posts:
    224
    Hi!
    I know you posted this almost a year ago, but have you tried Realistic Engine Sounds unity asset?
     
    Last edited: May 9, 2019
  6. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Wooah! Interesting. I didn't know that there was an asset, that did that.
     
  7. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    Thanks for the info. So when you say a loop for different engine speeds where do define the beginning of the next loop? For example my car goes up to 7000rpm, would you do a loop every 1000 rpms or how do know where to divide it?
     
  8. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    In the above examples, it's playing all the loops simultaneously. It adjusts the volume and pitch so they blend together nicely where there's some overlap. For instance, say you have two samples:

    Sample 1: 3000 rpm
    Sample 2: 5000 rpm

    I play them both simultaneously as two seperate loops, I never stop any sounds. It's just a matter of adjusting pitch and volume so at maybe between 2000 - 4000 rpm, sample 1 (the 2000 rpm recording) is 100% volume, then it trails down to 0% volume as it goes down from 2000 to 1000 rpm or up from 4000 rpm to 5000 rpm.

    Meanwhile the 5000 rpm sample is 100% volume when the engine is running between maybe 4000 and 6000 rpm. Then it drops linearly to 0% volume between 4000 and 3000 rpm on the one side, and between 5000 and 6000 on the other. Meanwhile you scale the pitch of both samples separately according to engine rpm.

    Once you get that, you can do the same thing with separate 3000 "off throttle" and 3000 "on throttle" samples. With those you're blending with the throttle position and rpm at the same time.

    Must be very careful to determine the engine rpm of the samples. If it's even a tiny bit off it'll sound weird. You can usually do that by ear. I wrote a little program that plays a sine wave of the correct frequency for the particular engine layout (number of cylinders, 2 or 4 stroke, rpm). Then I just adjust the sine wave until the frequency matches and read the rpm off. It's not too hard to do by ear.

    That's what I did here, essentially:



    It's just a matter of figuring out how to blend them so it sounds nice. I.e., how much overlap to use (spread of 4000-6000 rpm or 4500-5500rpm for 100%, etc..) This one has 15 engine sounds, but you probably wouldn't know it. It's just crossfading them all with engine rpm and throttle.
     
    Last edited: May 30, 2019
    spikyggames and PrimalCoder like this.
  9. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    Thanks for the help, I understand better now. Those examples you had are both real nice sounding.
     
    Todd-Wasson likes this.
  10. kaleb_unity709

    kaleb_unity709

    Joined:
    Jul 12, 2023
    Posts:
    1