Audio Sytem

In the early production of 'Kostrejsen' we wanted a new audio system that was had an easier interface than using unity's audio sources, especially easy enough to use that the audio designers with limited code knowledge could implement and play audio in scripts. This audio system was intended to be used on smaller unity projects where using and setting up Fmod or Wwise was a bit of an overkill.

So when I began designing this system I had a meeting with the audio team to hear what they wanted and expected from the system as it was mainly the audio team that would end up using the system. 


The audio system comprises of two main components; the audio manager that plays the audio and the data structures that hold all the data. 

All audio is played via the audio manager, it has control over all the audio sources in the project. These audiosources are in an object pool. This means that all audiosources are only created at startup. The audio system has four tags that an audio being played has; SFX, Voice Over, Ambience & Music. only one audio source of each type can be active at the same time per request of the audio team, except SFX. This means that if another type plays it fades out the existing one. This is because the other ones except SFX are more permanent in the scene and plays over multiple seconds or minutes. Audio also wanted something called 'ducking' when a certain type is played. This means that when an audiosource of this type is played all other sources' volume is lowered. When playing a sound an ID is given into the audiomanager and it tries to look up the ID to find the corresponding audio in its database. 

The other part is the data storage structure. It is a hiearchy of containers, starting with the 'SceneAudioEvents' This is a script that contains all the relevant event collections of the scene. The script adds these collections to the audio manager's database upon loading the scene and removes them when unloading the scene. 

The 'AudioEventCollection' is a scriptable object that contains a list of 'AudioEvents'. The audio collection also has a baking button to it, this button creates a c# script with the audio event IDs written into them, this is so you can access the variables and get the IDs within script. 

The audio event contains a list of 'AudioActions', all of these actions will be played when the audio event is called. It has a play order if we want the audio actions to be sequential - they play one by one in a list, or simultaneous - they play at the same time.

The Audio action holds an 'Audio Container' and an 'Action'. The action can be; stop, loop, play and will determine what the action does upon being called.

The audio container is the smallest structure and holds a list of 'Audioclips' these are just unity's data objects for handling sound. When playing the audio clips a random clip will be played among those in that list. It also stores what audio type it is & holds a mixer.