OscillatorNode
interface represents a periodic waveform, such as a sine wave. It is an
AudioScheduledSourceNode
audio-processing module that causes a specified frequency of a given wave to be created—in effect, a constant tone.
An
OscillatorNode
is created using the
BaseAudioContext.createOscillator()
method. It always has exactly one output and no inputs. Its basic property defaults (see
AudioNode
for definitions) are:
| 输入数 |
0
|
|---|---|
| 输出数 |
1
|
| 通道计数模式 |
max
|
| 通道计数 |
2
(不用于默认计数模式)
|
| 通道解释 |
speakers
|
OscillatorNode()
OscillatorNode
object, optionally providing an object specifying default values for the node's
properties
. If the default values are acceptable, you can simply call the
BaseAudioContext.createOscillator()
factory method.
继承的特性来自其父级,
AudioScheduledSourceNode
, and adds the following properties:
OscillatorNode.frequency
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).
OscillatorNode.detune
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.
OscillatorNode.type
custom
要使用
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"
.
OscillatorNode.onended
ended
event, which fires when the tone has stopped playing.
继承方法来自其父级
AudioScheduledSourceNode
, and adds the following:
OscillatorNode.setPeriodicWave()
PeriodicWave
which describes a periodic waveform to be used instead of one of the standard waveforms; calling this sets the
type
to
custom
. This replaces the now-obsolete
OscillatorNode.setWaveTable()
方法。
OscillatorNode.start()
Specifies the exact time to start playing the tone.
OscillatorNode.stop()
Specifies the time to stop playing the tone.
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.setValueAtTime(440, audioCtx.currentTime); // value in hertz oscillator.connect(audioCtx.destination); oscillator.start();
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'OscillatorNode' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
OscillatorNode
|
Chrome 14 | Edge ≤18 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS Yes | Samsung Internet Android 1.0 |
OscillatorNode()
构造函数
|
Chrome 55 | Edge ≤79 | Firefox 53 | IE 不支持 No | Opera 42 | Safari ? |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 53 | Opera Android 42 | Safari iOS ? |
Samsung Internet Android
6.0
注意事项
|
detune
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS Yes | Samsung Internet Android 1.0 |
frequency
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS Yes | Samsung Internet Android 1.0 |
onended
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
setPeriodicWave
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS Yes | Samsung Internet Android 1.0 |
start
|
Chrome 14 | Edge 12 |
Firefox
25
注意事项
|
IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 |
Firefox Android
26
注意事项
|
Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
stop
|
Chrome 14 | Edge 12 |
Firefox
25
注意事项
|
IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 |
Firefox Android
26
注意事项
|
Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
type
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS Yes | Samsung Internet Android 1.0 |
完整支持
不支持
兼容性未知
见实现注意事项。
OscillatorNode
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletNode
AudioWorkletProcessor
BaseAudioContext
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
DynamicsCompressorNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode