Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

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 des BaseAudioContext Interfaces erstellt einen OscillatorNode, eine Quelle, die eine periodische Wellenform darstellt. Sie erzeugt im Wesentlichen einen konstanten Ton.

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

Syntax

js
createOscillator()

Parameter

Keine.

Rückgabewert

Ein OscillatorNode.

Beispiele

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

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

Siehe auch