Firefox seems to be processing audio, but it does not play it. This exact code works great with Chrome. I do not see errors from the console, so I'm really at a loss. I think this has something to do with audioBuffer.getChannelData (0) .set (audio); but I'm not sure. Does anyone know why this sound will not play in FF, but will be in Chrome? Now I am running FF 27.
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();
var init = 0;
var nextTime = 0;
var audioStack = [];
function toArrayBuffer(buffer) {
var ab = new ArrayBuffer(buffer.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buffer.length; ++i) {
view[i] = buffer[i];
}
return ab;
}
socket.on('stream', function(data) {
audioStack.push(data);
init++;
scheduleBuffers();
});
function scheduleBuffers() {
while (audioStack.length) {
var data = toArrayBuffer(audioStack.shift().data);
var audio = [];
audData = new Int16Array(data);
for (var i = 0; i < audData.length; i++) {
audio[i] = (audData[i]>0)?audData[i]/32767:audData[i]/32768;
}
var source = context.createBufferSource();
var audioBuffer = context.createBuffer(1, audio.length , 44100);
source.buffer = audioBuffer;
audioBuffer.getChannelData(0).set(audio);
source.connect(context.destination);
if (nextTime == 0)
nextTime = context.currentTime + 0.05;
source.start(nextTime);
console.log('length: '+source.buffer.duration);
nextTime+=source.buffer.duration;
};
}
source
share