只读 offset 特性为 ConstantSourceNode interface returns a AudioParam object indicating the numeric a-rate value which is always returned by the source when asked for the next sample.

While the AudioParam 命名 offset is read-only, the value property within is not. So you can change the value of offset by setting the value of ConstantSourceNode.offset.value :

myConstantSourceNode.offset.value = newValue;
					

句法

let offsetParameter = ConstantAudioNode.offset;
let offset = ConstantSourceNode.offset.value;
ConstantSourceNode.offset.value = newValue;
					

AudioParam object indicating the a-rate value returned for every sample by this node. The default value is 1.0.

To access the offset parameter's current value, access the parameter's value property, as shown in the syntax box above.

范例

This example shows how to set up a ConstantSourceNode so its offset is used as the input to a pair of GainNode s; this snippet is derived from the complete example you can find in Controlling multiple parameters with ConstantSourcenode .

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

First, the gain nodes are created and configured, and a slider control's value is set to match the gain on the two nodes. Then we create a new ConstantSourceNode and make it the source for the two gain nodes' GainNode.gain values. Each of those values is also an AudioParam .

Let's say we have an event handler (for click events, in this case) which needs to respond by altering the value of the two gain nodes. With the linkage above in place, that can be done using this simple event handler:

function handleClickEvent(event) {
  volumeSliderControl.value = constantSource.offset.value;
}
					

All this function has to do is fetch the current value of the slider control we're using to control the paired nodes' gains, then store that value into the ConstantSourceNode 's offset parameter. That's done by simply changing the contents of its AudioParam.value property. The two gain nodes quickly adopt the new volume level.

规范

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

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: