PowerQuest 0.19.4
All Classes Namespaces Functions Variables Enumerations Properties Pages
SystemAudio Class Reference

Detailed Description

The PowerQuest Audio System. Provides convenient, 2d specific audio functionality, using audio cues.

Audio Functions are accessable from QuestScripts using Audio., or from other scripts from using the static class SystemAudio.

Examples:

Audio.Play("Explosion");
Audio.PlayMusic("WikkidBeats");
Audio.Play("BeachAmbience").FadeIn(3.0f); // start a looping sound and fade it in
....
Audio.PlayMusic("ChillBeats", 2.0f); // crossfade to new track
Audio.Stop("BeachAmbience",0.5f); // stop the loopsing sound, fading over 0.5 sec.

Features:

  • This is an audio cue based system. You create an AudioCue in your project, set up which clips it plays and data like volume, pitch, etc. Then you play that "Cue".
  • See the Audio manual for info on Sound Cues
  • Cues can be added to SystemAudio so that you can play them by name. Then it's as simple as calling Audio.Play("gunshot");
  • Cues have a lot of controls for randomisation so common sounds don't get repetive: set min/max pitch, a list of clips to randomly choose from, and even string multiple cues together with random delays
  • Type based volume control: Flag cues with a type (eg SoundEffect, Music, Dialog), and then set those volumes seperately
  • Simple functions for playing music and an ambient loop and crossfading between them
  • Stop/Pause/Modify volume/pitch/pan, etc of currently playing sounds by their cue name, or the AudioHandle returned from the Play Function. eg: Audio.GetHandle("gunshot").pitch = 0.5f, Audio.Stop("gunshot");
  • Ducking of music when playing dialog
  • Simple 2d falloff and stereo control: Some basic controls set how sounds get quieter, and move left/right based on their position relative to the camera
  • Automatic pooling system for efficiency
  • Save/Restore audio state

Inherits SingletonAuto< SystemAudio >.

Properties

static AudioHandle MusicHandle [get]
 The AudioHandle for the currently playing Music track.
 
static float FalloffDistanceMultiplier [get, set]
 A multiplier on the falloff distance for volume/panning. Useful when you want to bring it in close, or expand it outwards temporarily.
 
static float AnimSoundMult [get, set]
 
static bool ShouldRestartMusicIfAlreadyPlaying [get]
 Flag to set whether playing the same music cue again will restart it, or leave the old one playing.
 

Static Public Member Functions

static float GetVolume (AudioCue.eAudioType type)
 Retrieves the volume for audio of a particular type (eg: Sound effects, Music, Dialog)
 
static AudioCue GetCue (string cueName)
 Retrieves a sound cue by name.
 
static bool IsPlaying (string cueName)
 Returns true if the cue is currently playing, otherwise false.
 
static AudioHandle Play (string cueName, Transform emmitter=null)
 Play a cue by name. This is the main way to play sounds. If emmitter is set, the sound will falloff/pan as it goes off camera.
 
static AudioHandle Play (AudioCue cue, Transform emitter=null, float volumeMult=1, float pitchMult=1, float fromTime=0, float withStartDelay=0)
 Play the specified cue with extended options. If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue.
 
static AudioHandle Play (AudioCue cue, ref List< AudioHandle > handles, Transform emmitter=null, float volumeMult=1, float pitchMult=1, float fromTime=0, float withStartDelay=0)
 Advanced Play function with extended options, and returning a list of all handles started (for when multiple are started). If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue.
 
static AudioHandle Play (AudioClip clip, int type=(int) AudioCue.eAudioType.Sound, Transform emmitter=null, float volume=1, float pitch=1, bool loop=false, AudioMixerGroup mixerGroup=null)
 Plays a specific audio clip rather than an audio cue.
 
static void Pause (AudioHandle handle)
 Pauses the specified sound by it's handle.
 
static void UnPause (AudioHandle handle)
 Resumes the specified sound by it's handle.
 
static void Pause (string cueName)
 Pauses the specified sound by it's cue name.
 
static void UnPause (string cueName)
 Resumes the specified sound by it's cue name.
 
static AudioHandle GetHandle (string cueName)
 Gets a playing AudioHandle by its cue name.
 
static AudioHandle[] GetHandles (string cueName)
 Gets any currently playing AudioHandles by their cue name.
 
static void Stop (string cueName, float overTime=0)
 Stops the specified sound by it's cue name.
 
static void Stop (AudioHandle handle, float overTime=0, float afterDelay=0)
 Stops the specified sound by it's handle.
 
