BaseAudioContext: createOscillator() Methode

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.

Die createOscillator()-Methode der BaseAudioContext-Schnittstelle erstellt einen OscillatorNode, eine Quelle, die eine periodische Wellenform darstellt. Im Grunde erzeugt sie einen konstanten Ton.

Hinweis: Der OscillatorNode()-Konstruktor ist die empfohlene Methode, um einen OscillatorNode zu erstellen; siehe Erstellen eines AudioNode.

Syntax

js
createOscillator()

Parameter

Keine.

Rückgabewert

Beispiele

Das folgende Beispiel zeigt die grundlegende Verwendung eines AudioContext zur Erstellung eines Oszillator-Knotens. Für angewandte Beispiele/Informationen, schauen Sie sich unser Violent Theremin Demo (siehe app.js für den relevanten Code) an; sehen Sie auch unsere OscillatorNode Seite für weitere Informationen.

js
// create web audio api context
const audioCtx = new AudioContext();

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

oscillator.type = "square";
oscillator.frequency.setValueAtTime(3000, audioCtx.currentTime); // value in hertz
oscillator.connect(audioCtx.destination);
oscillator.start();

Spezifikationen

Specification
Web Audio API
# dom-baseaudiocontext-createoscillator

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
createOscillator

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch