Create a new SoundInstance3d instance.
The sound manager.
The sound to play.
Options for the instance.
Determines which algorithm to use to reduce the volume of the audio as it moves away from the listener. Can be:
Defaults to DISTANCE_LINEAR.
The total time after the startTime when playback will stop or restart if loop is true.
Whether the sound should loop when it reaches the end or not. Defaults to false.
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. Defaults to 10000.
The relative pitch. Defaults to 1 (plays at normal pitch).
The position of the sound in 3D space.
The reference distance for reducing volume as the sound source moves further from the listener. Defaults to 1.
The factor used in the falloff equation. Defaults to 1.
The time from which the playback will start. Default is 0 to start at the beginning.
The playback volume, between 0 and 1. Defaults to 1.
Private
_positionPrivate
_velocityGets 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.
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.
Determines which algorithm to use to reduce the volume of the audio as it moves away from the listener. Can be:
Default is DISTANCE_LINEAR.
The duration of the sound that the instance will play starting from startTime.
Returns true if the instance is currently paused.
Returns true if the instance is currently playing.
Returns true if the instance is currently stopped.
Returns true if the instance is currently suspended because the window is not focused.
If true the instance will restart when it finishes playing.
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.
The pitch modifier to play the sound with. Must be larger than 0.01.
The reference distance for reducing volume as the sound source moves further from the listener.
The factor used in the falloff equation.
The start time from which the sound will start playing.
The volume modifier to play the sound with. In range 0-1.
Private
_initializeClears any external nodes set by SoundInstance#setExternalNodes.
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message');
Gets any external nodes set by SoundInstance#setExternalNodes.
Returns an array that contains the two nodes set by SoundInstance#setExternalNodes.
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
obj.on('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
const evt = obj.on('test', function (a, b) {
console.log(a + b);
});
// some time later
evt.off();
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
obj.once('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled
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.
const context = app.systems.sound.context;
const analyzer = context.createAnalyzer();
const distortion = context.createWaveShaper();
const filter = context.createBiquadFilter();
analyzer.connect(distortion);
distortion.connect(filter);
instance.setExternalNodes(analyzer, filter);
Static
EVENT_Fired when the sound currently played by the instance ends.
instance.on('end', () => {
console.log('Instance ended');
});
Static
EVENT_Fired when the instance is paused.
instance.on('pause', () => {
console.log('Instance paused');
});
Static
EVENT_Fired when the instance starts playing its source.
instance.on('play', () => {
console.log('Instance started playing');
});
Static
EVENT_Fired when the instance is resumed.
instance.on('resume', () => {
console.log('Instance resumed');
});
Static
EVENT_Fired when the instance is stopped.
instance.on('stop', () => {
console.log('Instance stopped');
});
A SoundInstance3d plays a Sound in 3D.