diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/oscillatornode | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/oscillatornode')
-rw-r--r-- | files/zh-cn/web/api/oscillatornode/detune/index.html | 120 | ||||
-rw-r--r-- | files/zh-cn/web/api/oscillatornode/frequency/index.html | 119 | ||||
-rw-r--r-- | files/zh-cn/web/api/oscillatornode/index.html | 190 | ||||
-rw-r--r-- | files/zh-cn/web/api/oscillatornode/oscillatornode/index.html | 107 | ||||
-rw-r--r-- | files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html | 140 | ||||
-rw-r--r-- | files/zh-cn/web/api/oscillatornode/stop/index.html | 121 |
6 files changed, 797 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/oscillatornode/detune/index.html b/files/zh-cn/web/api/oscillatornode/detune/index.html new file mode 100644 index 0000000000..436ea0a26d --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/detune/index.html @@ -0,0 +1,120 @@ +--- +title: OscillatorNode.detune +slug: Web/API/OscillatorNode/detune +translation_of: Web/API/OscillatorNode/detune +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p>{{ domxref("OscillatorNode") }} 的 <code>detune 属性的接口</code>是 <a href="/en-US/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}} ,代表振荡频率的失谐量(<a href="http://en.wikipedia.org/wiki/Cent_%28music%29">cents</a>)。</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="brush: js">var oscillator = audioCtx.createOscillator(); +oscillator.detune.value = 100; // value in cents</pre> + +<div class="note"> +<p><strong>Note:</strong> 虽然返回的 <code>AudioParam</code> 是只读的,但是它表示的值不是。</p> +</div> + +<h3 id="值"> 值</h3> + +<p>一个 <a href="/en-US/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}} 的值</p> + +<h2 id="示例">示例</h2> + +<p>下面的例子使用 {{ domxref("AudioContext") }} 创建了一个 oscillator node。 这是已经在运行的例子,查看 <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> 是相关源码)。</p> + +<pre class="brush: js;highlight[9]">// 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.detune.value = 100; // value in cents +oscillator.start();</pre> + +<h2 id="说明">说明</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', '#widl-OscillatorNode-detune', 'detune')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>14 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>23</td> + <td>{{CompatNo}}</td> + <td>15 {{property_prefix("webkit")}}<br> + 22 (unprefixed)</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>28 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>25</td> + <td>1.2</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</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> diff --git a/files/zh-cn/web/api/oscillatornode/frequency/index.html b/files/zh-cn/web/api/oscillatornode/frequency/index.html new file mode 100644 index 0000000000..156531a8e6 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/frequency/index.html @@ -0,0 +1,119 @@ +--- +title: OscillatorNode.frequency +slug: Web/API/OscillatorNode/frequency +translation_of: Web/API/OscillatorNode/frequency +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p>{{ domxref("OscillatorNode") }} 的 <code>frequency 属性的接口</code>是 <a href="/en-US/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}},表示振荡的频率,单位HZ(hertz)</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="brush: js">var oscillator = audioCtx.createOscillator(); +oscillator.frequency.value = 440; // value in hertz</pre> + +<div class="note"> +<p><strong>Note</strong>: 虽然返回的 <code>AudioParam</code> 是只读的,但是它表示的值不是。</p> +</div> + +<h3 id="值">值</h3> + +<p>一个 <a href="/en-US/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}} 的值</p> + +<h2 id="示例">示例</h2> + +<p>下列示例使用 {{ domxref("AudioContext") }} 创建了一个 oscillator node. 这是一个用于展示的示例,查看 <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> 是相关代码).</p> + +<pre class="brush: js;highlight[8]">// 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.start();</pre> + +<h2 id="说明">说明</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', '#widl-OscillatorNode-frequency', 'frequency')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>14 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>23</td> + <td>{{CompatNo}}</td> + <td>15 {{property_prefix("webkit")}}<br> + 22 (unprefixed)</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>28 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>25</td> + <td>1.2</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</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> diff --git a/files/zh-cn/web/api/oscillatornode/index.html b/files/zh-cn/web/api/oscillatornode/index.html new file mode 100644 index 0000000000..7b1bf096bc --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/index.html @@ -0,0 +1,190 @@ +--- +title: OscillatorNode +slug: Web/API/OscillatorNode +translation_of: Web/API/OscillatorNode +--- +<p>{{APIRef("Web Audio API")}}</p> + +<p><strong><code>OscillatorNode</code></strong> 接口表示一个振荡器,它产生一个周期的波形信号(如正弦波)。它是一个 {{domxref("AudioScheduledSourceNode")}} 音频处理模块, 这个模块会生成一个指定频率的波形信号(即一个固定的音调)</p> + +<p>一个 <code>OscillatorNode 对象是通过 </code>{{domxref("AudioContext.createOscillator()")}} 方法创建的。它总是有一个输出,但没有输入。它的基础属性(定义见 {{domxref("AudioNode")}} )默认如下:</p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">Number of inputs</th> + <td><code>0</code></td> + </tr> + <tr> + <th scope="row">Number of outputs</th> + <td><code>1</code></td> + </tr> + <tr> + <th scope="row">Channel count mode</th> + <td><code>max</code></td> + </tr> + <tr> + <th scope="row">Channel count</th> + <td><code>2</code> (not used in the default count mode)</td> + </tr> + <tr> + <th scope="row">Channel interpretation</th> + <td><code>speakers</code></td> + </tr> + </tbody> +</table> + +<h2 id="构造函数">构造函数</h2> + +<dl> + <dt>{{domxref("OscillatorNode.OscillatorNode", "OscillatorNode()")}}</dt> + <dd>创建一个OscillatorNode对象的示例, 为node{{anch("properties")}}提供可选的一个定义默认值的对象. 如果默认值可接受,你可以简单地调用{{domxref("AudioContext.createOscillator()")}}工厂方法.</dd> +</dl> + +<h2 id="属性">属性</h2> + +<p><em>继承自父类 </em><em>{{domxref("AudioScheduledSourceNode")}},并添加下列属性:</em></p> + +<dl> + <dt>{{domxref("OscillatorNode.frequency")}}</dt> + <dd>一个 <a href="/en-US/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}} 对象的属性代表了振动的频率(单位为赫兹hertz) (虽然返回的<code>AudioParam 是只读的,但是它所表示的值是可以修改的</code>)。 默认值是 440 Hz (基本的中A音高).</dd> +</dl> + +<dl> + <dt>{{domxref("OscillatorNode.detune")}}</dt> + <dd>一个 <a href="/en-US/docs/Web/API/AudioParam#a-rate">a-rate</a> {{domxref("AudioParam")}} 对象的属性代表振动的音高微调(单位是cent音分) (虽然返回的<code>AudioParam 是只读的,但是它所表示的值是可以修改的</code>).。默认值是0。</dd> +</dl> + +<dl> + <dt>{{domxref("OscillatorNode.type")}}</dt> + <dd>一个字符串,决定 <code>OscillatorNode 播放的声音的周期波形</code>; 它的值可以是基础值中的一个或者用户使用 {{domxref("PeriodicWave")}}。不同的波形可以产生不同的声调。 基础值有 <code>"sine"</code>, <code>"square"</code>, <code>"sawtooth"</code>, <code>"triangle"</code> and <code>"custom"</code>. 默认值是<code>"sine"。</code></dd> +</dl> + +<h2 id="方法">方法</h2> + +<p><em>继承自父级, </em><em>{{domxref("AudioScheduledSourceNode")}}</em>, 自有方法如下:</p> + +<dl> + <dt>{{domxref("OscillatorNode.setPeriodicWave()")}}</dt> + <dd>设置一个 {{domxref("PeriodicWave")}} ,它描述了一个周期的波形常常替代标准波形之一; 调用这个方法来设置用户自定义的波形。它取代了已经废弃了的 {{domxref("OscillatorNode.setWaveTable()")}} 方法。</dd> +</dl> + +<h2 id="示例">示例</h2> + +<p>下面示例展示了 {{ domxref("AudioContext") }} 的基本使用 来创建一个 oscillator 节点 并使用它来播放音乐。这是已经在运行的例子,可以看这里 <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> 是相关代码).</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="说明">说明</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="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>14 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>25</td> + <td>{{CompatNo}}</td> + <td>15 {{property_prefix("webkit")}}<br> + 22 (unprefixed)</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + <tr> + <td>constructor</td> + <td>{{CompatChrome(55.0)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOpera(42)}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>25</td> + <td>1.2</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>6 {{property_prefix("webkit")}}</td> + <td>28 {{property_prefix("webkit")}}</td> + </tr> + <tr> + <td>constructor</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(55.0)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOpera(42)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(55.0)}}</td> + </tr> + </tbody> +</table> +</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> diff --git a/files/zh-cn/web/api/oscillatornode/oscillatornode/index.html b/files/zh-cn/web/api/oscillatornode/oscillatornode/index.html new file mode 100644 index 0000000000..cea622d021 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/oscillatornode/index.html @@ -0,0 +1,107 @@ +--- +title: OscillatorNode() +slug: Web/API/OscillatorNode/OscillatorNode +translation_of: Web/API/OscillatorNode/OscillatorNode +--- +<p>{{APIRef("Web Audio API")}}{{SeeCompatTable}}</p> + +<p><strong><code>OscillatorNode()</code></strong> 构造器创建了一个新的 {{domxref("OscillatorNode")}} 对象,也是 {{domxref("AudioNode")}} 类型,表示一个周期的波形,例如正弦波,用来在不同的对象中定义其可选属性的值</p> + +<p>如果属性的默认值可接受,也可以选择使用 {{domxref("AudioContext.createOscillator()")}} 工厂方法构造 {{domxref("OscillatorNode")}} 对象。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var <em>oscillatorNode</em> = new OscillatorNode(<em>context</em>, <em>options</em>)</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code>context</code></dt> + <dd>指向 {{domxref("AudioContext")}} 的引用。</dd> + <dt><code>options</code> {{optional_inline}}</dt> + <dd>一个用来给 oscillator node 的属性指定值得对象,该对象中省略的属性都将采用默认值 + <dl> + <dt><code>type</code></dt> + <dd>oscillator node 产生的波形的形状。可用的值有 '<code>sine</code>', '<code>square</code>', '<code>sawtooth</code>', '<code>triangle</code>' 和 '<code>custom</code>',默认值是'sine'。</dd> + <dt><code>detune</code></dt> + <dd>音高微调值(cents)可以对给定的频率值进行偏移。 默认值是0.</dd> + <dt><code>frequency</code></dt> + <dd>周期性波形的频率 (in {{interwiki("wikipedia", "hertz")}})。 默认值是440.</dd> + <dt><code>periodicWave</code></dt> + <dd>任意的周期性波形,通过一个 {{domxref("PeriodicWave")}} 对象描述。</dd> + </dl> + </dd> +</dl> + +<h2 id="说明">说明</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>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(55)}}<sup>[1]</sup></td> + <td>{{CompatGeckoDesktop(25)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOpera(42)}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android Webview</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(55)}}<sup>[1]</sup></td> + <td>{{CompatChrome(55)}}<sup>[1]</sup></td> + <td>{{CompatGeckoMobile(25)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatOperaMobile(42)}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] Chrome 59 之前,不支持默认属性。 </p> diff --git a/files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html b/files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html new file mode 100644 index 0000000000..43f27ec698 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html @@ -0,0 +1,140 @@ +--- +title: OscillatorNode.setPeriodicWave() +slug: Web/API/OscillatorNode/setPeriodicWave +translation_of: Web/API/OscillatorNode/setPeriodicWave +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<p> {{ domxref("OscillatorNode") }} 接口的 <strong><code>setPeriodicWave() </code></strong><code>方法</code>用来指向 {{domxref("PeriodicWave")}},PeriodicWave 定义了一个周期性波形能够形成oscillator的输出, 当{{domxref("OscillatorNode.type", "type")}} 是 <code>custom 的时候</code>.</p> + +<div class="note"> +<p>该方法取代了废弃的 {{ domxref("OscillatorNode.setWaveTable()")}}.</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>OscillatorNode</em>.setPeriodicWave(<em>wave</em>);</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code>wave</code></dt> + <dd>一个 {{domxref("PeriodicWave")}} 对象, 表示特定的波形用来形成oscillator的输出。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>{{jsxref("undefined")}}</p> + +<h2 id="示例">示例</h2> + +<p>下面示例说明了 <code>createPeriodicWave() 方法的简单使用</code>, 从一个周期波形中重新生成了一个正弦波形。</p> + +<pre class="brush: js;highlight[13]">var real = new Float32Array(2); +var imag = new Float32Array(2); +var ac = new AudioContext(); +var osc = ac.createOscillator(); + +real[0] = 0; +imag[0] = 0; +real[1] = 1; +imag[1] = 0; + +var wave = ac.createPeriodicWave(real, imag); + +osc.setPeriodicWave(wave); + +osc.connect(ac.destination); + +osc.start(); +osc.stop(2);</pre> + +<p>这段代码可以运行因为通过定义一个正弦波形使得声音包含了基础的音调。<br> + </p> + +<p>这里,我们用两个值创建一个{{domxref("PeriodicWave")}}。第一个值是直流偏移,是oscillator开始的时候的值。这里 0 很合适,因为我们想要在 [-1.0; 1.0] 这个范围的中间值开始。</p> + +<p>第二个和后面的值是正弦和余弦内容。可以把它看做傅里叶变换的结果,使得可以从时间阈值得到频率阈值。这里通过 <code>createPeriodicWave() 方法,可以指定频率,并且浏览器执行逆傅里叶变换来得到一个时间阈值缓冲。</code>Here, we only set one component at full volume (1.0) on the fundamental tone, so we get a sine wave.</p> + +<h2 id="说明">说明</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', '#widl-OscillatorNode-setPeriodicWave-void-PeriodicWave-periodicWave', 'setPeriodicWave')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>14 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>23</td> + <td>{{CompatNo}}</td> + <td>15 {{property_prefix("webkit")}}<br> + 22 (unprefixed)</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>28 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>25</td> + <td>1.2</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</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> + <li><a href="/en-US/docs/Web/API/AudioContext/createPeriodicWave">AudioContext.createPeriodicWave</a></li> +</ul> diff --git a/files/zh-cn/web/api/oscillatornode/stop/index.html b/files/zh-cn/web/api/oscillatornode/stop/index.html new file mode 100644 index 0000000000..3b776727b6 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/stop/index.html @@ -0,0 +1,121 @@ +--- +title: OscillatorNode.stop() +slug: Web/API/OscillatorNode/stop +translation_of: Web/API/OscillatorNode/stop +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p>这个 <strong><code>stop</code></strong>方法 {{ domxref("OscillatorNode") }} 接口在指定时间内停止播放,它的参数是可选的,默认情况下是0.</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">oscillator.stop(<em>when</em>); // stop playing oscillator at <em>when</em></pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><em>when</em></dt> + <dd>An optional double representing the <a href="/en-US/docs/Web/API/AudioContext/currentTime">audio context time</a> when the oscillator should stop. If a value is not included, it defaults to <code>0</code>. If the time is equal to or before the current audio context time, the oscillator will stop playing immediately.</dd> +</dl> + +<h2 id="例如">例如</h2> + +<p>下面的示例显示一个基本用法{{ domxref("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> for relevant code).</p> + +<pre class="brush: js;highlight[11]">// create web audio api context +var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + +// create Oscillator node +var oscillator = audioCtx.createOscillator(); +oscillator.connect(audioCtx.destination); + +oscillator.start(); + +oscillator.stop(audioCtx.currentTime + 2); // stop 2 seconds after the current time +</pre> + +<h2 id="规定">规定</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', '#widl-OscillatorNode-stop-void-double-when', 'stop')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器的兼容性">浏览器的兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>14 {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>23 [1]</td> + <td>{{CompatNo}}</td> + <td>15 {{property_prefix("webkit")}}<br> + 22 (unprefixed)</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>28 {{property_prefix("webkit")}}</td> + <td>25 [1]</td> + <td>1.2</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>6 {{property_prefix("webkit")}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] The parameter wasn't optional until Firefox 30.</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> |