From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/audionode/connect(audioparam)/index.html | 163 +++++++++ files/zh-cn/web/api/audionode/connect/index.html | 145 ++++++++ files/zh-cn/web/api/audionode/index.html | 370 +++++++++++++++++++++ 3 files changed, 678 insertions(+) create mode 100644 files/zh-cn/web/api/audionode/connect(audioparam)/index.html create mode 100644 files/zh-cn/web/api/audionode/connect/index.html create mode 100644 files/zh-cn/web/api/audionode/index.html (limited to 'files/zh-cn/web/api/audionode') diff --git a/files/zh-cn/web/api/audionode/connect(audioparam)/index.html b/files/zh-cn/web/api/audionode/connect(audioparam)/index.html new file mode 100644 index 0000000000..eb82534aed --- /dev/null +++ b/files/zh-cn/web/api/audionode/connect(audioparam)/index.html @@ -0,0 +1,163 @@ +--- +title: AudioNode.connect(AudioParam) +slug: Web/API/AudioNode/connect(AudioParam) +translation_of: Web/API/AudioNode/connect(AudioParam) +--- +

{{ APIRef("Web Audio API") }}

+ +
+

允许我们将当前节点的一个输出连接到音频参数的一个输入,并允许通过音频信号控制参数。
+ 使AudioNode输出连接到多个AudioParam,并将多个AudioNode输出连接到单个 AudioParam,同时多次调用connect()。因此支持Fan-in and fan-out。
+  AudioParam可以从连接到它的任何AudioNode输出获取渲染的音频数据,并通过下混合将其转换为单声道(如果本身不是单声道的话)。然后,它将其他这样的输出和固定参数混合( AudioParam的值通常没有任何连接),包括为参数调度的任何时间的变化。
+ 因此,可以通过将AudioParam的值设置为中心频率来选择AudioParam将要更改的范围,并使用音频源和AudioParam之间的GainNode来调整AudioParam更改的范围。

+
+ +

Syntax

+ +
var lfo = audioCtx.createOscillator();
+lfo.frequency.value = 2.0; // Hz, two times per second
+
+var lfoGain = audioCtx.createGain();
+lfoGain.gain.value = 0.5;
+
+// this is the parameter that is going to be modulated
+var gain = audioCtx.createGain();
+gain.gain.value = 0.5;
+
+// Oscillators go from -1 to 1
+// Make it go from -0.5 to +0.5 by connecting it to a GainNode with a gain value of 0.5
+lfo.connect(lfoGain);
+
+// because the value of the gain.gain AudioParam is originaly 0.5, the value is added, and it will go from 0.0 to 1.0
+lfoGain.connect(gain.gain);
+
+lfo.connect(gain.gain);
+ +
+

Note: There can only be one connection between an output from one specific AudioNode and an {{ domxref("AudioParam") }}. Multiple connections to the same termini are equivalent to a single such connection (the duplicates are ignored).

+
+ +

Returns

+ +

Void.

+ +

Example

+ +

In this example, we will be altering the gain value of a {{domxref("GainNode")}} using an {{domxref("OscillatorNode")}} with a slow frequency value. This technique is know as an LFO-controlled parameter.

+ +
var AudioContext = window.AudioContext || window.webkitAudioContext;
+
+var audioCtx = new AudioContext();
+
+// create an normal oscillator to make sound
+var oscillator = audioCtx.createOscillator();
+
+// create a second oscillator that will be used as an LFO (Low-frequency
+// oscillator), and will control a parameter
+var lfo = audioCtx.createOscillator();
+
+// set the frequency of the second oscillator to a low number
+lfo.frequency.value = 2.0; // 2Hz: two oscillations par second
+
+// create a gain whose gain AudioParam will be controlled by the LFO
+var gain = audioCtx.createGain();
+
+// connect the LFO to the gain AudioParam. This means the value of the LFO
+// will not produce any audio, but will change the value of the gain instead
+lfo.connect(gain.gain);
+
+// connect the oscillator that will produce audio to the gain
+oscillator.connect(gain);
+
+// connect the gain to the destination so we hear sound
+gain.connect(audioCtx.destination);
+
+// start the oscillator that will produce audio
+oscillator.start();
+
+// start the oscillator that will modify the gain value
+lfo.start();
+ +

Parameters