static AudioHandle PlayMusic (string cueName, float fadeTime=0)
 Play a music track using the cue name, with optional crossfade time.
 
static AudioHandle PlayMusic (string cueName, float fadeOutTime, float fadeInTime)
 Play a music track using the cue name, with seperate fade out and fade in times.
 
static AudioHandle PlayMusic (AudioCue cue, float fadeTime=0)
 Play a music cue, with optional crossfade time.
 
static AudioHandle PlayMusic (AudioCue cue, float fadeOutTime, float fadeInTime)
 Play a music cue, with seperate fade out and fade in times.
 
static AudioSource PlayMusicSynced (string name, float fadeTime, float volumeOverride=0)
 Play a music track using the cue name, Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier.
 
static AudioSource PlayMusicSynced (AudioCue cue, float fadeTime, float volumeOverride=0)
 Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier.
 
static void StopMusic (float fadeTime=0, float afterDelay=0)
 Stops the currently playing music, with optional fade out time.
 
static void PlayAmbientSound (string name, float fadeTime=0.4f)
 Plays an ambient sound by it's cue name, with optional fade time. Sound cue is assumed to be looping.
 
static void PlayAmbientSound (string name, float fadeoutTime, float fadeInTime)
 Plays an ambient sound by it's cue name, with seperate fade out and fade in times. Sound cue is assumed to be looping.
 
static void StopAmbientSound (float overTime=0.4f)
 Stops the current ambient sound cue, with optional fade time.
 
static void UpdateCustomFalloff (string cueName, Vector2 soundPos, Vector2 listenerPos, float closeDist, float farDist, float farVol=0, float closeVol=1, float farPan=0.7f)
 Sets a sound's volume and stereo pan based on distance to it. Use this function when you want sounds to be louder when standing near them, and quieter as you walk away. The function should be placed in your room's Update() function. eg. ~~~ void Update()
 
static float ToDecibel (float linear)
 
static float FromDecibel (float dB)
 

Public Member Functions

bool StopHandleInternal (AudioHandle handle, float overTime=0, float afterDelay=0)
 

Property Documentation

◆ MusicHandle

AudioHandle MusicHandle
staticget

The AudioHandle for the currently playing Music track.

See also
PlayMusic
StopMusic

◆ FalloffDistanceMultiplier

float FalloffDistanceMultiplier
staticgetset

A multiplier on the falloff distance for volume/panning. Useful when you want to bring it in close, or expand it outwards temporarily.

◆ ShouldRestartMusicIfAlreadyPlaying

bool ShouldRestartMusicIfAlreadyPlaying
staticget

Flag to set whether playing the same music cue again will restart it, or leave the old one playing.

Member Function Documentation

◆ GetVolume()

static float GetVolume ( AudioCue.eAudioType type)
inlinestatic

Retrieves the volume for audio of a particular type (eg: Sound effects, Music, Dialog)

◆ GetCue()

static AudioCue GetCue ( string cueName)
inlinestatic

Retrieves a sound cue by name.

◆ IsPlaying()

static bool IsPlaying ( string cueName)
inlinestatic

Returns true if the cue is currently playing, otherwise false.

◆ Play() [1/4]

static AudioHandle Play ( string cueName,
Transform emmitter = null )
inlinestatic

Play a cue by name. This is the main way to play sounds. If emmitter is set, the sound will falloff/pan as it goes off camera.

Eg: Audio.Play("DoorKnock"); Audio.Play("Gunshot", C.Gunman.Instance); Audio.Play("SeasideAmbience").FadeIn(2.0f);

◆ Play() [2/4]

static AudioHandle Play ( AudioCue cue,
Transform emitter = null,
float volumeMult = 1,
float pitchMult = 1,
float fromTime = 0,
float withStartDelay = 0 )
inlinestatic

Play the specified cue with extended options. If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue.

◆ Play() [3/4]

static AudioHandle Play ( AudioCue cue,
ref List< AudioHandle > handles,
Transform emmitter = null,
float volumeMult = 1,
float pitchMult = 1,
float fromTime = 0,
float withStartDelay = 0 )
inlinestatic

Advanced Play function with extended options, and returning a list of all handles started (for when multiple are started). If emmitter is set, the sound will falloff/pan as it goes off camera. Can also set volume and pitch overrides, and override the start time of the cue.

◆ Play() [4/4]

static AudioHandle Play ( AudioClip clip,
int type = (int)AudioCue::eAudioType::Sound,
Transform emmitter = null,
float volume = 1,
float pitch = 1,
bool loop = false,
AudioMixerGroup mixerGroup = null )
inlinestatic

