recieveChannel.onmessage = function(event) {
if(typeof(event.data) === "string") {
// recieve the offset from the src to compensate for extra data at the start of
// every arraybuffer
firstBufferDur = Number(event.data);
console.log('offset: ' + firstBufferDur);
}
else {
audioContext.decodeAudioData(event.data, function(buffer) {
if(bufferQueue.length < 4) {
bufferQueue.unshift(buffer);
}
else {
bufferQueue.unshift(buffer);
nextBuffer = bufferQueue.pop();
soundSource = audioContext.createBufferSource();
soundSource.buffer = nextBuffer;
// here there is breakup because there is a gap between new buffer playing and old one ending
soundSource.start(audioContext.currentTime + prevBufferDur, firstBufferDur);
prevBufferDur = nextBuffer.duration;
soundSource.connect(soundDest);
tabAudio.srcObject = soundDest.stream;
tabAudio.play();
}
//visualizer();
}, function(error) {
console.log('Audio Decoding failed. Error: ' + String(error));
});
}
}