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.
ConstantSourceNode has no inputs and exactly one monaural (one-channel) output. The output's value is always the same as the value of the
Some implementations of this interface inherit from
AudioSourceNode directly, implementing
AudioScheduledSourceNode's properties and methods.
|Number of inputs||
|Number of outputs||
- Creates and returns a new
ConstantSourceNodeinstance, optionally specifying an object which establishes initial values for the object's properties. You can also create a
ConstantSourceNodewhose properties are initialized to their default values by calling
Inherits properties from its parent interface,
AudioScheduledSourceNode, and adds the following properties:
AudioParamwhich specifies the value that this source continuously outputs. The default value is 1.0.
Inherits event handlers from its parent interface,
Some browsers' implementations of this event handler are part of the
Inherits methods from its parent interface,
Some browsers' implementations of these methods are part of the
- Schedules a sound to playback at an exact time.
- Schedules a sound to stop playback at an exact time.
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(); constantSource.connect(gainNode2.gain); constantSource.connect(gainNode3.gain); constantSource.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
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.
|Web Audio API
The definition of 'ConstantSourceNode' in that specification.
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|Basic support||56.0||52 (52)||No support||43||?|
|Feature||Android Webview||Chrome||Firefox Mobile (Gecko)||IE Phone||Opera Mobile||Safari Mobile|
|Basic support||56.0||56.0||52.0 (52)||No support||43||56.0|
 Chrome and Opera implement
stop() directly on this interface.
ConstantSourceNode was introduced in Firefox 52, based directly on
stop() methods were defined directly on this interface, as was the
onended event handler. Starting in Firefox 53, this interface instead inherits from