aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/baseaudiocontext/createoscillator/index.html
blob: 3b992092cca3dffa84ff65b669bc00b17f0e370c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
title: BaseAudioContext.createOscillator()
slug: Web/API/BaseAudioContext/createOscillator
translation_of: Web/API/BaseAudioContext/createOscillator
---
<p>{{APIRef("Web Audio API")}}</p>

<p>{{domxref("BaseAudioContext")}}接口的createOscillator()方法创建一个{{domxref("OscillatorNode")}},它是一个表示周期性波形的源。 它基本上产生一个不变的音调。</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">var <em>oscillatorNode</em> = <em>audioCtx</em>.createOscillator();</pre>

<h3 id="Description" name="Description">Returns</h3>

<p>An {{domxref("OscillatorNode")}}.</p>

<h2 id="Examples" name="Examples">Example</h2>

<p>以下示例显示了用于创建振荡器节点的AudioContext的基本用法。 有关应用示例/信息,请查看我们的<a href="http://mdn.github.io/violent-theremin/">Violent Theremin demo</a>(有关相关代码,请参阅<a href="https://github.com/mdn/violent-theremin/blob/gh-pages/scripts/app.js">see app.js</a>); 另请参阅我们的OscillatorNode页面以获取更多信息。</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.setValueAtTime(3000, audioCtx.currentTime); // 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', '#dom-baseaudiocontext-createoscillator', 'createOscillator')}}</td>
   <td>{{Spec2('Web Audio API')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>
<div>


<p>{{Compat("api.BaseAudioContext.createOscillator")}}</p>
</div>
</div>

<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>