Plays a specific audio clip rather than an audio cue.

◆ Pause() [1/2]

static void Pause ( AudioHandle handle)
inlinestatic

Pauses the specified sound by it's handle.

◆ UnPause() [1/2]

static void UnPause ( AudioHandle handle)
inlinestatic

Resumes the specified sound by it's handle.

◆ Pause() [2/2]

static void Pause ( string cueName)
inlinestatic

Pauses the specified sound by it's cue name.

◆ UnPause() [2/2]

static void UnPause ( string cueName)
inlinestatic

Resumes the specified sound by it's cue name.

◆ GetHandle()

static AudioHandle GetHandle ( string cueName)
inlinestatic

Gets a playing AudioHandle by its cue name.

◆ GetHandles()

static AudioHandle[] GetHandles ( string cueName)
inlinestatic

Gets any currently playing AudioHandles by their cue name.

◆ Stop() [1/2]

static void Stop ( string cueName,
float overTime = 0 )
inlinestatic

Stops the specified sound by it's cue name.

◆ Stop() [2/2]

static void Stop ( AudioHandle handle,
float overTime = 0,
float afterDelay = 0 )
inlinestatic

Stops the specified sound by it's handle.

◆ PlayMusic() [1/4]

static AudioHandle PlayMusic ( string cueName,
float fadeTime = 0 )
inlinestatic

Play a music track using the cue name, with optional crossfade time.

◆ PlayMusic() [2/4]

static AudioHandle PlayMusic ( string cueName,
float fadeOutTime,
float fadeInTime )
inlinestatic

Play a music track using the cue name, with seperate fade out and fade in times.

◆ PlayMusic() [3/4]

static AudioHandle PlayMusic ( AudioCue cue,
float fadeTime = 0 )
inlinestatic

Play a music cue, with optional crossfade time.

◆ PlayMusic() [4/4]

static AudioHandle PlayMusic ( AudioCue cue,
float fadeOutTime,
float fadeInTime )
inlinestatic

Play a music cue, with seperate fade out and fade in times.

◆ PlayMusicSynced() [1/2]

static AudioSource PlayMusicSynced ( string name,
float fadeTime,
float volumeOverride = 0 )
inlinestatic

Play a music track using the cue name, Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier.

◆ PlayMusicSynced() [2/2]

static AudioSource PlayMusicSynced ( AudioCue cue,
float fadeTime,
float volumeOverride = 0 )
inlinestatic

Crossfades beteween two music tracks, attempting to keep them synced (assumes identical length/tempo/etc). Optional volume multiplier.

◆ StopMusic()

static void StopMusic ( float fadeTime = 0,
float afterDelay = 0 )
inlinestatic

Stops the currently playing music, with optional fade out time.

◆ PlayAmbientSound() [1/2]

static void PlayAmbientSound ( string name,
float fadeTime = 0::4f )
inlinestatic

Plays an ambient sound by it's cue name, with optional fade time. Sound cue is assumed to be looping.

◆ PlayAmbientSound() [2/2]

static void PlayAmbientSound ( string name,
float fadeoutTime,
float fadeInTime )
inlinestatic

Plays an ambient sound by it's cue name, with seperate fade out and fade in times. Sound cue is assumed to be looping.

◆ StopAmbientSound()

static void StopAmbientSound ( float overTime = 0::4f)
inlinestatic

Stops the current ambient sound cue, with optional fade time.

◆ UpdateCustomFalloff()

static void UpdateCustomFalloff ( string cueName,
Vector2 soundPos,
Vector2 listenerPos,
float closeDist,
float farDist,
float farVol = 0,
float closeVol = 1,
float farPan = 0::7f )
inlinestatic

Sets a sound's volume and stereo pan based on distance to it. Use this function when you want sounds to be louder when standing near them, and quieter as you walk away. The function should be placed in your room's Update() function. eg. ~~~ void Update()

~~~

Parameters
cueNameCue name to fade.
soundPosThe location of the sound. Eg: P.Fireplace.LookAtPoint.
listenerPosThe location of the listener (usually the player). Eg: C.Player.Position.
closeDistHow close should the player be to the sound for it to be at maxVol. In game units.
farDistHow far should the player be from the sound for it to be at minVol. In game units.
farVolThe volume when the player is standing FAR from the sound (eg. quiet). From 0 to 1.
closeVolThe volume when the player is standing CLOSE to the sound (eg. loud). From 0 to 1.
farPanThe maximum amount to pan in stereo, when the player is FAR from the sound. From 0 to 1.