Constructor
new SoundInstance3d(manager, sound, options)
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
manager |
pc.SoundManager | The sound manager | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sound |
pc.Sound | The sound to play | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options |
Object | Options for the instance
Properties
|
Properties:
Name | Type | Description |
---|---|---|
position |
pc.Vec3 | The position of the sound in 3D space. |
velocity |
pc.Vec3 | The velocity of the sound. |
distanceModel |
String | Determines which algorithm to use to reduce the volume of the audio as it moves away from the listener. Can be one of pc.DISTANCE_LINEAR, pc.DISTANCE_INVERSE or pc.DISTANCE_EXPONENTIAL. Default is pc.DISTANCE_LINEAR. * @property {Number} refDistance The reference distance for reducing volume as the sound source moves further from the listener. |
maxDistance |
Number | The maximum distance from the listener at which audio falloff stops. Note the volume of the audio is not 0 after this distance, but just doesn't fall off anymore. |
rollOffFactor |
Number | The factor used in the falloff equation. |
- Source:
Extends
Methods
(private) _initializeNodes()
Creates internal audio nodes and connects them
- Inherited From:
- Source:
(private) _onManagerDestroy()
Handle the manager's 'destroy' event.
- Overrides:
- Source:
(private) _onManagerResume()
Handle the manager's 'resume' event.
- Inherited From:
- Source:
(private) _onManagerSuspend()
Handle the manager's 'suspend' event.
- Inherited From:
- Source:
(private) _onManagerVolumeChange()
Handle the manager's 'volumechange' event.
- Inherited From:
- Source:
(private) _updateCurrentTime()
Sets the current time taking into account the time the instance started playing, the current pitch and the current time offset.
- Inherited From:
- Source:
clearExternalNodes()
Clears any external nodes set by pc.SoundInstance#setExternalNodes.
- Inherited From:
- Source:
getExternalNodes() → {Array.<AudioNode>}
Gets any external nodes set by pc.SoundInstance#setExternalNodes.
- Inherited From:
- Source:
Returns:
Returns an array that contains the two nodes set by pc.SoundInstance#setExternalNodes.
- Type
- Array.<AudioNode>
pause() → {Boolean}
Pauses playback of sound. Call resume() to resume playback from the same position.
- Inherited From:
- Source:
Returns:
Returns true if the sound was paused
- Type
- Boolean
play() → {Boolean}
Begins playback of sound. If the sound is not loaded this will return false.
If the sound is already playing this will restart the sound.
- Inherited From:
- Source:
Returns:
True if the sound was started.
- Type
- Boolean
resume() → {Boolean}
Resumes playback of the sound. Playback resumes at the point that the audio was paused
- Inherited From:
- Source:
Returns:
Returns true if the sound was resumed.
- Type
- Boolean
setExternalNodes(firstNode, lastNodeopt)
Connects external Web Audio API nodes. 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). Requires Web Audio API support.
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. |
- Inherited From:
- 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);
instance.setExternalNodes(analyzer, filter);
stop() → {Boolean}
Stops playback of sound. Calling play() again will restart playback from the beginning of the sound.
- Inherited From:
- Source:
Returns:
Returns true if the sound was stopped.
- Type
- Boolean
Events
end
Fired when the sound currently played by the instance ends.
- Inherited From:
- Source:
pause
Fired when the instance is paused.
- Inherited From:
- Source:
play
Fired when the instance starts playing its source
- Inherited From:
- Source:
resume
Fired when the instance is resumed.
- Inherited From:
- Source:
stop
Fired when the instance is stopped.
- Inherited From:
- Source: