ConstantSourceNode.offset - Web APIs 编辑

The read-only offset property of the 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 named 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;

Syntax

let offsetParameter = ConstantAudioNode.offset;

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

Value

An 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.

Example

This example shows how to set up a ConstantSourceNode so its offset is used as the input to a pair of GainNodes; 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) {
  constantSource.offset.value = volumeSliderControl.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 changing the contents of its AudioParam.value property. The two gain nodes quickly adopt the new volume level.

Specifications

SpecificationStatusComment
Web Audio API
The definition of 'offset' in that specification.
Working Draft

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:133 次

字数:5051

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文