WebAudio scriptProcessorNodes*是否需要连接输出?

Apt*_*ary 2 nodes scriptprocessor web-audio-api

这是一个简单的jsFiddle链接,它使用网络音频测量实时输入的响度(它将值作为百分比输出到控制台).

http://jsfiddle.net/XSnsF/

我计划有一个输入而没有输出,因为没有必要延迟我的音频信号等待我的自定义节点完成音量.

但是,很明显,如果连接的话,scriptProcessor 只会记录值context.destination.难道我做错了什么?或者这是一个错误?或者这是预期的行为?

function gotStream(stream) {

    var mediaStreamSource = context.createMediaStreamSource(stream);

    var gainNode = context.createGain();
    gainNode.gain.value = 3;

    var levelChecker = context.createScriptProcessor(2048);

    mediaStreamSource.connect(gainNode);
    gainNode.connect(levelChecker);

    //Commenting out the line directly below stops the script processor from working!
    levelChecker.connect(context.destination);
    levelChecker.onaudioprocess = process;

}

function process(e) {
    var buffer = e.inputBuffer.getChannelData(0);

    var maxVal = 0;

    for (var i = 0; i < buffer.length; i++) {

        if (maxVal < buffer[i]) {
            maxVal = buffer[i];
        }
    }

    console.log(Math.round(maxVal * 100) + "%");
}
Run Code Online (Sandbox Code Playgroud)

cwi*_*lso 5

这是Blink和Webkit实现中的一个错误.根据规范:"如果ScriptProcessorNode至少连接了一个输入或一个输出,则仅调度audioprocess事件." 它不需要两者.

现在,只需将其连接到连接到audiocontext.destination的零增益GainNode即可.