gpt4 book ai didi

javascript - Web Audio Context 和 Buffer 的最大输出数量是多少

转载 作者:行者123 更新时间:2023-11-30 00:31:43 33 4
gpt4 key购买 nike

我正在尝试创建一个程序,它可以在单个缓冲区中将音频输出到任意数量的任意 channel 。我在 Mac 上使用 Chrome 43.0.2339.0 canary(64 位)。我要输出到的硬件是 Motu 16A,它能够通过雷电连接实现 128 个 IO channel 。我创建了一支笔(基于修改后的 MDN 示例)来演示我要完成的工作:http://codepen.io/alexanderson1993/pen/dPwqPL

还有代码:

var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var button = document.querySelector('button');

audioCtx.destination.channelCount = 8

var channels = audioCtx.destination.channelCount;
// Create an empty half-second buffer at the
// sample rate of the AudioContext
var frameCount = audioCtx.sampleRate * 0.5;
button.onclick = function(){
var myArrayBuffer = audioCtx.createBuffer(audioCtx.destination.channelCount, frameCount, audioCtx.sampleRate);

// Fill the buffer with white noise;
//just random values between -1.0 and 1.0
for (var channel = 0; channel < channels; channel++) {
// This gives us the actual ArrayBuffer that contains the data
var nowBuffering = myArrayBuffer.getChannelData(channel);
for (var i = 0; i < frameCount; i++) {
// Math.random() is in [0; 1.0]
// audio needs to be in [-1.0; 1.0]
nowBuffering[i] = Math.random() * 2 - 1;
}
}

// Get an AudioBufferSourceNode.
// This is the AudioNode to use when we want to play an AudioBuffer
var source = audioCtx.createBufferSource();
// set the buffer in the AudioBufferSourceNode
source.buffer = myArrayBuffer;
// connect the AudioBufferSourceNode to the
// destination so we can hear the sound
source.connect(audioCtx.destination);
// start the source playing
source.start();
}

您会注意到在第 4 行我明确地将 channel 数设置为 8,即使我的目的地能够有 128 个 channel (运行 audioCtx.destination.maxChannelCount 证明)。这按预期运行,音频通过管道传输到所有 8 个 channel 。但是,每当我将 channel 数增加到 8 以上时,我在任何 channel 上都没有输出。

我的问题是限制在哪里——是在 AudioBuffer 中吗?音频上下文?我的硬件设置?有没有办法克服这些限制并输出到超过 8 个 channel ?

最佳答案

这是一个 bug in chrome ;正在处理中。

关于javascript - Web Audio Context 和 Buffer 的最大输出数量是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29185251/

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