#### Archived

This topic is now archived and is closed to further replies.

# Do any games factor in the speed of sound?

This topic is 5015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was thinking the other day about how sound doesn''t travel at instantaneous speed (obviously) but I think most if not all games model it this way. As an example: Imagine you are standing on a virtual mountain and about 1 KM away an apache helicopter gets hit by a missile and crashes into the ground. You see the helicopter crash into the earth and explode in a fiery explosion. You also hear this explosion as you are seeing it explode. This is the scenario most game engines would do, but in reality you would hear the explosion shortly after seeing the explosion. Does anyone know if any games (or game engines) actually take this type of thing into consideration? I was thinking of modifying my engine to create a sound sphere which would increase in diameter at the speed of the sound, and when that sphere first enveloped a listener, the sound would be instructed to be played.... I dont know if it is worth the effort, but I figure if noone else does it, then maybe I will just to be the first Also, anyone else have an alternative method of implementing this effect? A naive approach would be to get the position of the listener and the position of the sound and precalc how long it would take the sound to reach the listener and then just tell the sound subsystem to start playing the sound in X seconds from now, but this wouldnt handle the case properly in situations where the listener suddenly starts moving towards the sound or perhaps even instantly changes location via a mechanishm such as teleporting or what not. I think my sphere case above would handle that. Well I called it a naive approach, it is actually probably a fairly good approach if you dont mind it not working in some cases. Alternatively, you could create a ton of sound particles and then make them radiate outward from the source and they could be put through collision detection so it would also support occlusion and perhaps even reverberation but I suspect that might suck up a lot more cpu than it is worth... Jeff

##### Share on other sites
In outdoor environments you could probably get away with sound spheres.

##### Share on other sites
I personally don''t know any game that does this. The reason for this is that perhaps most of the games don''t envolve great distances in their worlds. For example, in a fps, you see things "in your face" and most worlds don''t have more than a "square mile" in it.

Another reason might be the fact that certain effects, although fisically correct, might look strange to the person playing the game. For example, those movies where there are explosions in space and you can ear them. Although this is fisically incorrect, it seems much more natural to us then not earing a thing when the ship in front of us just explodes. Sometimes fiction feels more realistic than reality.

##### Share on other sites
operation flashpoint and ofp: resistance by codemasters do this but i dont know how they implement it. you can shoot something from say 800 meters and see the explosion and then a second passes and you hear the boom. i havent heard of any others.

##### Share on other sites
Battlefield 1942 seems to do this with artillery explosions, but I'm not sure how realistic the delay is.

Also, Mechwarrior II seemed to do this, but that's an old one.

Implementing it is easy. You just set up a timed sound play event with location parameters and play the sound when the timer elapses. It gets more complicated if NPC's can be alerted by sounds. Each of them would need a separate timer for realism.

EDIT: Expanding sound spheres would work too, but might be overkill calculation-wise, especially if noone in the area is travelling fast enough for it to make much of a difference.

[edited by - Waverider on March 24, 2004 9:10:15 AM]

##### Share on other sites
I''d have thought the simpler way would be just as good; after all the player will surely move a negligable distance in the time the sound takes to reach him - assuming he''s moving at a realistic speed

##### Share on other sites
Extreme-G 2+3 sorta did this. When you drove above the sound barrier, the music would fade out and get really quiet. Then when you drop back down it would come back with a KABOOM!

##### Share on other sites
This is how most (or every) 3D sound libraries work. If your using headfones, it calculates the distance of the sound to each ear and plays the sound at the correct time. If your in a 5.1 enviroment, it takes 5 calculations

Hope this helps,

JVFF

##### Share on other sites
Battlefield Vietnam : Dolper effects
Wolfenstein Ennemy Territory : sound distortion (not sure if it is delayed but it is realy nice)

--- At The Edge Of Time

##### Share on other sites
I think RTCW did this.
Sometimes if you were getting shot by a sniper from super far away, you would loose health and about 1 second later you would hear the gunshot.

##### Share on other sites
quote:
Original post by AndreTheGiant
I think RTCW did this.
Sometimes if you were getting shot by a sniper from super far away, you would loose health and about 1 second later you would hear the gunshot.

