Sound

Sound Object - Stores a sound for later use and can be played positionally

Create sounds using the ZzFX Sound Designer.

Constructor

new Sound(zzfxSound, rangeopt, taperopt)

Create a sound object and cache the zzfx samples for later use

Parameters:
NameTypeAttributesDefaultDescription
zzfxSoundArray

Array of zzfx parameters, ex. [.5,.5]

rangenumber<optional>
soundDefaultRange

World space max range of sound

tapernumber<optional>
soundDefaultTaper

At what percentage of range should it start tapering

Example
// create a sound
const sound_example = new Sound([.5,.5]);

// play the sound
sound_example.play();

Members

loadedPercent

Properties
TypeDescription
number

Percentage of this sound currently loaded

randomness

Properties
TypeDescription
number

How much to randomize frequency each time sound plays

range

Properties
TypeDescription
number

World space max range of sound

sampleRate

Properties
TypeDescription
number

Sample rate for this sound

taper

Properties
TypeDescription
number

At what percentage of range should it start tapering

Methods

getDuration() → {number}

Get how long this sound is in seconds

Returns:
  • How long the sound is in seconds (undefined if loading)
Type: 
number

isLoaded() → {boolean}

Check if sound is loaded, for sounds fetched from a url

Returns:
  • True if sound is loaded and ready to play
Type: 
boolean

play(posopt, volumeopt, pitchopt, randomnessScaleopt, loopopt, pausedopt) → {SoundInstance}

Play the sound Sounds may not play until a user interaction occurs

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

World space position to play the sound if any

volumenumber<optional>
1

How much to scale volume by

pitchnumber<optional>
1

How much to scale pitch by

randomnessScalenumber<optional>
1

How much to scale pitch randomness

loopboolean<optional>
false

Should the sound loop?

pausedboolean<optional>
false

Should the sound start paused

Returns:
  • The audio source node
Type: 
SoundInstance

playMusic(volumeopt, loopopt, pausedopt) → {SoundInstance}

Play a music track that loops by default

Parameters:
NameTypeAttributesDefaultDescription
volumenumber<optional>
1

Volume to play the music at

loopboolean<optional>
true

Should the music loop?

pausedboolean<optional>
false

Should the music start paused

Returns:
  • The audio source node
Type: 
SoundInstance

playNote(semitoneOffset, posopt, volumeopt) → {SoundInstance}

Play the sound as a musical note with a semitone offset This can be used to play music with chromatic scales

Parameters:
NameTypeAttributesDefaultDescription
semitoneOffsetnumber

How many semitones to offset pitch

posVector2<optional>

World space position to play the sound if any

volumenumber<optional>
1

How much to scale volume by

Returns:
  • The audio source node
Type: 
SoundInstance