How do I muffle audio behind walls?

How should I go about muffling audio sources behind walls? Should I have all audio sources have their own audio filter component and a script that linecasts to the audiolistener to know when/how go muffle ? Is there a better way because that sounds very computationally expensive, and tiedeous. (or is it not very computationally expensive?)

If i were to make it muffle per room, how would i get all the audiosources in a room and muffle them? I know theres things like sectr audio but i was curious if i could do at least something without having to buy that

Is it possible or is it too much to ask computationally regardless of how its set up ?
Any help is appreciated

Sound propagation in games is one of the biggest, untapped challenges that game engines do not provide a solution for. Or in the case of Unreal, it’s strictly line-based I believe.

Since you mention rooms, it gets simpler for a Quake-style game. You could create trigger colliders in your rooms and give each audiosource a collider and script which responds to OnTriggerEnter, then disables/destroys the script. By nature of being placed within a trigger collider, this will allow the audiosource (or anything else) to register with a lookup class that maintains a Dictionary<Room, List<AudioSource>>.

Player has the same collider, and whenever the player triggers a new room collider it would enable/disable the respective audio sources. There’s a few caveats to consider (eg overlapping triggers, audio fade in/out highly recommended) but in principle this should work. But it would be rather granular and how well this works depends on the game.

Where it gets really complicated:

  • multiple local players (Unity has a single AudioListener)
  • NPCs being able to listen (computational overhead)

Ray casting will be unrealistic because what happens if the sound source is obscured by a thin post?. It wouldn’t make sense to muffle the sound in that case. A better approach would be using the marching cubes method to see if the sound can eventually reach the camera but that would be expensive. So a more performant method could be to use a navmesh to see if you can calculate a path from the sound source to the player. This is still a little expensive but if your sound is already on an enemy that emits a sound then you can also use the navigation calculation for the audio. So if the enemy can’t reach the player then you could assume that the player can’t hear the enemy.

I imagine games generally don’t bother simulating muffled sounds because it’s barely noticeable even in reality.

I would ask if it would be possible to use renderer.isvisible or occlusion culling to figure out if the object should be muffled or not, but that wouldnt work since looking away would make them muffled too
Hmmm

Yeah and sound is barely affected by line of sight. For a sound to be obviously muffled it needs to be obscured by soft surfaces. So imagine somebody stuck in a wardrobe full of clothes or a coffin.

You are beginning to understand the surface-level complexity of this deceivingly “simple” problem. :wink:

More:

Sound bounces, and loses loudness and frequencies to varying degrees depending on surface material and roughness. Sound can be cancelled out by opposite frequencies (noise cancelling). Can be drowned by louder noises. Perceived loudness is different from “volume”.

I think i will stick to muffling far away rooms like quake then :sob:
Thanks a lot for the help though ! Very informative