ConstantSourceNode

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 参数。

Number of inputs 0
Number of outputs 1

构造函数

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() .

特性

继承特性来自其父级接口 AudioScheduledSourceNode , and adds the following properties:

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

事件处理程序

Inherits event handlers from its parent interface, AudioScheduledSourceNode .

Some browsers' implementations of this event handler are part of the AudioScheduledSourceNode 接口。

onended
Fired whenever the ConstantSourceNode data has stopped playing.

方法

Inherits methods from its parent interface, AudioScheduledSourceNode .

Some browsers' implementations of these methods are part of the AudioScheduledSourceNode 接口。

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

范例

In the article Controlling multiple parameters with ConstantSourceNode ConstantSourceNode is created to allow one slider control to change the gain on two GainNode s. 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.

规范

规范 状态 Comment
Web 音频 API
The definition of 'ConstantSourceNode' in that specification.
工作草案

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
ConstantSourceNode Chrome 56 Edge ≤79 Firefox 52
注意事项
52
注意事项
ConstantSourceNode inherited from AudioNode initially, but was changed in Firefox 53 to inherit from AudioScheduledSourceNode .
IE 不支持 No Opera 43 Safari 不支持 No WebView Android 56 Chrome Android 56 Firefox Android 52
注意事项
52
注意事项
ConstantSourceNode inherited from AudioNode initially, but was changed in Firefox 53 to inherit from AudioScheduledSourceNode .
Opera Android 43 Safari iOS 不支持 No Samsung Internet Android 6.0
ConstantSourceNode() 构造函数 Chrome 56 Edge ≤79 Firefox 52 IE 不支持 No Opera 43 Safari 不支持 No WebView Android 56 Chrome Android 56 Firefox Android 52 Opera Android 43 Safari iOS 不支持 No Samsung Internet Android 6.0
offset Chrome 56 Edge 79 Firefox 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
onended Chrome 56 Edge 79 Firefox 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 56 Chrome Android 56 Firefox Android 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 6.0
start Chrome 56 Edge 79 Firefox 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 56 Chrome Android 56 Firefox Android 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 6.0
stop Chrome 56 Edge 79 Firefox 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 56 Chrome Android 56 Firefox Android 不支持 52 — 53
注意事项
52 — 53
注意事项
This property is still available, but via the inheritance of AudioScheduledSourceNode .
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 6.0

图例

完整支持
完整支持
不支持
不支持
见实现注意事项。

另请参阅