+ +
+
Destination
+
The {{ domxref("AudioParam") }} you are connecting to.
+
Output (optional)
+
An index describing which output of the current AudioNode you want to connect to the {{ domxref("AudioParam") }}. The index numbers are defined according to the number of output channels (see Audio channels.)  If this parameter is out-of-bound, an INDEX_SIZE_ERR exception is thrown.
+
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-AudioNode-connect-void-AudioParam-destination-unsigned-long-output', 'connect(AudioParam)')}}{{Spec2('Web Audio API')}} 
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
connect(AudioParam){{CompatVersionUnknown}} {{property_prefix("webkit")}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)Firefox OS (Gecko)IE PhoneOpera MobileSafari Mobile
connect(AudioParam){{CompatNo}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/audionode/connect/index.html b/files/zh-cn/web/api/audionode/connect/index.html new file mode 100644 index 0000000000..a0b5a763cb --- /dev/null +++ b/files/zh-cn/web/api/audionode/connect/index.html @@ -0,0 +1,145 @@ +--- +title: AudioNode.connect() +slug: Web/API/AudioNode/connect +translation_of: Web/API/AudioNode/connect +--- +

{{ APIRef("Web Audio API") }}

+ +
+

{{ domxref("AudioNode") }} 接口的 connect() 方法使你能将一个节点的输出连接到一个指定目标,这个指定的目标可能是另一个 AudioNode(从而将音频数据引导到下一个指定节点)或一个{{domxref("AudioParam")}}, 以便上一个节点的输出数据随着时间流逝能自动地对下一个参数值进行改变。

+
+ +

语法

+ +
var destinationNode = AudioNode.connect(destination, outputIndex, inputIndex);
+
+AudioNode.connect(destination, outputIndex);
+
+ +

属性

+ +
+
destination
+
需要连接的 {{domxref("AudioNode")}} 或 {{domxref("AudioParam")}}.
+
outputIndex {{optional_inline}}
+
一个索引,用于描述当前  AudioNode 的哪个输出会连接到destination。索引数字是由输出频道(详见 Audio channels)的数量来确定的。当你只能将给定的输出连接到给定的输入一次(重复的尝试会被忽略)时,可以通过多次调用 connect() 将一个输出连接到多个输入。可以通过这样来实现扇出。这个参数的默认值为0。
+
inputIndex {{optional_inline}}
+
一个索引,用于描述当前  AudioNode 会连接到destination的哪个输入,它的默认值是0。索引数字是由输入频道(详见 Audio channels)的数量来确定的。将一个  AudioNode 连接回之前的 AudioNode,以此形成一个圈是可行的。 不过只在这个圈里有至少一个 {{domxref("DelayNode")}} 才可行。否则会抛出一个 NotSupportedError 异常。此参数在destination是 {{domxref("AudioParam")}}时不可用。
+
+ +

返回值

+ +

如果destination是一个节点, connect() 返回destination所表示的  {{domxref("AudioNode")}} 对象的引用,允许你链式地调用数个 connect() 。某些浏览器关于该接口的旧实现会返回 {{jsxref("undefined")}}。

+ +

如果destination是一个  AudioParamconnect() 返回 undefined.

+ +

异常

+ +
+
IndexSizeError
+
这个异常表明 outputIndex 或 inputIndex 与当前输入或输出不符。
+
InvalidAccessError
+
目标节点与原节点不在同一个音频上下文。
+
NotSupportedError
+
该链接会形成一个闭环(音频在这个环里不断重复经过同一个节点)并且这个闭环里没有 {{domxref("DelayNode")}} 来防止产生的波形被卡住,不停地构建相同的音频帧。
+
+ +

示例

+ +

Connecting to an audio input

+ +

The most obvious use of the connect() method is to direct the audio output from one node into the audio input of another node for further processing. For example, you might send the audio from a {{domxref("MediaElementAudioSourceNode")}}—that is, the audio from an HTML5 media element such as {{HTMLElement("audio")}}—through a band pass filter implemented using a {{domxref("BiquadFilterNode")}} to reduce noise before then sending the audio along to the speakers.

+ +

This example creates an oscillator, then links it to a gain node, so that the gain node controls the volume of the oscillator node.

+ +
var AudioContext = window.AudioContext || window.webkitAudioContext;
+
+var audioCtx = new AudioContext();
+
+var oscillator = audioCtx.createOscillator();
+var gainNode = audioCtx.createGain();
+
+oscillator.connect(gainNode);
+gainNode.connect(audioCtx.destination);
+
+ +

AudioParam example

+ +

In this example, we will be altering the gain value of a {{domxref("GainNode")}} using an {{domxref("OscillatorNode")}} with a slow frequency value. This technique is know as an LFO-controlled parameter.

+ +
var AudioContext = window.AudioContext || window.webkitAudioContext;
+
+var audioCtx = new AudioContext();
+
+// create an normal oscillator to make sound
+var oscillator = audioCtx.createOscillator();
+
+// create a second oscillator that will be used as an LFO (Low-frequency
+// oscillator), and will control a parameter
+var lfo = audioCtx.createOscillator();
+
+// set the frequency of the second oscillator to a low number
+lfo.frequency.value = 2.0; // 2Hz: two oscillations par second
+
+// create a gain whose gain AudioParam will be controlled by the LFO
+var gain = audioCtx.createGain();
+
+// connect the LFO to the gain AudioParam. This means the value of the LFO
+// will not produce any audio, but will change the value of the gain instead
+lfo.connect(gain.gain);
+
+// connect the oscillator that will produce audio to the gain
+oscillator.connect(gain);
+
+// connect the gain to the destination so we hear sound
+gain.connect(audioCtx.destination);
+
+// start the oscillator that will produce audio
+oscillator.start();
+
+// start the oscillator that will modify the gain value
+lfo.start();
+ +

AudioParam notes

+ +

It is possible to connect an AudioNode output to more than one {{ domxref("AudioParam") }}, and more than one AudioNode output to a single {{ domxref("AudioParam") }}, with multiple calls to connect(). Fan-in and fan-out are therefore supported.

+ +

An {{ domxref("AudioParam") }} will take the rendered audio data from any AudioNode output connected to it and convert it to mono by down-mixing (if it is not already mono). Next, it will mix it together with any other such outputs, and the intrinsic parameter value (the value the {{ domxref("AudioParam") }} would normally have without any audio connections), including any timeline changes scheduled for the parameter.

+ +

Therefore, it is possible to choose the range in which an {{domxref("AudioParam")}} will change by setting the value of the {{domxref("AudioParam")}} to the central frequency, and to use a {{domxref("GainNode")}} between the audio source and the {{domxref("AudioParam")}} to adjust the range of the {{domxref("AudioParam")}} changes.

+ +

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-AudioNode-connect-AudioNode-AudioNode-destination-unsigned-long-output-unsigned-long-input', 'connect() to an AudioNode')}}{{Spec2('Web Audio API')}} 
{{SpecName('Web Audio API', '#widl-AudioNode-connect-void-AudioParam-destination-unsigned-long-output', 'connect() to an AudioParam')}}{{Spec2('Web Audio API')}} 
+ +

Browser compatibility

+ +
+ + +

{{Compat("api.AudioNode.connect")}}

+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/audionode/index.html b/files/zh-cn/web/api/audionode/index.html new file mode 100644 index 0000000000..1c08f81dc4 --- /dev/null +++ b/files/zh-cn/web/api/audionode/index.html @@ -0,0 +1,370 @@ +--- +title: AudioNode +slug: Web/API/AudioNode +translation_of: Web/API/AudioNode +--- +
{{ APIRef("Web Audio API") }} {{SeeCompatTable}}
+ +

AudioNodes participating in an AudioContext create a audio routing graph.AudioNode 接口是一个处理音频的通用模块, 比如一个音频源 (e.g. 一个 HTML {{HTMLElement("audio")}} or {{HTMLElement("video")}} 元素), 一个音频地址或者一个中间处理模块 (e.g. 一个过滤器如 {{domxref("BiquadFilterNode")}}, 或一个音量控制器如 {{domxref("GainNode")}}).

+ +

一个AudioNode 既有输入也有输出。输入与输出都有一定数量的通道。只有一个输出而没有输入的 AudioNode 叫做音频源。

+ +

处理多个 AudioNode 时,一般来说, 一个模块读取它的输入,做一些处理。后输出新生成的结果。

+ +

不同的模块可以连接在一起构建一个处理图。 这样一个处理图包含 {{domxref("AudioContext")}}。 每个 AudioNode 只有一个这样的上下文。

+ +

一个 AudioNode 可以作为事件的目标,所以它实现了 {{domxref("EventTarget")}} 接口。

+ +

属性

+ +
+
{{domxref("AudioNode.context")}} {{readonlyInline}}
+
链接到关联的 {{domxref("AudioContext")}},处理图中模块的上下文对象。
+
+ +
+
{{domxref("AudioNode.numberOfInputs")}} {{readonlyInline}}
+
返回这个node需要的输入数量. Source nodes are defined as nodes having a numberOfInputs attributes with a value of 0.
+
+ +
+
{{domxref("AudioNode.numberOfOutputs")}} {{readonlyInline}}
+
返回这个node的输出数量. Destination nodes, like AudioDestinationNode, have a value of 0 for this attribute.
+
+ +
+
{{domxref("AudioNode.channelCount")}}
+
Represents an integer used in determining how many channels outputs must contains. Its usage and precise definition depends of the value of AudioNode.channelCountMode: it is ignored if the value is "max", used as a maximum value for "clamped-max", or used as the effective value for "explicit".
+
+ +
+
{{domxref("AudioNode.channelCountMode")}}
+
Represents an enumerated value describing the way channels must be matched between the inputs and the outputs. Possible values are: + + + + + + + + + + + + + + + + + + + + + + + + + +
ValueDescriptionUsed as default for the following AudioNode children
"max"The number of channels is the maximum of the number of channels all connections. That implies that channelCount is ignored and only up-mixing happens{{domxref("GainNode")}}, {{domxref("DelayNode")}}, {{domxref("ScriptProcessorNode")}}, {{domxref("ChannelSplitterNode")}}, {{domxref("ChannelMergerNode")}}, {{domxref("BiquadFilterNode")}}, {{domxref("WaveShaperNode")}}
"clamped-max"The number of channels is the maximum of the number of channels of all connections, clamped to the value of channelCount.{{domxref("PannerNode")}}, {{domxref("ConvolverNode")}}
"explicit"The number of channels is defined by the value of channelCount.{{domxref("AudioDestinationNode")}}, {{domxref("AnalyserNode")}}, {{domxref("DynamicsCompressorNode")}}
+
+
{{domxref("AudioNode.channelInterpretation")}}
+
Represents an enumerated value describing the meaning of the channels. This interpretation will define how the up-mixing and the down-mixing will happen.
+ The possible values are "speakers" or "discrete". In the case of "speakers", the ordering of the channels have the following meaning, and the channels are often represented by a standard abbreviation: + + + + + + + + + + + + + + + + + + + +
Mono0: M: mono
Stereo0: L: left
+ 1: R: right
Quad0: L:  left
+ 1: R:  right
+ 2: SL: surround left
+ 3: SR: surround right
5.10: L:   left
+ 1: R:   right
+ 2: C:   center
+ 3: LFE: subwoofer
+ 4: SL:  surround left
+ 5: SR:  surround right
+ When the amount of channels doesn't match between an input and an output, up- or down-mixing happens according the following rules: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
InterpretationInput channelsOutput channelsMixing rules
speakers1 (Mono)2 (Stereo)Up-mix from mono to stereo.
+ The M input channel is used for both output channels (L and R).
+ output.L = input.M
+ output.R = input.M
1 (Mono)4 (Quad)Up-mix from mono to quad.
+ The M input channel is used for non-surround output channels (L and R). Surround output channels (SL and SR) are silent.
+ output.L  = input.M
+ output.R  = input.M
+ output.SL = 0
+ output.SR = 0
1 (Mono)6 (5.1)Up-mix from mono to 5.1.
+ The M input channel is used for the center output channel (C). All the others (L, R, LFE, SL, and SR) are silent.
+ output.L   = 0
+ output.R   = 0

+ output.C   = input.M
+ output.LFE = 0
+ output.SL  = 0
+ output.SR  = 0
2 (Stereo)1 (Mono)Down-mix from stereo to mono.
+ Both input channels (L and R) are equally combined to produce the unique output channel (M).
+ output.M = 0.5 * (input.L + input.R)
2 (Stereo)4 (Quad)Up-mix from stereo to quad.
+ The L and R input channels are used for their non-surround respective output channels (L and R). Surround output channels (SL and SR) are silent.
+ output.L  = input.L
+ output.R  = input.R
+ output.SL = 0
+ output.SR = 0
2 (Stereo)6 (5.1)Up-mix from stereo to 5.1.
+ The L and R input channels are used for their non-surround respective output channels (L and R). Surround output channels (SL and SR), as well as the center (C) and subwoofer (LFE) channels, are left silent.
+ output.L   = input.L
+ output.R   = input.R
+ output.C   = 0
+ output.LFE = 0
+ output.SL  = 0
+ output.SR  = 0
4 (Quad)1 (Mono)Down-mix from quad to mono.
+ All four input channels (L, R, SL, and SR) are equally combined to produce the unique output channel (M).
+ output.M = 0.25 * (input.L + input.R + input.SL + input.SR)
4 (Quad)2 (Stereo)Down-mix from quad to mono.
+ Both left input channels (L and SL) are equally combined to produce the unique left output channel (L). And similarly, both right input channels (R and SR) are equally combined to produce the unique right output channel (R).
+ output.L = 0.5 * (input.L + input.SL)
+ output.R = 0.5 * (input.R + input.SR)
4 (Quad)6 (5.1)Up-mix from quad to 5.1.
+ The L, R, SL, and SR input channels are used for their respective output channels (L and R). Center (C) and subwoofer (LFE) channels are left silent.
+ output.L   = input.L
+ output.R   = input.R
+ output.C   = 0
+ output.LFE = 0
+ output.SL  = input.SL
+ output.SR  = input.SR
6 (5.1)1 (Mono)Down-mix from 5.1 to stereo.
+ 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 (LFE) channel is lost.
+ output.M = 0.7071 * (input.L + input.R) + input.C + 0.5 * (input.SL + input.SR)
6 (5.1)2 (Stereo)Down-mix from 5.1 to stereo.
+ The central (C) is summed with each lateral surround channels (SL or SR) 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 √2/2. The subwoofer (LFE) channel is lost.
+ output.L   = input.L + 0.7071 * (input.C + input.SL)
+ output.R   = input.R
+ 0.7071 * (input.C + input.SR)
6 (5.1)4 (Quad)Down-mix from 5.1 to quad.
+ The central (C) is mixed with the lateral non-surround channels (L and R). As it is mixed in two channels, it is mixed at lower power, that is they are multiplied by √2/2. The surround channels are passed unchanged. The subwoofer (LFE) channel is lost.
+ output.L   = input.L + 0.7071 * input.C
+ output.R   = input.R
+ output.SL  = input.SL
+ output.SR  = input.SR
OtherAs these are non-standard channel layout, they are handled as if channelInterpretation was set to discrete.
+ 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.
discreteany (x)any (y) where x<yUp-mix discrete channels.
+ 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.
any (x)any (y) where x>yDown-mix discrete channels.
+ 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.
+
+
+ +

方法

+ +

Also implements methods from the interface {{domxref("EventTarget")}}.

+ +
+
{{domxref("AudioNode.connect(AudioNode)")}}
+
允许将此节点的一个输出连接到另一个节点的一个输入。
+
{{domxref("AudioNode.connect(AudioParam)")}}
+
允许将此节点的一个输出连接到音频参数的一个输入。
+
{{domxref("AudioNode.disconnect()")}}
+
允许将这个节点从另一个节点断开连接。
+
+ +

例子

+ + + +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#AudioNode-section', 'AudioNode')}}{{Spec2('Web Audio API')}}
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatVersionUnknown}}{{property_prefix("webkit")}}Activated on Nightly only{{CompatNo}}{{CompatNo}}{{CompatUnknown}}
channelCount channelCountMode{{CompatNo}}{{CompatNo}} (?){{CompatNo}}{{CompatNo}}{{CompatNo}}
connect(AudioParam){{CompatNo}}Activated on Nightly only{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatNo}}Activated on Nightly only{{CompatNo}}{{CompatNo}}{{CompatUnknown}}
channelCount
+ channelCountMode
{{CompatNo}}{{CompatNo}} (?){{CompatNo}}{{CompatNo}}{{CompatNo}}
connect(AudioParam){{CompatNo}}Activated on Nightly only{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

相关内容

+ + -- cgit v1.2.3-54-g00ecf