When using audio sources in unity, they come standard with a fall-off setting to control the volume fall-off over distance.  This may work fine in an open level but will not take obstacles into account, like walls between the source and the player. 

Ok, so why not use reverb zones for this?  They can mute or alter the sound while the player is inside. 

However, this is only useful for sounds that are directly attached to the player.  The most common use-cases are footsteps, gun shots and so on.  And they only come in one handy shape…, spheres. 

So let's build our own reverb zone that affects the source and not the listener and can have any shape.  This will only work for single-player games though, as it will change the source, not each player’s sound perception. 

When the player walks into the next room, the sound emitted inside the distant room will fade gradually, with the door still open.  The volume level will decrease even more while the door is closing.  But it will not be turned off completely. 

Depending on the intensity of the sound, it will still be audible behind the wall but a lot duller and muffled. 

To achieve the muffled sound, every audio source is equipped with a reverb filter.  It will work just like the reverb zone but it only affects the source it is attached to. 

I set up the reverb filters to work for the room where the audio source resides, to have the correct reverb effect while the player is inside the room.  As soon as he leaves, the controller will adjust some of its properties to make it sound dull, like dry level, reverb level and room HF. 

Make sure to use the user preset.  Otherwise you will not be able to change the settings during runtime in the code.  You can also switch presets in code before modifying the values. 

To figure out if the player is inside or outside the room, a simple box collider will do.  When the player walks about outside the trigger, the controller will determine the current door states and the distance to the player. 

Due to the fact that most walls are perfectly straight and not spherical, I added a separate distance fall-off function for the volume level by checking the distance for one axis only, as most rooms are only accessible from one side.