AudioComponent

Overview

This is the lowest component in a hierarchy and extends Unity’s existing audio source component functionality. An audio component cannot have any children components attached.

In the audio component it is possible to:

  • Set the audio clip that will be used to play audio, delay it
  • Disable it from the audio component virtualization (if enabled in the Fabric manager)
  • Keep the audio playing even if the parent game object has been destroyed
  • Play audio clip
  • Read loop markers from wavfile.
    • Define
  • Loop
    • Define num of loops
    • Loop infinitely until stopped
  • Randomise position
  • Dynamic load the audio clip
    • In Unity 4.5.3> the Resourcesw.LoadAsync is used, in previous version WWW is used
  • Sync with global music selection set in the component properties
    • Delay the start of the audio components by a number of beats

 

Dynamic AudioClip Loading

By Enabling this option Fabric will manage the loading of the audio data into memory automatically depending the audio clip options (for Unity 5+). For example if an audio component ir requested to play an instance for the first time the audio data will be loaded into memory and then will only get unloaded if all instances have stopped playing.

It is also possible to post LoadAudio/UnloadAudio event actions to any component in the Fabric hierarchy causing all audio components located underneath to load/unload their audio data into/from the audio memory.

Dynamic AudioClip Loading

Using AudioClip Path

When the dynamic audio clip option is selected for the first time the "Use AudioClip Path" behavior is enabled which uses Unity's Resource.Load function to load the audio clip into memory. This is the first implementation of this feature and was design with Unity 4 in mind. The main reason enabled by default mainly to support existing games.

Using AudioClip Path

AudioClip Loading options

In Unity 5+ the audio clip now provides two different options for loading the audio data,

  • Load In Background: Loads the audio data Asynchronously without stalling the game
  • Preload Audio Data: The audio data will load into memory the moment it is referenced by an audio component
AudioClip Loading options

Markers and Regions

The Audio Componebnt can load Markers and Regions that are saved within the audio file that is set to play.

NOTE: This is a manual process and its up to you to ensure that the markers are loaded/unloaded when a new audio file is selected.

MARKERS

When loading Markers it is possible to set the type of notification the audio component will send to its parent. This is useful if the audio component is part of a Sequence or Switch hiearchy tconfigured to sync on a marker and that way instruct them when to advance.

It is also possible to specify which the loop region using the markers and randomize the start or end marker from the list available. The randomization occurs everytime the sound has been looped.

 

Marker Notification Types Description
Ignore Marker is ignored
Notify Marker notifies the parent and keeps playing
Notify And Play To End
Marker notifies parent component and plays until the end and then stops
Notify And Stop Marker notifies parent component and stops

REGIONS

The audio component can also load Regions such as 'Sample Loops' and provide an option to set the active looop section.

When the "Randomize Region" option is enabled the audio component will pick a new loop region in random everytime a loop is played.

Inspector Elements

Properties

Description

Ignore Virtualization

Audio component won’t be virtualized (stopped) according to distance from listener.

Don’t Play

Audio component won’t play.

Delay

How much to delay (is seconds) the component from playing

Don’t Stop On Destroy

Keeps playing when it’s parent game object is destroyed. The last know position of the game object is used.

Loop

Pitch value of the component multiplied with/by its parent pitch.

Ignore Native Loop Use audio components loop support (uses two audio sources but supports web deployment)
Randomize Start

Picks a random point on the audio file to start playing

Randomiz Start Percentage

Percentage of the audio file length to choose random position

Load Markers

Load markers from audio clip (must be wavfile)

Unload Markers

Unload existing markers

Num Of Loops

Number of time to loop the audio component (or marker region) before stopping

Infinite

Loop audio component infinite times

Randomise Position

Randomise position within a min/max sphere

Randomise Max Position

Max position used in randomisation

Randomise Min Position

Min position used in randomisation

Audio Clip

Audio clip to play.

Dynamic AudioClip Loading

Audio clip is loaded into memory when its played for the first time. It will stay in memory until all instances have stopped playing.

Use AudioClip Path Stores and uses the audio clip path to load the audio clip into memory. It only works if the Audio Clip is located inside a Resources folder. It is enabled by default for backwards compatibility, with Unity 5 this option is not important if the Preload Audio is disabled

Async Loading

Loads the audio clip asynchronously without blocking the Unity thread.

 

NOTE: In Unity3D <4.5.3 This option uses the WWW class which duplicates the audio memory for each instance playing. In Unity3D >4.5.3 its using the Resources.AsyncLoad

In Unity 5 AudioClip provides a Load In Background option so this option is not required.

Sync With Global Music

Audio component will start playing in sync with the music time settings selected.

 

Note: This option is not available if the component is already in a hierarchy with the music sync option enabled.

Delay In Beats

 

Status

Displays the current status of the audio component

-          WaitingToPlay

-          Playing

-          WaitingToStop

-          Stopped

-          Paused

-          Virtual

-          LostFocus

Code Support

AudioComponent provides the following code features,

 

- SetMarker: If the audio clip has wavfile markers and they are loaded it is possible to set the playing position using the marker label, this is achieved by posting a SetMarker event action passing the name of the marker,

Fabric.EventManager.Instance.PostEvent("NAME OF EVENT", Fabric.EventAction.SetMarker, "marker name", gameObject);

 

Link to a video explaining more about Audio Components and event triggers

https://www.youtube.com/watch?v=zzsv8__PvNw&index=2&list=PLjo4vf11pt-MWtpdnyJdqJ41khf4YhS8y