gpt4 book ai didi

nodes - WebAudio scriptProcessorNodes *需要*连接输出吗?

转载 作者:行者123 更新时间:2023-12-02 04:47:41 26 4
gpt4 key购买 nike

这里是一个简单的 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) + "%");
}

最佳答案

这是 Blink 和 Webkit 实现中的一个错误。来自规范:“仅当 ScriptProcessorNode 至少连接了一个输入或一个输出时,才会调度音频处理事件。”它不需要两者。

现在,只需将它连接到连接到 audiocontext.destination 的零增益 GainNode。

关于nodes - WebAudio scriptProcessorNodes *需要*连接输出吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19482155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com