pc.SoundInstance3d
Extends: pc.SoundInstance
A pc.SoundInstance3d plays a pc.Sound in 3D
Summary
Properties
distanceModel | Determines which algorithm to use to reduce the volume of the audio as it moves away from the listener. |
maxDistance | The maximum distance from the listener at which audio falloff stops. |
position | The position of the sound in 3D space. |
rollOffFactor | The factor used in the falloff equation. |
velocity | The velocity of the sound. |
Inherited
Properties
currentTime | Gets or sets the current time of the sound that is playing. |
duration | The duration of the sound that the instance will play starting from startTime. |
isPaused | Returns true if the instance is currently paused. |
isPlaying | Returns true if the instance is currently playing. |
isStopped | Returns true if the instance is currently stopped. |
isSuspended | Returns true if the instance is currently suspended because the window is not focused. |
loop | If true the instance will restart when it finishes playing |
pitch | The pitch modifier to play the sound with. |
sound | The sound resource that the instance will play. |
source | Gets the source that plays the sound resource. |
startTime | The start time from which the sound will start playing. |
volume | The volume modifier to play the sound with. |
Methods
clearExternalNodes | Clears any external nodes set by pc.SoundInstance#setExternalNodes. |
getExternalNodes | Gets any external nodes set by pc.SoundInstance#setExternalNodes. |
pause | Pauses playback of sound. |
play | Begins playback of sound. |
resume | Resumes playback of the sound. |
setExternalNodes | Connects external Web Audio API nodes. |
stop | Stops playback of sound. |
Events
end | Fired when the sound currently played by the instance ends. |
pause | Fired when the instance is paused. |
play | Fired when the instance starts playing its source |
resume | Fired when the instance is resumed. |
stop | Fired when the instance is stopped. |
Details
Constructor
SoundInstance3d(manager, sound, options)
Parameters
manager | pc.SoundManager | The sound manager |
sound | pc.Sound | The sound to play |
options | Object | Options for the instance |
options.volume | Number | The playback volume, between 0 and 1. |
options.pitch | Number | The relative pitch, default of 1, plays at normal pitch. |
options.loop | Boolean | Whether the sound should loop when it reaches the end or not. |
options.startTime | Number | The time from which the playback will start. Default is 0 to start at the beginning. |
options.duration | Number | The total time after the startTime when playback will stop or restart if loop is true. |
options.position | pc.Vec3 | The position of the sound in 3D space. |
options.velocity | pc.Vec3 | The velocity of the sound. |
options.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. |
options.refDistance | Number | The reference distance for reducing volume as the sound source moves further from the listener. |
options.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. |
options.rollOffFactor | Number | The factor used in the falloff equation. |
Properties
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.
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.
Inherited
Properties
Gets or sets the current time of the sound that is playing. If the value provided is bigger than the duration of the instance it will wrap from the beginning.
Returns true if the instance is currently suspended because the window is not focused.
Gets the source that plays the sound resource. If the Web Audio API is not supported the type of source is Audio. Source is only available after calling play.
Methods
clearExternalNodes()
Clears any external nodes set by pc.SoundInstance#setExternalNodes.
getExternalNodes()
Gets any external nodes set by pc.SoundInstance#setExternalNodes.
Returns
AudioNode[] Returns an array that contains the two nodes set by pc.SoundInstance#setExternalNodes.pause()
Pauses playback of sound. Call resume() to resume playback from the same position.
Returns
Boolean Returns true if the sound was pausedplay()
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.
Returns
Boolean True if the sound was started.resume()
Resumes playback of the sound. Playback resumes at the point that the audio was paused
Returns
Boolean Returns true if the sound was resumed.setExternalNodes(firstNode, [lastNode])
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.
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);
Parameters
firstNode | AudioNode | The first node that will be connected to the audio source of sound instances. |
lastNode | AudioNode | 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. |
stop()
Stops playback of sound. Calling play() again will restart playback from the beginning of the sound.
Returns
Boolean Returns true if the sound was stopped.Events
end
Fired when the sound currently played by the instance ends.
pause
Fired when the instance is paused.
play
Fired when the instance starts playing its source
resume
Fired when the instance is resumed.
stop
Fired when the instance is stopped.