Mar*_*S95 5 javascript web-audio-api
我试图通过一个channelsplitter带有增益控制的6个通道将立体声音频路由,然后返回到a channelMerger,以控制5.1组的所有6个通道.该组通过HDMI连接,并且窗口正确输出到所有6个通道(一个屏幕,您可以让所有6个扬声器分别播放声音).
我能找到的唯一例子就是这段代码:
if (context.destination.maxChannelCount >= 6) {
context.destination.channelCount = 6;
}
else {
context.destination.channelCount = 2;
}
Run Code Online (Sandbox Code Playgroud)
初始化audiocontext时,我的channelCount默认为2,maxChannelCount为6.
我使用以下代码在中间创建拆分器,合并和增益:
if (context.destination.maxChannelCount >= 6) {
context.destination.channelCount = 6;
}
else {
context.destination.channelCount = 2;
}
context.destination.channelCountMode = "explicit";
context.destination.channelInterpretation = "discrete";
var ammount = context.destination.channelCount;
console.log('Ammount of channels:',ammount); //this outputs 6
window.channelSplitter = context.createChannelSplitter(ammount);
window.channelMerger = context.createChannelMerger(ammount);
postGain.connect(channelSplitter); //postGain is the last node of the audio system
channelMerger.connect(context.destination);
window.channelGains = [];
for(i=0;i<ammount;i++){
channelGains[i] = context.createGain();
channelSplitter.connect(channelGains[i],i,0);
channelGains[i].connect(channelMerger,0,i);
}
Run Code Online (Sandbox Code Playgroud)
我在chrome(39.0.2171.71 m)中尝试了这个,其中maxChannelCount是6. Firefox输出2.
编辑:在摆弄了channelSplitter之后,我发现除了前两个之外的所有输出都保持沉默.根据规范,当使用channelinterpretation'speaker'时,这是正确的.这意味着我需要自己填充频道,可能是通过使用此处描述的算法.我仍然需要检查chrome是否正确输出所有6个频道.
该问题是由channelSplitter 未在所有通道上输出引起的(这是我所期望的)。尽管根据规范,这种行为是正确的。因此,我们需要将自己的立体声写入 5.1 上混音器。但为了测试声音输出,我使用了左声道,并且能够独立输出到所有 6 个声道。我只遇到了一个问题。connect 方法上的输入参数(第三个)并不决定输出的顺序,如此处所示。调用的顺序.connect()决定了输出的顺序。但是,第三个数字需要存在并且与我调用的其他时间不同.connect(但在输入数量的范围内)。
另一件事是我注意到合并器和分离器上的channelCount等于2。但是我发现当channelCountMode设置为max时并不重要
除了上述所有内容之外,我还摆弄了所有这些设置,但它们对此没有任何影响。唯一重要的事情是将目标节点上的channelCount 设置为maxChannelCount。
但是,当未将所有通道连接到通道合并器时,合并器会根据这些规则对传入信号进行上混音。当设置channelInterpretation为显式时,您仍然会得到上混音结果,而根据规范,它应该填充通道,并使每个通道没有输入为空(因此仅将第一个通道输出到左通道,并保留右通道)输出无声)。
下面是一个摆弄立体声通道的片段。
onload = function(){
window.context = new AudioContext();
window.source = context.createMediaElementSource(document.getElementById('player'));
window.splitter = context.createChannelSplitter(2);
source.connect(splitter);
window.merger = context.createChannelMerger(2);
window.leftGain = context.createGain();
window.rightGain = context.createGain();
splitter.connect(leftGain, 0, 0);
splitter.connect(rightGain, 1, 0);
//--------try (de)commenting things below-------
leftGain.connect(merger, 0, 0);
rightGain.connect(merger, 0, 1);
//merger.channelInterpretation = 'discrete' //doesn't seem to have influcence..
//merger.channelCountMode = 'explicit' //makes everything only output to the left channel
//-------until here------
merger.connect(context.destination);
var leftRange = document.querySelector('#left');
var rightRange = document.querySelector('#right');
leftRange.oninput = function(){leftGain.gain.value = this.value}
rightRange.oninput = function(){rightGain.gain.value = this.value}
}Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<audio src="http://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg" controls autoplay id="player" preload></audio><br />
<label for="left">Left channel</label>
<input type="range" min=0 max=1 step=.01 value=1 id="left" /><br />
<label for="right">Right channel</label>
<input type="range" min=0 max=1 step=.01 value=1 id="right" />
</body>
</html>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1740 次 |
| 最近记录: |