Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum number of outputs for a Web Audio Context and Buffer

I'm trying to create a program which can output audio to any number of arbitrary channels in a single buffer. I'm using Chrome 43.0.2339.0 canary (64-bit) on a Mac. The hardware I am outputting to is a Motu 16A which is capable of 128 channels of IO over thunderbolt connection. I've created a pen (based on a modified MDN example) which demonstrates what I'm trying to accomplish: http://codepen.io/alexanderson1993/pen/dPwqPL

And the code:

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();
  }

You'll notice on line 4 I explicitly set the channel count to 8, even though my destination is capable of 128 channels (as is evidenced by running audioCtx.destination.maxChannelCount). This functions as expected, with audio being piped to all 8 channels. However, whenever I increase the channel count above 8, I get no output on any channels.

My question is where the limitation lies - is it in the AudioBuffer? The AudioContext? My hardware setup? Is there any way overcome these limitations and output to more channels than 8?

like image 213
Alex Anderson Avatar asked Nov 01 '22 07:11

Alex Anderson


1 Answers

This is a bug in chrome; it's being worked on.

like image 64
Raymond Toy Avatar answered Nov 15 '22 05:11

Raymond Toy