Class: SoundInstance3d

pc.SoundInstance3d

A pc.SoundInstance3d plays a pc.Sound in 3D

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
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 Whether the sound should loop when it reaches the end or not.
startTime Number <optional>
0 The time from which the playback will start. Default is 0 to start at the beginning.
duration Number <optional>
null The total time after the startTime when playback will stop or restart if loop is true.
position pc.Vec3 <optional>
null The position of the sound in 3D space.
velocity pc.Vec3 <optional>
null The velocity of the sound.
distanceModel String <optional>
pc.DISTANCE_LINEAR 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.
refDistance Number <optional>
1 The reference distance for reducing volume as the sound source moves further from the listener.
maxDistance Number <optional>
10000 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 <optional>
1 The factor used in the falloff equation.
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: