MDN’s new design is in Beta! A sneak peek:



OscillatorNode 接口表示一个周期的波形,比如一个正弦波. 它是一个 AudioScheduledSourceNode 音频处理模块, 这个模块会对一个指定频率将创建的给定波产生影响, 一个恒定的音调.

An OscillatorNode is created using the AudioContext.createOscillator() method. It always has exactly one output and no inputs. Its basic property defaults (see AudioNode for definitions) are:

Number of inputs 0
Number of outputs 1
Channel count mode max
Channel count 2 (not used in the default count mode)
Channel interpretation speakers


创建一个OscillatorNode对象的示例, 为nodeproperties提供可选的一个定义默认值的对象.  如果默认值可接受,你可以简单地调用AudioContext.createOscillator()工厂方法.


继承自父级, AudioScheduledSourceNode, and adds the following properties:

An a-rate AudioParam representing the frequency of oscillation in hertz (though the AudioParam returned is read-only, the value it represents is not). The default value is 440 Hz (a standard middle-A note).
An a-rate AudioParam representing detuning of oscillation in cents (though the AudioParam returned is read-only, the value it represents is not). The default value is 0.
A string which specifies the shape of waveform to play; this can be one of a number of standard values, or custom to use a PeriodicWave to describe a custom waveform. Different waves will produce different tones. Standard values are "sine", "square", "sawtooth", "triangle" and "custom". The default is "sine".


继承自父级, AudioScheduledSourceNode, 自有方法如下:

设置一个 PeriodicWave ,它描述了一个周期的波形常常替代标准波形之一; calling this sets the type to custom. This replaces the now-obsolete OscillatorNode.setWaveTable() method.


The following example shows basic usage of an AudioContext to create an oscillator node and to start playing a tone on it. For an applied example, check out our Violent Theremin demo (see app.js for relevant code).

// 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


Specification Status Comment
Web Audio API
Working Draft  

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 14 webkit (Yes) 25 未实现 15 webkit
22 (unprefixed)
6 webkit
constructor 55.0 ? ? ? 42 ?
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 (Yes) (Yes) 25 1.2 未实现 未实现 webkit 28 webkit
constructor 未实现 55.0 ? ? ? ? 42 ? 55.0

See also


 此页面的贡献者: huangxok
 最后编辑者: huangxok,