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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
---
title: AudioNode
slug: Web/API/AudioNode
translation_of: Web/API/AudioNode
---
<div>{{ APIRef("Web Audio API") }} {{SeeCompatTable}}</div>
<p><img alt="AudioNodes participating in an AudioContext create a audio routing graph." src="https://mdn.mozillademos.org/files/5081/WebAudioBasics.png" style="float: left; height: 260px; margin: 10px; width: 355px;"><strong><code>AudioNode</code></strong><strong> </strong>接口是一个处理音频的通用模块, 比如一个音频源 (e.g. 一个 HTML {{HTMLElement("audio")}} or {{HTMLElement("video")}} 元素), 一个音频地址或者一个中间处理模块 (e.g. 一个过滤器如 {{domxref("BiquadFilterNode")}}, 或一个音量控制器如 {{domxref("GainNode")}}).</p>
<p><code>一个AudioNode</code> 既有输入也有输出。输入与输出都有一定数量的通道。<em>只有一个输出而没有输入的</em> <code>AudioNode</code> 叫做音频源。</p>
<p>处理多个 <code>AudioNode</code> 时,一般来说, 一个模块读取它的输入,做一些处理。后输出新生成的结果。</p>
<p>不同的模块可以连接在一起构建一个处理图。 这样一个处理图包含 {{domxref("AudioContext")}}。 每个 <code>AudioNode</code> 只有一个这样的上下文。</p>
<p>一个 <code>AudioNode</code> 可以作为事件的目标,所以它实现了 {{domxref("EventTarget")}} 接口。</p>
<h2 id="属性">属性</h2>
<dl>
<dt>{{domxref("AudioNode.context")}} {{readonlyInline}}</dt>
<dd>链接到关联的 {{domxref("AudioContext")}},处理图中模块的上下文对象。</dd>
</dl>
<dl>
<dt>{{domxref("AudioNode.numberOfInputs")}} {{readonlyInline}}</dt>
<dd>返回这个node需要的输入数量. Source nodes are defined as nodes having a <code>numberOfInputs</code> attributes with a value of <code>0</code>.</dd>
</dl>
<dl>
<dt>{{domxref("AudioNode.numberOfOutputs")}} {{readonlyInline}}</dt>
<dd>返回这个node的输出数量. Destination nodes, like <code>AudioDestinationNode</code>, have a value of <code>0</code> for this attribute.</dd>
</dl>
<dl>
<dt>{{domxref("AudioNode.channelCount")}}</dt>
<dd>Represents an integer used in determining how many channels outputs must contains. Its usage and precise definition depends of the value of <code>AudioNode.channelCountMode</code>: it is ignored if the value is <code>"max"</code>, used as a maximum value for <code>"clamped-max"</code>, or used as the effective value for <code>"explicit"</code>.</dd>
</dl>
<dl>
<dt>{{domxref("AudioNode.channelCountMode")}}</dt>
<dd>Represents an enumerated value describing the way channels must be matched between the inputs and the outputs. Possible values are:
<table class="standard-table">
<thead>
<tr>
<th scope="col">Value</th>
<th scope="col">Description</th>
<th scope="col">Used as default for the following <code>AudioNode</code> children</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>"max"</code></td>
<td>The number of channels is the maximum of the number of channels all connections. That implies that <code>channelCount</code> is ignored and only up-mixing happens</td>
<td>{{domxref("GainNode")}}, {{domxref("DelayNode")}}, {{domxref("ScriptProcessorNode")}}, {{domxref("ChannelSplitterNode")}}, {{domxref("ChannelMergerNode")}}, {{domxref("BiquadFilterNode")}}, {{domxref("WaveShaperNode")}}</td>
</tr>
<tr>
<td><code>"clamped-max"</code></td>
<td>The number of channels is the maximum of the number of channels of all connections, <em>clamped</em> to the value of <code>channelCount</code>.</td>
<td>{{domxref("PannerNode")}}, {{domxref("ConvolverNode")}}</td>
</tr>
<tr>
<td><code>"explicit"</code></td>
<td>The number of channels is defined by the value of <code>channelCount</code>.</td>
<td>{{domxref("AudioDestinationNode")}}, {{domxref("AnalyserNode")}}, {{domxref("DynamicsCompressorNode")}}</td>
</tr>
</tbody>
</table>
</dd>
<dt>{{domxref("AudioNode.channelInterpretation")}}</dt>
<dd>Represents an enumerated value describing the meaning of the channels. This interpretation will define how the up-mixing and the down-mixing will happen.<br>
The possible values are <code>"speakers"</code> or <code>"discrete"</code>. In the case of <code>"speakers"</code>, the ordering of the channels have the following meaning, and the channels are often represented by a standard abbreviation:
<table class="standard-table">
<tbody>
<tr>
<td><em>Mono</em></td>
<td><code>0: M: mono</code></td>
</tr>
<tr>
<td><em>Stereo</em></td>
<td><code>0: L: left<br>
1: R: right</code></td>
</tr>
<tr>
<td><em>Quad</em></td>
<td><code>0: L: left<br>
1: R: right<br>
2: SL: surround left<br>
3: SR: surround right</code></td>
</tr>
<tr>
<td><em>5.1</em></td>
<td><code>0: L: left<br>
1: R: right<br>
2: C: center<br>
3: LFE: subwoofer<br>
4: SL: surround left<br>
5: SR: surround right</code></td>
</tr>
</tbody>
</table>
When the amount of channels doesn't match between an input and an output, up- or down-mixing happens according the following rules:
<table class="standard-table">
<thead>
<tr>
<th scope="row">Interpretation</th>
<th scope="col">Input channels</th>
<th scope="col">Output channels</th>
<th scope="col">Mixing rules</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="1" rowspan="13" scope="row"><code>speakers</code></th>
<td><code>1</code> <em>(Mono)</em></td>
<td><code>2</code> <em>(Stereo)</em></td>
<td><em>Up-mix from mono to stereo</em>.<br>
The <code>M</code> input channel is used for both output channels (<code>L</code> and <code>R</code>).<br>
<code>output.L = input.M<br>
output.R = input.M</code></td>
</tr>
<tr>
<td><code>1</code> <em>(Mono)</em></td>
<td><code>4</code> <em>(Quad)</em></td>
<td><em>Up-mix from mono to quad.</em><br>
The <code>M</code> input channel is used for non-surround output channels (<code>L</code> and <code>R</code>). Surround output channels (<code>SL</code> and <code>SR</code>) are silent.<br>
<code>output.L = input.M<br>
output.R = input.M<br>
output.SL = 0<br>
output.SR = 0</code></td>
</tr>
<tr>
<td><code>1</code> <em>(Mono)</em></td>
<td><code>6</code> <em>(5.1)</em></td>
<td><em>Up-mix from mono to 5.1.</em><br>
The <code>M</code> input channel is used for the center output channel (<code>C</code>). All the others (<code>L</code>, <code>R</code>, <code>LFE</code>, <code>SL</code>, and <code>SR</code>) are silent.<br>
<code>output.L = 0<br>
output.R = 0</code><br>
<code>output.C = input.M<br>
output.LFE = 0<br>
output.SL = 0<br>
output.SR = 0</code></td>
</tr>
<tr>
<td><code>2</code> <em>(Stereo)</em></td>
<td><code>1</code> <em>(Mono)</em></td>
<td><em>Down-mix from stereo to mono</em>.<br>
Both input channels (<code>L</code> and <code>R</code>) are equally combined to produce the unique output channel (<code>M</code>).<br>
<code>output.M = 0.5 * (input.L + input.R)</code></td>
</tr>
<tr>
<td><code>2</code> <em>(Stereo)</em></td>
<td><code>4</code> <em>(Quad)</em></td>
<td><em>Up-mix from stereo to quad.</em><br>
The <code>L</code> and <code>R </code>input channels are used for their non-surround respective output channels (<code>L</code> and <code>R</code>). Surround output channels (<code>SL</code> and <code>SR</code>) are silent.<br>
<code>output.L = input.L<br>
output.R = input.R<br>
output.SL = 0<br>
output.SR = 0</code></td>
</tr>
<tr>
<td><code>2</code> <em>(Stereo)</em></td>
<td><code>6</code> <em>(5.1)</em></td>
<td><em>Up-mix from stereo to 5.1.</em><br>
The <code>L</code> and <code>R </code>input channels are used for their non-surround respective output channels (<code>L</code> and <code>R</code>). Surround output channels (<code>SL</code> and <code>SR</code>), as well as the center (<code>C</code>) and subwoofer (<code>LFE</code>) channels, are left silent.<br>
<code>output.L = input.L<br>
output.R = input.R<br>
output.C = 0<br>
output.LFE = 0<br>
output.SL = 0<br>
output.SR = 0</code></td>
</tr>
<tr>
<td><code>4</code> <em>(Quad)</em></td>
<td><code>1</code> <em>(Mono)</em></td>
<td><em>Down-mix from quad to mono</em>.<br>
All four input channels (<code>L</code>, <code>R</code>, <code>SL</code>, and <code>SR</code>) are equally combined to produce the unique output channel (<code>M</code>).<br>
<code>output.M = 0.25 * (input.L + input.R + </code><code>input.SL + input.SR</code><code>)</code></td>
</tr>
<tr>
<td><code>4</code> <em>(Quad)</em></td>
<td><code>2</code> <em>(Stereo)</em></td>
<td><em>Down-mix from quad to mono</em>.<br>
Both left input channels (<code>L</code> and <code>SL</code>) are equally combined to produce the unique left output channel (<code>L</code>). And similarly, both right input channels (<code>R</code> and <code>SR</code>) are equally combined to produce the unique right output channel (<code>R</code>).<br>
<code>output.L = 0.5 * (input.L + input.SL</code><code>)</code><br>
<code>output.R = 0.5 * (input.R + input.SR</code><code>)</code></td>
</tr>
<tr>
<td><code>4</code> <em>(Quad)</em></td>
<td><code>6</code> <em>(5.1)</em></td>
<td><em>Up-mix from quad to 5.1.</em><br>
The <code>L</code>, <code>R</code>, <code>SL</code>, and <code>SR</code> input channels are used for their respective output channels (<code>L</code> and <code>R</code>). Center (<code>C</code>) and subwoofer (<code>LFE</code>) channels are left silent.<br>
<code>output.L = input.L<br>
output.R = input.R<br>
output.C = 0<br>
output.LFE = 0<br>
output.SL = input.SL<br>
output.SR = input.SR</code></td>
</tr>
<tr>
<td><code>6</code> <em>(5.1)</em></td>
<td><code>1</code> <em>(Mono)</em></td>
<td><em>Down-mix from 5.1 to stereo.</em><br>
The left and right, both surround or not, and the central channels are all mixed together. The surround channels are slightly attenuated and the regular lateral channels are power-compensated to make them count as a single channel. The subwoofer (<code>LFE</code>) channel is lost.<br>
<code>output.M = 0.7071 * (input.L + input.R) + input.C + 0.5 * (input.SL + input.SR)</code></td>
</tr>
<tr>
<td><code>6</code> <em>(5.1)</em></td>
<td><code>2</code> <em>(Stereo)</em></td>
<td><em>Down-mix from 5.1 to stereo.</em><br>
The central (<code>C</code>) is summed with each lateral surround channels (<code>SL</code> or <code>SR</code>) and mixed to each lateral channel. As it is mixed in two channels, it is mixed at lower power, that is they are multiplied by <code>√2/2</code>. The subwoofer (<code>LFE</code>) channel is lost.<br>
<code>output.L = input.L + 0.7071 * (input.C + input.SL)<br>
output.R = input.R </code><code>+ 0.7071 * (input.C + input.SR)</code></td>
</tr>
<tr>
<td><code>6</code> <em>(5.1)</em></td>
<td><code>4</code> <em>(Quad)</em></td>
<td><em>Down-mix from 5.1 to quad.</em><br>
The central (<code>C</code>) is mixed with the lateral non-surround channels (<code>L</code> and <code>R</code>). As it is mixed in two channels, it is mixed at lower power, that is they are multiplied by <code>√2/2</code>. The surround channels are passed unchanged. The subwoofer (<code>LFE</code>) channel is lost.<br>
<code>output.L = input.L + 0.7071 * input.C<br>
output.R = input.R<br>
output.SL = input.SL<br>
output.SR = input.SR</code></td>
</tr>
<tr>
<td colspan="2" rowspan="1">Other</td>
<td>As these are non-standard channel layout, they are handled as if <code>channelInterpretation</code> was set to <code>discrete</code>.<br>
The specification explicitly allow the future definition of new speakers layout. This fallback is therefore not future proof as the behavior of the browsers for a specific amount of channels may change in the future.</td>
</tr>
<tr>
<th colspan="1" rowspan="2" scope="row"><code>discrete</code></th>
<td rowspan="1">any (<code>x</code>)</td>
<td rowspan="1">any (<code>y</code>) where <code>x<y</code></td>
<td><em>Up-mix discrete channels.</em><br>
Fill each output channel with its input counterpart, that is the input channel with the same index. Channels with no corresponding input channels are left silent.</td>
</tr>
<tr>
<td rowspan="1">any (<code>x</code>)</td>
<td rowspan="1">any (<code>y</code>) where <code>x>y</code></td>
<td><em>Down-mix discrete channels.</em><br>
Fill each output channel with its input counterpart, that is the input channel with the same index. Input channels with no corresponding output channels are dropped.</td>
</tr>
</tbody>
</table>
</dd>
</dl>
<h2 id="方法">方法</h2>
<p><em>Also implements methods from the interface </em>{{domxref("EventTarget")}}.</p>
<dl>
<dt>{{domxref("AudioNode.connect(AudioNode)")}}</dt>
<dd>允许将此节点的一个输出连接到另一个节点的一个输入。</dd>
<dt>{{domxref("AudioNode.connect(AudioParam)")}}</dt>
<dd>允许将此节点的一个输出连接到音频参数的一个输入。</dd>
<dt>{{domxref("AudioNode.disconnect()")}}</dt>
<dd>允许将这个节点从另一个节点断开连接。</dd>
</dl>
<h2 id="例子">例子</h2>
<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', '#AudioNode-section', 'AudioNode')}}</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>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatVersionUnknown}}{{property_prefix("webkit")}}</td>
<td>Activated on Nightly only</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>channelCount</code> <code>channelCountMode</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}} (?)</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>connect</code><code>(AudioParam)</code></td>
<td>{{CompatNo}}</td>
<td>Activated on Nightly only</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</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>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatNo}}</td>
<td>Activated on Nightly only</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>channelCount</code><br>
<code>channelCountMode</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}} (?)</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>connect</code><code>(AudioParam)</code></td>
<td>{{CompatNo}}</td>
<td>Activated on Nightly only</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="相关内容">相关内容</h2>
<ul>
<li>Using Web Audio</li>
</ul>
|