ChannelMergerNode

 ChannelMergerNode 接口,经常与其对应的 ChannelSplitterNode 接口一起使用,将不同的单声道输入重新组合成单个输出。每个输入用于填充输出的一个通道。这对于分别访问每个通道非常有用,例如,执行通道混合时,必须在每个信道上单独控制增益。

如果 ChannelMergerNode 用于一个单一输出,但输入数量与用于合并的信道数量相同;输入的数量被定义为其构造函数的参数及对 AudioContext.createChannelMerger 的调用。 如果没有给出值,则为默认值 6

使用 ChannelMergerNode,可以创建比渲染硬件能处理的更多的通道输出。在这种情况下,当信号发送至 AudioContext.listener 对象时,额外的信道将被忽略。

输入数量 变量; 默认为 6.
输出数量 1
通道计数模式 "max"
通道数量 2 (不在默认计数模式下使用)
频道解释 "speakers"

构造函数

ChannelMergerNode()
生成一个新的 ChannelMergerNode 对象实例。

属性

没有具体属性;从其父级继承属性, AudioNode

方法

没具体方法; 从其父级继承方法, AudioNode

例子

下面的例子展示了如何分离立体音轨(就是一段音乐),处理使左右声道不同。使用的时候,需要指定AudioNode.connect(AudioNode)方法的第二个和第三个参数,分别用来指定通道链接来源的索引和输出的索引。

var ac = new AudioContext();
ac.decodeAudioData(someStereoBuffer, function(data) {
 var source = ac.createBufferSource();
 source.buffer = data;
 var splitter = ac.createChannelSplitter(2);
 source.connect(splitter);
 var merger = ac.createChannelMerger(2);

 // Reduce the volume of the left channel only
 var gainNode = ac.createGain();
 gainNode.gain.value = 0.5;
 splitter.connect(gainNode, 0);

 // Connect the splitter back to the second input of the merger: we
 // effectively swap the channels, here, reversing the stereo image.
 gainNode.connect(merger, 0, 1);
 splitter.connect(merger, 1, 0);

 var dest = ac.createMediaStreamDestination();

 // Because we have used a ChannelMergerNode, we now have a stereo
 // MediaStream we can use to pipe the Web Audio graph to WebRTC,
 // MediaRecorder, etc.
 merger.connect(dest);
});

规格

Specification Status Comment
Web Audio API
ChannelMergerNode
Working Draft  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
ChannelMergerNodeChrome Full support 14Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
ChannelMergerNode() constructorChrome Full support 55Edge ? Firefox Full support 53IE No support NoOpera Full support 42Safari ? WebView Android Full support 55Chrome Android Full support 55Firefox Android Full support 53Opera Android Full support 42Safari iOS ? Samsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

参见