Class: SoundSlot

pc.SoundSlot

The SoundSlot controls playback of an audio asset.

Constructor

new SoundSlot(component, name, options)

Create a new SoundSlot
Parameters:
Name Type Description
component pc.SoundComponent The Component that created this slot.
name String The name of the slot.
options Object Settings for the slot
Properties
Name Type Attributes Default Description
volume Number <optional>
1 The playback volume, between 0 and 1.
pitch Number <optional>
1 The relative pitch, default of 1, plays at normal pitch.
loop Boolean <optional>
false If true the sound will restart when it reaches the end.
startTime Number <optional>
0 The start time from which the sound will start playing.
duration Number <optional>
null The duration of the sound that the slot will play starting from startTime.
overlap Boolean <optional>
false If true then sounds played from slot will be played independently of each other. Otherwise the slot will first stop the current sound before starting the new one.
autoPlay Boolean <optional>
false If true the slot will start playing as soon as its audio asset is loaded.
asset Number <optional>
null The asset id of the audio asset that is going to be played by this slot.
Properties:
Name Type Description
name String The name of the slot
asset String The asset id
autoPlay Boolean If true the slot will begin playing as soon as it is loaded
volume Number The volume modifier to play the sound with. In range 0-1.
pitch Number The pitch modifier to play the sound with. Must be larger than 0.01
startTime Number The start time from which the sound will start playing.
duration Number The duration of the sound that the slot will play starting from startTime.
loop Boolean If true the slot will restart when it finishes playing
overlap Boolean If true then sounds played from slot will be played independently of each other. Otherwise the slot will first stop the current sound before starting the new one.
isLoaded Boolean Returns true if the asset of the slot is loaded.
isPlaying Boolean Returns true if the slot is currently playing.
isPaused Boolean Returns true if the slot is currently paused.
isStopped Boolean Returns true if the slot is currently stopped.
instances Array.<pc.SoundInstance> An array that contains all the pc.SoundInstances currently being played by the slot.
Source:

Methods

(private) _createInstance() → {pc.SoundInstance}

Creates a new pc.SoundInstance with the properties of the slot.
Source:
Returns:
The new instance
Type
pc.SoundInstance

(private) _hasAsset() → {Boolean}

Source:
Returns:
Returns true if the slot has an asset assigned.
Type
Boolean

clearExternalNodes()

Clears any external nodes set by pc.SoundSlot#setExternalNodes.
Source:

getExternalNodes() → {Array.<AudioNode>}

Gets an array that contains the two external nodes set by pc.SoundSlot#setExternalNodes.
Source:
Returns:
An array of 2 elements that contains the first and last nodes set by pc.SoundSlot#setExternalNodes.
Type
Array.<AudioNode>

load()

Loads the asset assigned to this slot.
Source:

pause() → {Boolean}

Pauses all sound instances. To continue playback call pc.SoundSlot#resume.
Source:
Returns:
true if the sound instances paused successfully, false otherwise.
Type
Boolean

play() → {pc.SoundInstance}

Plays a sound. If pc.SoundSlot#overlap is true the new sound instance will be played independently of any other instances already playing. Otherwise existing sound instances will stop before playing the new sound.
Source:
Returns:
The new sound instance
Type
pc.SoundInstance

resume() → {Boolean}

Resumes playback of all paused sound instances.
Source:
Returns:
True if any instances were resumed.
Type
Boolean

setExternalNodes(firstNode, lastNodeopt)

Connect external Web Audio API nodes. Any sound played by this slot will automatically attach the specified nodes to the source that plays the sound. You need to pass the first node of the node graph that you created externally and the last node of that graph. The first node will be connected to the audio source and the last node will be connected to the destination of the AudioContext (e.g. speakers).
Parameters:
Name Type Attributes Description
firstNode AudioNode The first node that will be connected to the audio source of sound instances.
lastNode AudioNode <optional>
The last node that will be connected to the destination of the AudioContext. If unspecified then the firstNode will be connected to the destination instead.
Source:
Example
var context = app.systems.sound.context;
var analyzer = context.createAnalyzer();
var distortion = context.createWaveShaper();
var filter = context.createBiquadFilter();
analyzer.connect(distortion);
distortion.connect(filter);
slot.setExternalNodes(analyzer, filter);

stop() → {Boolean}

Stops playback of all sound instances.
Source:
Returns:
True if any instances were stopped.
Type
Boolean

Events

load

Fired when the asset assigned to the slot is loaded
Parameters:
Name Type Description
sound pc.Sound The sound resource that was loaded
Source:

pause

Fired when a sound instance is paused.
Parameters:
Name Type Description
instance pc.SoundInstance The instance that was paused created to play the sound
Source:

play

Fired when a sound instance starts playing
Parameters:
Name Type Description
instance pc.SoundInstance The instance that started playing
Source:

resume

Fired when a sound instance is resumed..
Parameters:
Name Type Description
instance pc.SoundInstance The instance that was resumed
Source:

stop

Fired when a sound instance is stopped.
Parameters:
Name Type Description
instance pc.SoundInstance The instance that was stopped
Source: