--- title: OscillatorNode.frequency slug: Web/API/OscillatorNode/frequency translation_of: Web/API/OscillatorNode/frequency ---

{{ APIRef("Web Audio API") }}

{{ domxref("OscillatorNode") }} 的 frequency 属性的接口a-rate {{domxref("AudioParam")}},表示振荡的频率,单位HZ(hertz)

语法

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

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

一个 a-rate {{domxref("AudioParam")}} 的值

示例

下列示例使用 {{ domxref("AudioContext") }} 创建了一个 oscillator node. 这是一个用于展示的示例,查看 Violent Theremin demo (see app.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 Status Comment
{{SpecName('Web Audio API', '#widl-OscillatorNode-frequency', 'frequency')}} {{Spec2('Web Audio API')}}  

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 14 {{property_prefix("webkit")}} {{CompatVersionUnknown}} 23 {{CompatNo}} 15 {{property_prefix("webkit")}}
22 (unprefixed)
6 {{property_prefix("webkit")}}
Feature Android Chrome Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} 28 {{property_prefix("webkit")}} {{CompatVersionUnknown}} 25 1.2 {{CompatNo}} {{CompatNo}} 6 {{property_prefix("webkit")}}

See also