Web 音频上下文和缓冲区的最大输出数量是多少

Posted

技术标签:

【中文标题】Web 音频上下文和缓冲区的最大输出数量是多少【英文标题】:What is the maximum number of outputs for a Web Audio Context and Buffer 【发布时间】:2015-03-21 16:43:37 【问题描述】:

我正在尝试创建一个程序,该程序可以将音频输出到单个缓冲区中的任意数量的任意通道。我在 Mac 上使用 Chrome 43.0.2339.0 canary(64 位)。我要输出的硬件是 Motu 16A,它能够通过雷电连接实现 128 个 IO 通道。我创建了一支笔(基于修改后的 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 行,我明确地将通道数设置为 8,即使我的目的地能够支持 128 个通道(运行 audioCtx.destination.maxChannelCount 可以证明这一点)。这按预期运行,音频通过管道传输到所有 8 个通道。但是,每当我将通道数增加到 8 以上时,我在任何通道上都没有输出。

我的问题是限制在哪里 - 它在 AudioBuffer 中吗?音频上下文?我的硬件设置?有什么办法可以克服这些限制,输出到超过 8 个通道?

【问题讨论】:

这很漂亮。你是在 node.js 中运行这个吗? 这是供客户端使用的。据我所知,Node.js(和 IO.js)本身并不支持 WebAudio API。有一个可用的软件包here 声称处于预 alpha 阶段。 【参考方案1】:

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

【讨论】:

这个bug已经修复了吗?从事完全相同的项目 此问题已修复,但如果您遇到问题,请在crbug.com/new 提交新错误。如果可以,请务必将组件字段设置为“Blink>WebAudio”。

以上是关于Web 音频上下文和缓冲区的最大输出数量是多少的主要内容,如果未能解决你的问题,请参考以下文章

如何确定活动WebGL上下文的数量?

离屏渲染

将 Jack 与 Web 音频上下文连接

AudioUnit 帧的最大值?

ASIO SDK如何处理音频缓冲区

ffmpeg函数01__swr_convert()