【问题标题】:Web audio 5.1 (6 channel) output网络音频 5.1(6 声道)输出
【发布时间】:2014-11-28 18:24:40
【问题描述】:

我正在尝试通过channelsplitter 将立体声音频路由到具有增益控制的 6 个通道,然后返回到channelMerger,以控制 5.1 组的所有 6 个通道。设备通过 HDMI 连接,windows 正确输出到所有 6 个通道(一个可以让所有 6 个扬声器分别播放声音的屏幕)。

我能找到的唯一例子有这段代码:

if (context.destination.maxChannelCount >= 6) {
    context.destination.channelCount = 6;
}
else {
    context.destination.channelCount = 2;
}

初始化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);
}

我在 chrome(39.0.2171.71 m) 中尝试过,其中 maxChannelCount 为 6。Firefox 输出 2。

编辑: 在摆弄了 channelSplitter 之后,我发现除了前两个之外的所有输出都保持沉默。根据spec,当使用通道解释“扬声器”时,这是正确的。 这意味着我需要自己填充通道,可能使用here 描述的算法。我仍然需要检查 chrome 是否正确输出所有 6 个通道。

【问题讨论】:

    标签: javascript web-audio-api


    【解决方案1】:

    问题是由于 channelSplitter 没有在所有通道上输出(我预期的)引起的。尽管根据规范,这种行为是正确的。因此,我们需要将自己的立体声写入 5.1 上混器。但是为了测试声音输出,我使用了左声道,我能够独立输出到所有 6 个声道。我只遇到了一个问题。 connect 方法上的输入参数(第 3 个)不决定输出的顺序,如看到的here。调用.connect() 的顺序决定了输出的顺序。但是,第三个数字需要存在并且与我调用.connect 的其他时间不同(但在输入数量的范围内)。

    另一件事我注意到合并和拆分器上的channelCount等于2。但是我发现它does not matter when having channelCountMode set to max

    除了上述所有,我摆弄了所有这些设置,但它们对此没有任何影响。唯一重要的是将目标节点上的 channelCount 设置为 maxChannelCount。

    但是,当没有将所有通道连接到通道合并器时,合并器会根据these 规则对传入信号进行上混。将channelInterpretation 设置为显式时,您仍然会得到上混结果,而根据规范,它应该填充通道,并使每个通道没有输入为空(因此仅将第一个通道输出到左通道,并且保持正确的输出静默)。

    下面是一个用于处理立体声通道的 sn-p。

    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}
    }
    <!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>

    【讨论】:

    • 有趣。这需要反馈给 WebAudio 委员会,以便在规范中准确定义其工作方式。
    • @notthetup 是的,我正在考虑在 code.google.com/p/chromium/issues/list 上提交错误。
    • @notthetup 我决定不提交错误。我摆弄了 channelInterpretation 和 channelCountMode,这些功能也有所作为。例如,根据this,将一个通道连接到立体声合并器将向上混音。将 channelInterpretation 设置为离散并连接两个通道时,仅听到左扬声器的输出。这是fiddle with
    • 找到this。它仍然令人眼花缭乱。也许画一张图可以帮助澄清这一点。
    猜你喜欢
    • 1970-01-01
    • 2022-12-22
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 2023-03-13
    相关资源
    最近更新 更多