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
|
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. |
Methods
(private) _createInstance() → {pc.SoundInstance}
Creates a new pc.SoundInstance with the properties of the slot.
Returns:
The new instance
- Type
- pc.SoundInstance
(private) _hasAsset() → {Boolean}
Returns:
Returns true if the slot has an asset assigned.
- Type
- Boolean
clearExternalNodes()
Clears any external nodes set by pc.SoundSlot#setExternalNodes.
getExternalNodes() → {Array.<AudioNode>}
Gets an array that contains the two external nodes set by pc.SoundSlot#setExternalNodes.
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.
pause() → {Boolean}
Pauses all sound instances. To continue playback call pc.SoundSlot#resume.
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.
Returns:
The new sound instance
- Type
- pc.SoundInstance
resume() → {Boolean}
Resumes playback of all paused sound instances.
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. |
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.
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 |
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 |
play
Fired when a sound instance starts playing
Parameters:
Name | Type | Description |
---|---|---|
instance |
pc.SoundInstance | The instance that started playing |
resume
Fired when a sound instance is resumed..
Parameters:
Name | Type | Description |
---|---|---|
instance |
pc.SoundInstance | The instance that was resumed |
stop
Fired when a sound instance is stopped.
Parameters:
Name | Type | Description |
---|---|---|
instance |
pc.SoundInstance | The instance that was stopped |