One aspect of Hevn that is very important for immersion is the audio and sound effects - specifically the "muffling" of sounds. By "muffling" I mean adding a low pass filter to an audio or sound. If you're unfamiliar with what a low pass filter does, imagine listening to music playing from a separate closed-off room from the one you're currently in. The lower frequencies (i.e. bass) can be heard through the walls while the higher frequencies are attenuated, or not heard as clearly. In this post, we'll discuss how this is currently handled in the game.
Before getting into the details of how we're applying low pass filters to various audio sources, I thought I'd share a short video of how it currently sounds in an early test scene in the game. Note you may need to turn the volume up a bit for it to be heard properly. Also please disregard the extra mouse pointers.
A few things to listen for in the video:
- Sound of the wind being muffled when the door closes while the player is inside.
- Sound of the footsteps both outside and inside are similar.
- Sound of the indoor vent blowing air is unmuffled.
- Sound of the player's breath before and after equipping a helmet. Note the wind (or outdoor) sounds are muffled even more when the helmet closes.
- Sound of everything after the player leaves the indoor space and opens the helmet.
Let's take a look at how the simple concept of "muffling" a sound was handled in this setup.
There are several cases where applying a low pass filter on an audio source is ideal:
- Walking indoors directly from outdoors and vice versa.
- Equipping or un-equipping a helmet.
- Opening or closing a previously equipped helmet.
- The combination of being indoors or outdoors and equipping and un-equipping a helmet.
- When the player's character experiences anxiety or panic.
Let's expand on the first scenario above. In a typical outdoor scene there will likely be several ambient sounds playing such as the wind, creature sounds, machinery sounds, ships, etc. In addition to that, there are also sounds that are closer to the player's proximity such as footsteps, clothes rustling, breathing, etc. When the character is outside, all sounds will play unmuffled. When the character travels indoors (while still being enclosed in an outdoor space) , we'll need to preserve sounds that are physically closer to the character and muffle sounds that are farther away or outside of the indoor space.
To manage all of these sounds and how they relate to the player, we created a relatively simple AudioManager class along with a concept of custom audio layers.
Audio Manager and Layers
Currently the AudioManager component is responsible for several things:
- Ensure every AudioSource contains an accompanying LowPassFilterComponent.
- Handle the creation of runtime AudioSources.
- Manage the low pass filters by increasing or decreasing the cutoff frequency over time, depending on the state of the scene and player. This ensures that the filter sounds relatively natural, such as when slowly opening or closing a door.
Now that we can be sure that every piece of audio is filterable, we need a way to manage what gets filtered and when. Note this will also help to ensure we're minimizing our CPU usage for the DSP required. That's currently done using the concept of custom audio layers. Here are the layers along with a brief description of the types of audio or sounds associated with them:
- Default - Every audio source in the game that does not fall into one of the bottom three layers.
- Player - Audio associated with the player's physical actions such as footsteps, clothes rustling, equipping a body suit/shoes/helmet, picking up objects and handling them, etc. The filter for audio outside of this layer is set to 500Hz. In the example video above, all of the sounds outside of the room were filtered at 500Hz.
- Helmet - Audio heard inside of a helmet. This includes the player's breathing sounds, menu sounds, or anything that can be heard inside a typical helmet. The filter for audio outside of this layer is set at 350Hz. In the example video above all sounds both outside and inside the room were filtered at 350Hz.
- Narration - Audio associated with the narrative aspect of the game or music. This can also include the player's own thoughts presented as an audible voice or "in-ear" sound such as tinnitus.
With every AudioSource and filter associated to a layer, we're now able to plug the AudioManager into the existing custom CullingManager to essentially enable low pass filter's according to the player's location, attribute state, and contents of the player's inventory (i.e. is the player wearing a helmet).
When the player leaves the outdoor space by opening a door and entering a room, the appropriate low pass filters kick in and gradually decrease over time as the door closes. While indoors, if the player equips a helmet, the low pass filters for both the outdoor and indoor sounds will be filtered as well. At this point the only unfiltered audio is inside the player's helmet (and narration if it's playing). The opposite happens if the helmet is opened.
Hopefully this helps to make Hevn that much more immersive. Until the next post, thanks so much for reading! Much appreciated!