OscillatorNode.type

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.

typeOscillatorNode インターフェイスのプロパティで、発振器が出力する波形の形状を指定します。利用できる一般的な波形がいくつかあり、カスタム波形を指定するオプションもあります。波形は、生成される音色に影響を与えます。

発振器の波形を指定する文字列です。利用できる値は以下のとおりです。

sine

正弦波です。これが既定値です。

square

矩形波で、デューティサイクルが 0.5 のものです。すなわち、それぞれの周期で半分が「高」の信号です。

sawtooth

のこぎり波です。

triangle

三角波です。

custom

カスタム波形です。手動で typecustom に設定することはありません。代わりに setPeriodicWave() メソッドを使用して、波形を表すデータを使用してください。そうすることで、自動的に typecustom に設定されます。

例外

InvalidStateError DOMException

custom が指定された場合に発生します。カスタム波形を設定するには setPeriodicWave() を呼び出すだけです。そうすることで、自動的に型が設定されます。

以下の例は、発振器ノードを作成するための AudioContext の基本的な使用方法を示しています。応用例については、 Violent Theremin demo を見てみてください。(関連するコードは app.js を参照)。

js
// create web audio api context
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();

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

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

仕様書

Specification
Web Audio API
# dom-oscillatornode-type

ブラウザーの互換性

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
type

Legend

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

Full support
Full support

関連情報