The 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 a-rateAudioParam 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-rateAudioParam 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".
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).
js
// create web audio api contextconst audioCtx =new(window.AudioContext || window.webkitAudioContext)();// create Oscillator nodeconst oscillator = audioCtx.createOscillator();
oscillator.type ="square";
oscillator.frequency.setValueAtTime(440, audioCtx.currentTime);// value in hertz
oscillator.connect(audioCtx.destination);
oscillator.start();