sound SoundThe sound object
volume number optional, default 1How much to scale volume by
rate number optional, default 1The playback rate to use
pan number optional, default 0How much to apply stereo panning
loop boolean optional, default falseShould the sound loop?
paused boolean optional, default falseShould the sound start paused?
// Play a sound and get an instance for control
const jumpSound = new Sound([.5,.5,220]);
const instance = jumpSound.play();
// Control the individual instance
instance.setVolume(.5);
instance.pause();
instance.resume();
instance.stop();
Gain node for the sound, undefined once it is stopped or paused
Called when this instance plays to its end, not when it is stopped
or paused; it is read when the sound ends, so it can be set at any time
Node or effect to route this instance through, copied from the sound
How much to apply stereo panning
Stereo panner for the sound, undefined once it is stopped or paused
Where it is in the sound while not playing, in the sound's own seconds, undefined while playing
Source node of the audio, undefined while not playing
Where it was in the sound at startTime, in the sound's own seconds
Audio context time its place was last taken at, while playing
How much to scale volume by
Get where it is in the sound, in the sound's own seconds: at a rate of 2 it moves two seconds for each one
that passes, and at 0 it stays put
- Returns
Get the length of the sound in its own seconds, the same at any rate; divide by the rate for how long it takes to play
- Returns
- Length in seconds (0 if loading)
Get source of this sound instance
- Returns
- The source, or undefined while not playing
Check if this instance is paused or stopped (not currently playing)
- Returns
Check if this instance is currently playing
- Returns
Pause this sound instance
Resume this sound instance
Set the stereo pan of this sound instance, while it plays too
- A looping sound can follow its source across the screen this way
pan number-1 is left, 0 is center, 1 is right, clamped to that range
Set the playback rate of this sound instance, its speed and pitch, while it plays
- A looping sound can follow something smoothly this way, like an engine with the speed
- A rate of 0 freezes the sound in place, and it carries on from there when the rate comes back
rate number1 is normal, 2 is twice as fast and an octave up
Set the volume of this sound instance, with an optional fade to it
- A fade ducks music under dialogue or cross fades two tracks without a click
volume numberfadeTime number optional, default 0Seconds to fade to the new volume over
Start playing the sound instance from a place in the sound
offset number optional, default 0Where to start in the sound, in its own seconds whatever the rate
Stop this sound instance and reset position to the start
fadeTime number optional, default 0Seconds to fade out over before stopping