OscillatorNode.frequency

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

OscillatorNodefrequency 属性的接口a-rate AudioParam,表示振荡的频率,单位 HZ(hertz)

语法

js
var oscillator = audioCtx.createOscillator();
oscillator.frequency.value = 440; // value in hertz

备注: 虽然返回的 AudioParam 是只读的,但是它表示的值不是。

一个 a-rate AudioParam 的值

示例

下列示例使用 AudioContext 创建了一个 oscillator node. 这是一个用于展示的示例,查看 Violent Theremin demo (see app.js 是相关代码).

js
// create web audio api context
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();

// create Oscillator node
var oscillator = audioCtx.createOscillator();

oscillator.type = "square";
oscillator.frequency.value = 440; // value in hertz
oscillator.start();

规范

Specification
Web Audio API
# dom-oscillatornode-frequency

浏览器兼容性

BCD tables only load in the browser

See also