ConstantSourceNode

The ConstantSourceNode interface—part of the Web Audio API—represents an audio source (based upon AudioScheduledSourceNode) whose output is single unchanging value. This makes it useful for cases in which you need a constant value coming in from an audio source. In addition, it can be used like a constructible AudioParam by automating the value of its offset or by connecting another node to it; see Controlling multiple parameters with ConstantSourceNode.

A ConstantSourceNode has no inputs and exactly one monaural (one-channel) output. The output's value is always the same as the value of the offset parameter.

Number of inputs 0
Number of outputs 1

Constructor

ConstantSourceNode()
Creates and returns a new ConstantSourceNode instance, optionally specifying an object which establishes initial values for the object's properties. You can also create a ConstantSourceNode whose properties are initialized to their default values by calling AudioContext.createConstantSource().

Properties

Inherits properties from its parent interface, AudioScheduledSourceNode, and adds the following properties:

offset
An AudioParam which specifies the value that this source continuously outputs. The default value is 1.0.

Event handlers

Inherits event handlers from its parent interface, AudioScheduledSourceNode.

Some browsers' implementations of this event handler are part of the  AudioScheduledSourceNode interface.

onended
Fired whenever the ConstantSourceNode data has stopped playing.

Methods

Inherits methods from its parent interface, AudioScheduledSourceNode.

Some browsers' implementations of these methods are part of the AudioScheduledSourceNode interface.

start()
Schedules a sound to playback at an exact time.
stop()
Schedules a sound to stop playback at an exact time.

Example

In the article Controlling multiple parameters with ConstantSourceNode, a ConstantSourceNode is created to allow one slider control to change the gain on two GainNodes. The three nodes are set up like this:

gainNode2 = context.createGain();
gainNode3 = context.createGain();
gainNode2.gain.value = gainNode3.gain.value = 0.5;
volumeSliderControl.value = gainNode2.gain.value;

constantNode = context.createConstantSource();
constantNode.connect(gainNode2.gain);
constantNode.connect(gainNode3.gain);
constantNode.start();

gainNode2.connect(context.destination);
gainNode3.connect(context.destination);

This code starts by creating the gain nodes and setting them and the volume control that will adjust their value all to 0.5. Then the ConstantSourceNode is created by calling AudioContext.createConstantSource(), and the gain parameters of each of the two gain nodes are connected to the ConstantSourceNode. After starting the constant source by calling its start() method. Finally, the two gain nodes are connected to the audio destination (typically speakers or headphones).

Now, whenever the value of constantNode.offset changes, the gain on both gainNode2 and gainNode3 will change to have that same value.

To see this example in action, as well as to read the rest of the code from which these snippets were derived, see Controlling multiple parameters with ConstantSourceNode.

Specification

Specification Status Comment
Web Audio API
The definition of 'ConstantSourceNode' in that specification.
Working Draft  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome No support NoEdge ? Firefox Full support 52
Notes
Full support 52
Notes
Notes ConstantSourceNode inherited from AudioNode initially, but was changed in Firefox 53 to inherit from AudioScheduledSourceNode.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile ? Firefox Android Full support 52
Notes
Full support 52
Notes
Notes ConstantSourceNode inherited from AudioNode initially, but was changed in Firefox 53 to inherit from AudioScheduledSourceNode.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
ConstantSourceNode() constructorChrome No support NoEdge ? Firefox Full support 52IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile ? Firefox Android Full support 52Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
offsetChrome Full support 56Edge No support NoFirefox No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
onendedChrome Full support 14Edge No support NoFirefox No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
IE No support NoOpera No support NoSafari No support NoWebView Android Full support YesChrome Android Full support 18Edge Mobile No support NoFirefox Android No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
startChrome Full support 14Edge No support NoFirefox No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
IE No support NoOpera No support NoSafari No support NoWebView Android Full support YesChrome Android Full support 18Edge Mobile No support NoFirefox Android No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
stopChrome Full support 14Edge No support NoFirefox No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
IE No support NoOpera No support NoSafari No support NoWebView Android Full support YesChrome Android Full support 18Edge Mobile No support NoFirefox Android No support 52 — 53
Notes
No support 52 — 53
Notes
Notes This property is still available, but via the inheritance of AudioScheduledSourceNode.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

See also

Document Tags and Contributors

Contributors to this page: chrisdavidmills, Sheppy, Karlt, raohmaru, fscholz, lukehorvat, jpmedley
Last updated by: chrisdavidmills,