Tuesday, October 23, 2012

Overview of the Sound Manager

The sound manager, if you haven’t figured it out from the title, is in charge of playing audio files in the game.  The more recent Battlestar Galactica TV series attempted to be more realistic in its approach to the IP.  Sound does not travel through space, and this game attempts to adhere to that principle.  All sounds in the game come from the actual fighter, like pulling the trigger, or from the communication system.  This made creating a dedicated sound manager appealing for this game. 

There were various design needs inherent to the sound managers.  This required the creation of three sub-classes within this script.  Each class was necessary to keep relevant data within the same list.  The classes are: a source tracker, play tracker and trigger tracker.

The source tracker’s purpose is to make sure that an individual finishes a speech before beginning another speech.  It detracts from realism when another pilot tells you something, and another audio file begins to play with the same pilot telling you something else before the completion of the first statement.  The source tracker is designed to de-conflict these instances.  Every file designed to be spoken by an individual is placed into a source tracker list.  Before playing any clip from any source, the source tracker list is checked to make sure that individual is not already speaking to the pilot.  If he or she is speaking, the new audio is ignored or queued into a play list.

The play list utilizes the play tracker class.  It consists of a reference to the audio file and the source, or speaker, of the audio file.  Every Update(), the play list is checked against the source tracker list.  If the audio file’s speaker is done speaking, the new audio file is played by sound manager.  In essence, this system just delays the speech until it is ready to be played to the player.

Once the audio is played, a trigger needs to be generated at the completion of the audio file and sent to the trigger manager.  The trigger tracker is instrumental in performing this function.  Once the audio file is played, an end time is calculated by adding the current system time index to the length of the audio clip.  This information, along with the clip name, is stored in the trigger list.  Every Update, the trigger list’s contents are checked against the current system time index.  If the record’s time index is less than the system time index, a trigger is sent to the trigger manager.

To make the Update() procedure work properly, there are three distinct play overloads in this script.  The first accepts a clip as a parameter.  This overload method plays the clip without any criteria and designed for sounds that occur despite the source.  An example of this would be sound of the fighter’s gun firing.  Pressing the trigger before the gun audio file completes would cause another gun audio to execute despite the incompletion of the first gun audio.  The second overload method accepts a clip and a source.  This method will play the clip if source is not currently speaking to the player.  If the source is speaking, the clip is ignored and discarded without playing the clip.  Audio files that are not important generally fall into this category.  The third method requires a clip, a source and play list flag.  The play list flag designates this clip as important.  If the speaker is already speaking, the audio file is queued into the play list.  It is played once the speaker is done with its current speech.

Another play option, PlayCheck(), is used to play clips in the play list.  The major difference with this procedure is that it returns a Boolean value.  If the clip is played, due to the availability of the speaker, a true value is returned by the function.  This allows the script to identify whether a clip is played and should be deleted from the play list.

Here is the complete script:

Unlike the trigger manager, I don’t anticipate many changes to the sound manager.  It is relatively complete at this point.  The only thing I would want to add to it is a method to end an audio clip prematurely.  This would be useful in getting a speaker to change his or her speech if something important occurred during a mission.  I’m looking into how to end audio files in Unity; however, I haven’t come up with anything yet…


No comments:

Post a Comment