--- title: OscillatorNode slug: Web/API/OscillatorNode translation_of: Web/API/OscillatorNode --- <p>{{APIRef("Web Audio API")}}</p> <p><strong>OscillatorNode </strong>インタフェースは、正弦波などの周期的な波形を表します。これは、指定された波形で、特定の周波数の一定のトーンを発生させる、オーディオ処理モジュール {{domxref("AudioScheduledSourceNode")}} です。</p> <p>この OscillatorNode は {{domxref("AudioContext.createOscillator()")}} で生成されます。常に1つの出力だけをもち、入力はありません。基本的なプロパティのデフォルト値 (定義 については {{domxref("AudioNode")}} を参照)は、次のとおりです。</p> <table class="properties"> <tbody> <tr> <th scope="row">入力数</th> <td><code>0</code></td> </tr> <tr> <th scope="row">出力数</th> <td><code>1</code></td> </tr> <tr> <th scope="row">チャンネル カウントモード</th> <td><code>max</code></td> </tr> <tr> <th scope="row">チャンネル カウント</th> <td><code>2</code> (デフォルトのカウントモードでは使用されません。)</td> </tr> <tr> <th scope="row">チャンネル 解釈</th> <td><code>speakers</code></td> </tr> </tbody> </table> <h2 id="コンストラクタ">コンストラクタ</h2> <dl> <dt>{{domxref("OscillatorNode.OscillatorNode", "OscillatorNode()")}}</dt> <dd>ノードの {{anch("properties")}} の初期値を任意で設定し、新しい OscillatorNode のインスタンスを作成します。<br> 任意なプロパティ変更が不要で、初期値そのままで良いならば、単にファクトリメソッド、{{domxref("AudioContext.createOscillator()")}} を呼び出すことができます。</dd> </dl> <h2 id="プロパティ">プロパティ</h2> <p>親インターフェース、<em>{{domxref("AudioScheduledSourceNode")}}</em> のプロパティ継承に加え、以下のプロパティがあります。</p> <dl> <dt>{{domxref("OscillatorNode.frequency")}}</dt> <dd><a href="/ja/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}} であり、振動数・周波数をヘルツ (hertz、記号:Hz)で表わしたものです。(AudioParam は読み取り専用ですが、この値は設定できます。)初期値は 440 HZ (標準 A(ラ) 音) です。</dd> </dl> <dl> <dt>{{domxref("OscillatorNode.detune")}}</dt> <dd><a href="/ja/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}} であり、振動の離調をセントで表わしたものです。(AudioParam は読み取り専用ですが、この値は設定できます。)初期値は 0 です。</dd> </dl> <dl> <dt>{{domxref("OscillatorNode.type")}}</dt> <dd>再生する波形の種類を指定する文字列です。いくつかの標準値の中から1つ、または、{{domxref("PeriodicWave")}} を使用した、カスタム波形を設定することができます。設定する波の種類により、それぞれに合わせたトーンが生成されます。初期値は sine (サイン波) です。</dd> </dl> <h2 id="メソッド">メソッド</h2> <p>親である <em>{{domxref("AudioScheduledSourceNode")}}</em> のメソッド継承に加え、以下のメソッドがあります。</p> <dl> <dt>{{domxref("OscillatorNode.setPeriodicWave()")}}</dt> <dd>標準的な波形の代わりに、{{domxref("PeriodicWave")}} で設定した周期的な波形が、カスタムな波形として設定されます。これは、廃止された {{domxref("OscillatorNode.setWaveTable()")}} メソッドの代わりです。</dd> </dl> <h2 id="Examples">Examples</h2> <p>次の例は、AudioContextを使用し、オシレーターノードでトーンを再生する、基本的な例です。応用例については、<a href="http://mdn.github.io/violent-theremin/">Violent Theremin のデモ</a>をチェックしてみてください。 (コードは <a href="https://github.com/mdn/violent-theremin/blob/gh-pages/scripts/app.js">app.js</a> を参照してください。)</p> <pre class="brush: js">// create web audio api context var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); // create Oscillator node var oscillator = audioCtx.createOscillator(); oscillator.type = 'square'; oscillator.frequency.value = 440; // value in hertz oscillator.connect(audioCtx.destination); oscillator.start();</pre> <h2 id="Specifications">Specifications</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> <tr> <td>{{SpecName('Web Audio API', '#the-oscillatornode-interface', 'OscillatorNode')}}</td> <td>{{Spec2('Web Audio API')}}</td> <td> </td> </tr> </tbody> </table> <h2 id="Browser_compatibility">Browser compatibility</h2> <p>{{Compat("api.OscillatorNode")}}</p> <h2 id="See_also">See also</h2> <ul> <li><a href="/en-US/docs/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> </ul>