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/audiobuffer | |
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/audiobuffer')
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/audiobuffer/index.html | 59 | ||||
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/copyfromchannel/index.html | 137 | ||||
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/duration/index.html | 128 | ||||
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/getchanneldata/index.html | 102 | ||||
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/index.html | 111 | ||||
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/length/index.html | 129 | ||||
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/numberofchannels/index.html | 132 | ||||
-rw-r--r-- | files/zh-cn/web/api/audiobuffer/samplerate/index.html | 81 |
8 files changed, 879 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/audiobuffer/audiobuffer/index.html b/files/zh-cn/web/api/audiobuffer/audiobuffer/index.html new file mode 100644 index 0000000000..0b207a8d4c --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/audiobuffer/index.html @@ -0,0 +1,59 @@ +--- +title: AudioBuffer() +slug: Web/API/AudioBuffer/AudioBuffer +translation_of: Web/API/AudioBuffer/AudioBuffer +--- +<p>{{APIRef("Web Audio API")}}</p> + +<p><span class="seoSummary"><a href="/en-US/docs/Web/API/Web_Audio_API">Web Audio API</a> 的 <strong><code>AudioBuffer</code></strong> 构造函数将创建一个新的 {{domxref("AudioBuffer")}} 对象.</span></p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var audioBuffer = new AudioBuffer([options]); +var audioBuffer = new AudioBuffer(context[, options]);</pre> + +<h3 id="参数">参数</h3> + +<p><em>继承参数自 {{domxref("AudioNodeOptions")}} 字典</em>.</p> + +<dl> + <dt><em>context </em>{{obsolete_inline("")}}</dt> + <dd>一个 {{domxref("AudioContext")}} 对象. (这个参数已经被标准移除, 详细信息请参阅浏览器兼容性部分.)</dd> + <dt><em>options</em> {{optional_inline}}</dt> + <dd>Options are as follows: + <ul> + <li><code>length</code>: buffer中采样帧的长度.</li> + <li><code>numberOfChannels</code>: buffer的通道数. 默认值为1. </li> + <li><code>sampleRate</code>: buffer的采样率 (Hz). 默认值为构造此对象时使用的 <code>context</code> 的采样率.</li> + </ul> + </dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>一个新的 {{domxref("AudioBuffer")}} 对象实例.</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','#AudioBuffer','AudioBuffer')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.AudioBuffer.AudioBuffer")}}</p> +</div> diff --git a/files/zh-cn/web/api/audiobuffer/copyfromchannel/index.html b/files/zh-cn/web/api/audiobuffer/copyfromchannel/index.html new file mode 100644 index 0000000000..2cbcf3a57b --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/copyfromchannel/index.html @@ -0,0 +1,137 @@ +--- +title: AudioBuffer.copyFromChannel() +slug: Web/API/AudioBuffer/copyFromChannel +translation_of: Web/API/AudioBuffer/copyFromChannel +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p><span class="seoSummary">{{ domxref("AudioBuffer") }}接口的copyFromChannel方法将样本从AudioBuffer的指定通道复制到目标数组中</span></p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>myArrayBuffer</em>.copyFromChannel(<em>destination</em>,<em>channelNumber</em>,<em>startInChannel</em>);</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><em>destination</em></dt> + <dd>将通道数据复制到的{{domxref("Float32Array")}}</dd> + <dt><em>channelNumber</em></dt> + <dd>当前AudioBuffer的通道号,用于复制通道数据。键入channelNumber大于或等于{{domxref("AudioBuffer.numberOfChannels")}},将会抛出<code>INDEX_SIZE_ERR</code> 的错误</dd> + <dt><em>startInChannel</em> {{optional_inline}}</dt> + <dd>用于复制数据的可选偏移量。假如<em>startInChannel比</em>{{domxref("AudioBuffer.length")}}大,将会抛出<code>INDEX_SIZE_ERR</code> 的错误</dd> +</dl> + +<h2 id="例子">例子</h2> + +<pre class="brush: js">var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); +var anotherArray = new Float32Array; +myArrayBuffer.copyFromChannel(anotherArray,1,0); +</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-AudioBuffer-copyFromChannel-void-Float32Array-destination-long-channelNumber-unsigned-long-startInChannel', 'copyFromChannel')}}</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>{{CompatChrome(14.0)}} {{property_prefix("webkit")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop(27)}}</td> + <td>{{CompatNo}}</td> + <td>15 {{property_prefix("webkit")}}<br> + 22 (unprefixed)</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td>Unprefixed</td> + <td>{{CompatChrome(43.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</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>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile(27)}}</td> + <td>1.2</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(28.0)}} {{property_prefix("webkit")}}</td> + </tr> + <tr> + <td>Unprefixed</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(43.0)}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> +</ul> diff --git a/files/zh-cn/web/api/audiobuffer/duration/index.html b/files/zh-cn/web/api/audiobuffer/duration/index.html new file mode 100644 index 0000000000..42b804569e --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/duration/index.html @@ -0,0 +1,128 @@ +--- +title: AudioBuffer.duration +slug: Web/API/AudioBuffer/duration +translation_of: Web/API/AudioBuffer/duration +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p>{{domxref("AudioBuffer")}}接口的duration属性返回一个双精度数,表示缓冲区中存储的PCM数据的持续时间(以秒为单位)</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="brush: js;highlight[22]">var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); +myArrayBuffer.duration;</pre> + +<h3 id="值">值</h3> + +<p>双精度值</p> + +<h2 id="例子">例子</h2> + +<pre class="brush: js;highlight[22]">// Stereo +var channels = 2; + +// Create an empty two second stereo buffer at the +// sample rate of the AudioContext +var frameCount = audioCtx.sampleRate * 2.0; +var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); + +button.onclick = function() { + // Fill the buffer with white noise; + // just random values between -1.0 and 1.0 + for (var channel = 0; channel < channels; channel++) { + // This gives us the actual ArrayBuffer that contains the data + var nowBuffering = myArrayBuffer.getChannelData(channel); + for (var i = 0; i < frameCount; i++) { + // Math.random() is in [0; 1.0] + // audio needs to be in [-1.0; 1.0] + nowBuffering[i] = Math.random() * 2 - 1; + } + } + + console.log(myArrayBuffer.duration); +} +</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-AudioBuffer-duration', 'duration')}}</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/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> +</ul> diff --git a/files/zh-cn/web/api/audiobuffer/getchanneldata/index.html b/files/zh-cn/web/api/audiobuffer/getchanneldata/index.html new file mode 100644 index 0000000000..2c0d75cb1b --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/getchanneldata/index.html @@ -0,0 +1,102 @@ +--- +title: AudioBuffer.getChannelData() +slug: Web/API/AudioBuffer/getChannelData +translation_of: Web/API/AudioBuffer/getChannelData +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<p> {{ domxref("AudioBuffer") }} 接口的getChannelData()方法返回一{{domxref("Float32Array")}} ,其中包含与通道关联的PCM数据,通道参数定义(0表示第一个通道)。</p> + +<h2 id="语法">语法</h2> + +<pre class="brush: js;highlight[22]">var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); +var nowBuffering = myArrayBuffer.getChannelData(channel);</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>channel</dt> + <dd>channel属性是要获取特定通道数据的索引。0代表第一个通道。 如果索引值大于或等于{{domxref("AudioBuffer.numberOfChannels")}}, 会抛出一个索引大小异常(<code>INDEX_SIZE_ERR</code> )的错误。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p> {{domxref("Float32Array")}}.</p> + +<dl> +</dl> + +<h2 id="例子">例子</h2> + +<p>在下例中,我们创建一个2秒钟的缓冲区,用白噪声填充它,然后通过{{domxref("AudioBufferSourceNode") }}来播放它. 评论应该会清楚的解释发生的事情。 你也可以<a href="https://mdn.github.io/webaudio-examples/audio-buffer/">实时运行代码</a>,或者<a href="https://github.com/mdn/webaudio-examples">查看源代码</a>。</p> + +<pre class="brush: js;highlight[21]">var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); +var button = document.querySelector('button'); +var pre = document.querySelector('pre'); +var myScript = document.querySelector('script'); + +pre.innerHTML = myScript.innerHTML; + +// Stereo +var channels = 2; +// Create an empty two second stereo buffer at the +// sample rate of the AudioContext +var frameCount = audioCtx.sampleRate * 2.0; + +var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); + +button.onclick = function() { + // Fill the buffer with white noise; + //just random values between -1.0 and 1.0 + for (var channel = 0; channel < channels; channel++) { + // This gives us the actual ArrayBuffer that contains the data + var nowBuffering = myArrayBuffer.getChannelData(channel); + for (var i = 0; i < frameCount; i++) { + // Math.random() is in [0; 1.0] + // audio needs to be in [-1.0; 1.0] + nowBuffering[i] = Math.random() * 2 - 1; + } + } + + // Get an AudioBufferSourceNode. + // This is the AudioNode to use when we want to play an AudioBuffer + var source = audioCtx.createBufferSource(); + // set the buffer in the AudioBufferSourceNode + source.buffer = myArrayBuffer; + // connect the AudioBufferSourceNode to the + // destination so we can hear the sound + source.connect(audioCtx.destination); + // start the source playing + source.start(); +}</pre> + +<h2 id="Specification">Specification</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-audiobuffer-getchanneldata', 'getChannelData')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.AudioBuffer.getChannelData")}}</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> +</ul> diff --git a/files/zh-cn/web/api/audiobuffer/index.html b/files/zh-cn/web/api/audiobuffer/index.html new file mode 100644 index 0000000000..2922de46d6 --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/index.html @@ -0,0 +1,111 @@ +--- +title: AudioBuffer +slug: Web/API/AudioBuffer +translation_of: Web/API/AudioBuffer +--- +<p>{{APIRef("Web Audio API")}}</p> + +<div> +<p>AudioBuffer接口表示存在内存里的一段短小的音频资源,利用{{ domxref("AudioContext.decodeAudioData()") }}方法从一个音频文件构建,或者利用 {{ domxref("AudioContext.createBuffer()") }}从原始数据构建。把音频放入AudioBuffer后,可以传入到一个 {{ domxref("AudioBufferSourceNode") }}进行播放。</p> +</div> + +<p>这些类型对象被设计来控制小音频片段,往往短于45秒。对于更长的声音,通过 {{domxref("MediaElementAudioSourceNode")}}来实现更为合适。缓存区(buffer)包含以下数据:不间断的IEEE75432位线性PCM,从-1到1的范围额定,就是说,32位的浮点缓存区的每个样本在-1.0到1.0之间。如果{{domxref("AudioBuffer")}}有不同的频道,他们通常被保存在独立的缓存区。</p> + +<h2 id="属性">属性</h2> + +<dl> + <dt>{{domxref("AudioBuffer.sampleRate")}} {{readonlyInline}}</dt> + <dd>存储在缓存区的PCM数据的采样率:浮点数,单位为 sample/s。</dd> + <dt>{{domxref("AudioBuffer.length")}} {{readonlyInline}}</dt> + <dd>返回存储在缓存区的PCM数据的采样帧率:整形。</dd> + <dt>{{domxref("AudioBuffer.duration")}} {{readonlyInline}}</dt> + <dd>返回存储在缓存区的PCM数据的时长:双精度型(单位为秒),。</dd> + <dt>{{domxref("AudioBuffer.numberOfChannels")}} {{readonlyInline}}</dt> + <dd>返回存储在缓存区的PCM数据的通道数:整形。</dd> +</dl> + +<h2 id="方法">方法</h2> + +<dl> + <dt>{{domxref("AudioBuffer.getChannelData()")}}</dt> + <dd>返回一个 {{jsxref("Float32Array")}},包含了带有频道的PCM数据,由频道参数定义(有0代表第一个频道)</dd> + <dt>{{domxref("AudioBuffer.copyFromChannel()")}}</dt> + <dd>从AudioBuffer的指定频道复制到数组终端。</dd> + <dt>{{domxref("AudioBuffer.copyToChannel()")}}</dt> + <dd>复制样品到原数组的AudioBuffer的指定频道</dd> +</dl> + +<h2 id="例子">例子</h2> + +<p>以下的例子展示了如何构建一个AudioBuffer以及随机用白噪音填充。你可以在 <a href="https://github.com/mdn/webaudio-examples/tree/master/audio-buffer">audio-buffer demo</a>库发现完整的源代码;一个<a href="https://mdn.github.io/webaudio-examples/audio-buffer/">running live</a> 的版本也可获得。</p> + +<pre class="brush: js;highlight:[7,14,27] notranslate">// Stereo +var channels = 2; + +// Create an empty two second stereo buffer at the +// sample rate of the AudioContext +var frameCount = audioCtx.sampleRate * 2.0; +var myArrayBuffer = audioCtx.createBuffer(channels, frameCount, audioCtx.sampleRate); + +button.onclick = function() { + // Fill the buffer with white noise; + // just random values between -1.0 and 1.0 + for (var channel = 0; channel < channels; channel++) { + // This gives us the actual array that contains the data + var nowBuffering = myArrayBuffer.getChannelData(channel); + for (var i = 0; i < frameCount; i++) { + // Math.random() is in [0; 1.0] + // audio needs to be in [-1.0; 1.0] + nowBuffering[i] = Math.random() * 2 - 1; + } + } + + // Get an AudioBufferSourceNode. + // This is the AudioNode to use when we want to play an AudioBuffer + var source = audioCtx.createBufferSource(); + + // set the buffer in the AudioBufferSourceNode + source.buffer = myArrayBuffer; + + // connect the AudioBufferSourceNode to the + // destination so we can hear the sound + source.connect(audioCtx.destination); + + // start the source playing + source.start(); + +} +</pre> + +<h2 id="规格参数">规格参数</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规格参数</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + <tr> + <td>{{SpecName('Web Audio API', '#the-audiobuffer-interface', 'AudioBuffer')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div class="hidden"> +<p>此页面上的兼容性表是由结构化数据生成的。如果您想贡献数据,请查看https://github.com/mdn/browser-compat-data并向我们提交pull request。</p> +</div> + +<p>{{Compat("api.AudioBuffer")}}</p> + +<div></div> + +<h2 id="可查看">可查看</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">应用Web Audio API </a></li> +</ul> diff --git a/files/zh-cn/web/api/audiobuffer/length/index.html b/files/zh-cn/web/api/audiobuffer/length/index.html new file mode 100644 index 0000000000..054584f83b --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/length/index.html @@ -0,0 +1,129 @@ +--- +title: AudioBuffer.length +slug: Web/API/AudioBuffer/length +translation_of: Web/API/AudioBuffer/length +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p>The <code>length</code> property of the {{ domxref("AudioBuffer") }} interface returns an integer representing the length, in sample-frames, of the PCM data stored in the buffer.</p> + +<p>{{ domxref("AudioBuffer") }} 的length属性接口返回整数,该整数代表采样帧中,存贮在缓冲区中的PCM数据的长度</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="brush: js;highlight[22]">var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); +myArrayBuffer.length;</pre> + +<h3 id="值">值</h3> + +<p>浮点数</p> + +<h2 id="例子">例子</h2> + +<pre class="brush: js;highlight[22]">// Stereo +var channels = 2; + +// Create an empty two second stereo buffer at the +// sample rate of the AudioContext +var frameCount = audioCtx.sampleRate * 2.0; +var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); + +button.onclick = function() { + // Fill the buffer with white noise; + // just random values between -1.0 and 1.0 + for (var channel = 0; channel < channels; channel++) { + // This gives us the actual ArrayBuffer that contains the data + var nowBuffering = myArrayBuffer.getChannelData(channel); + for (var i = 0; i < frameCount; i++) { + // Math.random() is in [0; 1.0] + // audio needs to be in [-1.0; 1.0] + nowBuffering[i] = Math.random() * 2 - 1; + } + } + + console.log(myArrayBuffer.length); +}</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-AudioBuffer-length', 'length')}}</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/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> +</ul> diff --git a/files/zh-cn/web/api/audiobuffer/numberofchannels/index.html b/files/zh-cn/web/api/audiobuffer/numberofchannels/index.html new file mode 100644 index 0000000000..5ea379d53a --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/numberofchannels/index.html @@ -0,0 +1,132 @@ +--- +title: AudioBuffer.numberOfChannels +slug: Web/API/AudioBuffer/numberOfChannels +tags: + - API + - AudioBuffer + - Web Audio API + - 属性 +translation_of: Web/API/AudioBuffer/numberOfChannels +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p>{{ domxref("AudioBuffer") }}接口的<code>numberOfChannels</code>属性返回一个整数,该整数表示由缓冲区中存储的PCM数据描述的离散音频通道的数量</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="brush: js;highlight[22]">var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); +myArrayBuffer.numberOfChannels;</pre> + +<h3 id="返回值">返回值</h3> + +<p>一个整数。</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js;highlight[22]">// Stereo +var channels = 2; + +// Create an empty two second stereo buffer at the +// sample rate of the AudioContext +var frameCount = audioCtx.sampleRate * 2.0; +var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); + +button.onclick = function() { + // Fill the buffer with white noise; + // just random values between -1.0 and 1.0 + for (var channel = 0; channel < channels; channel++) { + // This gives us the actual ArrayBuffer that contains the data + var nowBuffering = myArrayBuffer.getChannelData(channel); + for (var i = 0; i < frameCount; i++) { + // Math.random() is in [0; 1.0] + // audio needs to be in [-1.0; 1.0] + nowBuffering[i] = Math.random() * 2 - 1; + } + } + + console.log(myArrayBuffer.numberOfChannels); +}</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-AudioBuffer-numberOfChannels', 'numberOfChannels')}}</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="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> +</ul> diff --git a/files/zh-cn/web/api/audiobuffer/samplerate/index.html b/files/zh-cn/web/api/audiobuffer/samplerate/index.html new file mode 100644 index 0000000000..1de2c66fb5 --- /dev/null +++ b/files/zh-cn/web/api/audiobuffer/samplerate/index.html @@ -0,0 +1,81 @@ +--- +title: AudioBuffer.sampleRate +slug: Web/API/AudioBuffer/sampleRate +tags: + - API + - AudioBuffer + - Web Audio API + - sampleRate +translation_of: Web/API/AudioBuffer/sampleRate +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<div> +<p>{{ domxref("AudioBuffer") }} 接口的 <code style="">sampleRate</code><span style='background-color: transparent; color: #333333; display: inline !important; float: none; font-family: "Open Sans",arial,x-locale-body,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;'> </span>属性返回一个以浮点数表示的采样率。该采样率是存储在缓冲区的PCM数据每秒钟的采样。</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="brush: js;highlight[22]">var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); +myArrayBuffer.sampleRate;</pre> + +<h3 id="返回值">返回值</h3> + +<p>一个浮点数,表示缓冲区数据的当前采样率。</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js;highlight[22]">// Stereo +var channels = 2; + +// Create an empty two second stereo buffer at the +// sample rate of the AudioContext +var frameCount = audioCtx.sampleRate * 2.0; +var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate); + +button.onclick = function() { + // Fill the buffer with white noise; + // just random values between -1.0 and 1.0 + for (var channel = 0; channel < channels; channel++) { + // This gives us the actual ArrayBuffer that contains the data + var nowBuffering = myArrayBuffer.getChannelData(channel); + for (var i = 0; i < frameCount; i++) { + // Math.random() is in [0; 1.0] + // audio needs to be in [-1.0; 1.0] + nowBuffering[i] = Math.random() * 2 - 1; + } + } + + console.log(myArrayBuffer.sampleRate); +}</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-AudioBuffer-sampleRate', 'sampleRate')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.AudioBuffer.sampleRate")}}</p> +</div> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> +</ul> |