Sound functions
|
Note: HeroEngine comes with some Class methods which already make use of the below functions. For information on these, see HeroEngine Audio System.
Sound functions
Play a sound
PlaySound(fileName as String, volume as Float, fadeInLength as Float) as NodeRef
Plays the specified sound at the specified volume. The filename must be a valid FQN (full path and filename). Volume is a float from 1.0 (full volume) to 0.0 (inaudible). FadeInLength is the time in seconds that the sound should fade in from inaudible to the specified volume.
Sounds played with PlaySound are played on a stereo channel. Thus stereo wavs will be properly channeled to left and right speakers. Mono wavs are played equally on both left and right channels.
Example
var mySound = PlaySound("world/livecontent/audio/boom.wav", 1.0, 0.0)
Play a 3D sound space
Play3DSound(fileName as String, volume as Float, fadeInLength as Float, whereAt as Vector3) as NodeRef
Plays the specified sound at the specified volume and positioned at the specified vector in 3d space. A fadeInLength (in seconds) may be specified to have the sound fade in from inaudible to the specified volume.
Example
var location = "(1.5, 0.0, 0.5)" var my3DSound = Play3DSound("world/livecontent/audio/boom.wav", 1.0, 0.0, location)
Looping Sounds
Stopping a looping sound
StopSound(handle as NodeRef)
The StopSound command can be used to stop any sound that is playing. You must pass in the noderef of the playing sound, which is given to you by the PlaySound or Play3DSound function.
Example
function PlayRainSound() as noderef // play the sound var myRainSound = PlaySound("world/livecontent/audio/rain.sgt", 1.0, 0,0) // return the sound noderef so we know what sound to stop later return myRainSound . function StopRainSound(myRainSound as noderef) // stop the sound StopSound(myRainSound) .
Manipulating Sound Volumes
Occasionally, you may need to change the volume of a sound. The following functions support this.
GetSoundVolume(sound as NodeRef) as Float
GetSoundVolume returns the current volume of the specified sound node.
SetSoundVolume(sound as NodeRef, volume as Float, fadeLength as Float) as Boolean
SetSoundVolume changes the volume of the current sound. With this, you can have existing sounds fade out smoothly.
Example
function FadeOutSound(theSound as noderef) // fade sound to inaudible over 3 seconds SetSoundVolume(theSound, 0.0, 3.0) .