Indeed, and it was a nice effect. You could see the flash of the sniper rifle in the tower, and the report came a short time later. I don''t know how accurate it was, but then again I''ve never been shot at with a Mauser rifle at a great distance.

That game had great sound effects all the way around.

##### Share on other sites
yeah, you can get openAL to use speed of sound calculations and doppler shift and all that sound goodiness with a remarkably few number of function calls. http://www.openal.org/

-me

##### Share on other sites
The MMOG "WW2 Online" uses the speed of sound to great effect (in fact, it makes it really immersive). When you hear an explosion you can pretty much judge how far away it was due to the way the sound also distorts over the distance. Gun fire becomes simple cracks (if you ever watch actual war footage on the news you''ll know what I mean by that). So if you are running towards a battle and see flashes of light and hear the crack of gunfire, it really makes you feel you are there.

##### Share on other sites
I think a new flight sim called "Lock On" did it. Basically if you flew above mach 1 and were in an external view outside of the "cone" you wouldn''t hear anything - at least not the plane engine anymore.

##### Share on other sites
Actually I suspect that many of the games that use real-time doppler etc. (ie. Battlefield to name one) probably do this to extent, because the calculations would be similar... can''t say for sure but I suspect a few do, but we just don''t notice

My guess would be that this type of thing will become completely the realm of the sound hardware in future years... ie. I will tell DirectSound to play this sound, as if it was coming from this exact position in space, relative to where I am. It will figure out all the other fun stuff

##### Share on other sites
3D audio cards already do this - they definetly do doppler shift etc... and I think the result of the correct convolutions is a gross atenutation (silencing) of the audio that works out to the speed-of-sound calculation.

There already is a 3D portion to DirectSound too.

##### Share on other sites
This would be an absolute nightmare to implement on your own, I would imagine. Using your sound sphere idea, you'd have to store a list of players for every sound. If someone is inside the sphere, you can't play the sound over and over again. And you can't assume that a player isn't going to be moving into the sphere anytime soon (if you implement some sort of teleportation method).

Also if you teleport right beside the object, you're in the sphere but the sound has already travelled passed you and thus you can't hear the sound anymore, you'd have to be at the edge.

I'd call it a nightmare not worth the effect =P

[edited by - GroZZleR on March 24, 2004 9:29:50 PM]

##### Share on other sites
I''m pretty sure both OpenAL and DirectSound are capable of dealing with those effects, so you shouldn''t have to code it yourself anymore People have already mentioned some very good games that make use of it.

##### Share on other sites
There''s a difference between doppler/localization, and start delay because of propagation. Most sound APIs do the first, but not the second; you have to do that yourself.

The best way of doing it is probably to just queue an event to play the sound in the future. If you move really quickly towards the sound source, the event will start too late, but that''s probably acceptable.

Also, sound is really quite pokish in air (about 340 m/s) -- you probably want to model sound that travels faster, for increased gaming enjoyment.

##### Share on other sites
it shouldn''t be that hard ... just hand a specialized event to every actor that can "hear", a structure that holds the origin, the velocity of the wave (if it isn''t constant), the velocity of the source (if it isn''t a sudden, point sound), and the time of the sound''s generation. If the actor''s distence is within the sound''s range, the event resolves and gets cleared. Kinda like a mousetrap. You should then have the distence, both velocities for the dopler, and a convenient way to store any additional agent data.
If you want to get really complicated, have the sound do a variation on raycasting -- deteremine vectors that will end up reflecting off various surfaces, and generating new sound objects that are virtually behind that surface. Look at a mirror and gauge where an object appears to be, behind the mirror, against where it is, for a real-life example.
Generating echos based on surfaces *without* tracing if it''ll actually be heard first would likely cause too much overhead. Rather than one check per sound per cycle, it''d be one check per sound one face per cycle. Ouch.

-"Sta7ic" Matt

• ### Forum Statistics

• Total Topics
628735
• Total Posts
2984449

• 25
• 11
• 10
• 16
• 14