# Math for sounds

I need help with making sounds for some vehicles.

question: What’s the math behind making the sound pitch go up or down depending on vehicle speed?? (or is there another way to make sound for vehicles?)

I have had this problem for a long time, I really need help with this.

Thanks for any help

1 Like

I am not an expert in this, but I think it was something called the doppler effect?

1 Like

SoundService.DopplerScale is a built in value that determines how sound warps when its source is moving. The dev wiki page mentions roblox uses something called FMOD for sound, and I have no idea how the math works for that other than that FMOD says that 0 is no doppler, 1 is “natural” doppler and 5 is an exaggerated doppler. Roblox’s scale goes beyond 5, though.

Your best bet is probably changing this value until you find something that works for you

2 Likes

Are you talking about Effects? If so I am the right person.

An easy way to get higher pitch is simply by raising the frequency of a sound.

You can do this in several ways.

Increase the speed of playback
Use PitchShift to change the pitch(recommended)
Use a part that is moving to create a doppler effect.

If you want to look more into PitchShift you can view it here.

One last thing. If your sound is not high enough you can add multiple PitchShiftEffects to multiply the sound So if you want lets say x64 high pitch sound simply add 8 PitchShift SFX to a sound and set them all to 2 octave

I’m asking for the math behind how raising the pitch while driving works.

How do i do this? could you please explain more.

Well there is no real math to it really. You can simply set the pitch to go up linearly to how fast you are driving.

Lets say you are driving at 30 sps The PitchShift.Octave is 1 Then if you are driving at 60 sps the PitchShift.Octave is 2 and so on…

There is no real math.

If you are asking in terms of the DopplerEffect then yes there is math the pitch of the audio increases by the DopplerScale Increasing the DopplerScale will exagerate the Doppler Effect.

The Doppler effect is easy to make .

Simply put some Audio that is playing in a part. Then move the part towards or away from the Players Camera.

Depending on the Scale you might have to move the part very quickly.

Here is a video that demonstrates the doppler effect. roblox doppler effect test - YouTube

Whats the math that would make that change though?

I don’t think OP wants to recreate the Doppler effect, which is just a phenomenon that describes an increase in the pitch of a sound from a stand-still observer (doesn’t necessarily have to be stationary) as the vehicle approaches them, and a decrease in the pitch as it is moving away from the observer

It’s simply just increasing the pitch of the sound based on the speed the driver is moving at, which can just be done by a linear equation:

``````sound.PlaybackSpeed = MULTIPLIER * Vehicle.Velocity.Magnitude
``````

Yeah, this is what I’m trying to go for, could you explain more?

The Doppler Effect is already a part of Roblox Studio. You do not need to recreate it.

However, if you still want to recreate it simply use the Velocity to find out the difference in magnitude from the players camera to the part that is moving. Then increase the PitchShiftSoundEffect.Octave by the number that you found out.

Given that an increase in the velocity will result in an increase in the engine’s pitch at the same rate and the same can be said for a decrease, it can be said that the two quantities, the vehicle’s velocity and the engine’s pitch are proportional to each other.

A general formula can be derived for two quantities that are proportional:
`p = k * p`
where:

• `v` is the vehicle’s velocity
• `p` is the engine’s pitch
• `k` is a constant, that is referred to as the constant of proportionality

Changing a sound’s speed will affect its pitch proportionally, given that the wavelength of the sound wave is constant, so we can derive an equation:
`v = λ * f`
where:

• `v` is the sound’s velocity
• `λ` (Lowercase Greek letter “lambda”) is the sound’s wavelength, being the constant of proportionality here
• `f` is the sound’s frequency (which represents its pitch)

Another example of two quantities being proportional to each other

You could use Sound.PlaybackSpeed. That is what I use to get the kart effect in Bloxy Kart.

(The jeep in the game is modded a lot btw. They used Sound.Pitch which is deprecated.)

These are the physics formulas for the doppler effect. Basically this states that:

1. the pitch of audio is some constant multiplied by a velocity (faster = higher pitch, slower = lower)
2. The speed of a sound is proportional to its wavelength and its frequency. We hear frequency as pitch and wavelength remains (mostly) constant, so, again, the more speed in a sound wave, the higher the pitch

(@Rare_tendo correct me if you have anything more)

The first equation is more useful here because roblox doesn’t show you wavelength or pitch, so you will want to make a script that relates velocity and pitch, like Rare_tendo said. The formula sound.PlaybackSpeed = Multiplier * Vehicle.Velocity.Magnitude is literally pitch = speed * k, which is exactly how the real life doppler effect occurs.

Back in my previous message I mentioned that you can use SoundService.DopplerScale to do the same thing without scripting, and this probably uses this same formula, but I don’t know what k is when you do that which is why I said to experiment if you want to go down that path

``````local Ratio = Car.DriveSeat.AssemblyLinearVelocity.magnitude / Speed