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?
This is a bug in chrome; it's being worked on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With