- Home /
Speed of sound delay adjustment
Hi, I'm working on a project that involves a moving object emitting a noise, to be heard by a stationary observer. When an object is moving and emitting sound, there is a Doppler shift, which Unity handles. But there is also a delay in when the sound that it produces hits your ears. This happens with every sound, but is most obvious at far distances and high speeds. If you've ever been to an airshow, you'll be familiar with what I'm trying to replicate. The sound of the aircraft seems to come from the location where it was moments before because the image of the aircraft moves faster than the sound does.
I've seen Answer threads about a stationary sound, like an explosion or a gunshot propagating forward, which would only require an AudioSource.PlayDelayed() call, but I don't think that would help me as starting and stopping the sound every game update would add a choppy noise and the delay needs to shift every update based on the new location of the object.
I'm able to find the delay in time very easily with the magnitude of the vector between object and listener and the speed of sound, but I'm having trouble applying this to the Audio. What I had in mind was an audio delay that continually updated with the object's location. I've noticed in the scripting reference and manual that there used to be an Audio Mixer effect that was a simple delay, but I don't see that in my version of Unity (5.6.3f1). Any ideas?
Answer by MichaeA · Apr 30, 2018 at 12:48 PM
So this morning I realized I could get the AudioSource to come from the right location by simply lagging the source behind the game object in space so that the sound would appear to come from where the object was. However, this still doesn't change the sound to be the same as what it was X seconds ago. Which I still will need to figure out for it to sound right.
Finally got it. To fix the rest of this issue, I attached and Audio Echo Filter with the delay modulated by vector magnitude between source and listener. The rest of the settings are to have DecayRatio = 0, Wet$$anonymous$$ix = 1, Dry$$anonymous$$ix = 0.
DecayRatio(0) makes the echo repeat only once. Wet$$anonymous$$ix(1) makes the echo at full volume. Dry$$anonymous$$ix(0) eli$$anonymous$$ates the original sound, leaving only the Echo, which is delayed by the modulated delay.
With the AudioSource shifted backwards from the visual object, and the sound actively delayed by the filter, it appears quite a bit closer to real life.