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, will not play if camera is farther away

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

randomness

Properties
TypeDescription
Number

How much to randomize frequency each time sound plays

range

Properties
TypeDescription
Number

World space max range of sound, will not play if camera is farther away

taper

Properties
TypeDescription
Number

At what percentage of range should it start tapering off

Methods

getDuration() → {Number}

Get how long this sound is in seconds

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

getSource() → {AudioBufferSourceNode}

Get source of most recent instance of this sound that was played

Returns:
Type: 
AudioBufferSourceNode

isLoading() → {Boolean}

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

Returns:
  • True if sound is loading and not ready to play
Type: 
Boolean

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

Play the sound

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

World space position to play the sound, sound is not attenuated if null

volumeNumber<optional>
1

How much to scale volume by (in addition to range fade)

pitchNumber<optional>
1

How much to scale pitch by (also adjusted by this.randomness)

randomnessScaleNumber<optional>
1

How much to scale randomness

loopBoolean<optional>
false

Should the sound loop

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode

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

Play the sound as a note with a semitone offset

Parameters:
NameTypeAttributesDefaultDescription
semitoneOffsetNumber

How many semitones to offset pitch

posVector2<optional>

World space position to play the sound, sound is not attenuated if null

volumeNumber<optional>
1

How much to scale volume by (in addition to range fade)

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode

setVolume(volumeopt)

Set the sound volume of the most recently played instance of this sound

Parameters:
NameTypeAttributesDefaultDescription
volumeNumber<optional>
1

How much to scale volume by

stop()

Stop the last instance of this sound that was played