title: Webaudio Playback from WebSocket has drop-outs
body: <p>I have a software-defined radio playing an audio stream from a WebSocket server, and a client which consumes the data and plays it using an AudioBufferSourceNode.</p>
  
  <p>It mostly works. The only problem is that there are momentary dropouts every few seconds, presumably caused by the overhead involved in creating each successive AudioBufferSourceNode instance. The WebAudio draft spec says that AudioBuffer should be used for playing sounds that are no longer than a minute or so, and that longer sounds should be played using a MediaElementSourceNode. That doesn't work for me, because I need to play audio from a WebSocket source, and there's no way that I know of to make a media element (e.g. HTML5 audio element) work with a WebSocket.</p>
  
  <p>Maybe I'm trying to do something WebAudio can't support by stringing AudioBufferSourceNode instances together and expecting them to play one after another seamlessly. But it seems there should be a way to play WebSocket data through WebAudio, and indeed <a href="https://github.com/audiocogs/aurora.js" rel="nofollow">auroa.js</a> (together with the <a href="https://github.com/fsbdev/aurora-websocket" rel="nofollow">aurora-websocket.js</a> plugin) seems to do it. I coded up a client using aurora.js, but I ran into other problems, for which I created an auroa.js issue on Github. In the meantime, I'm hoping that I can do in my client what they seem to have done wrt using WebAudio to play data seamlessly from a WebSocket.</p>
  
  <p>Here is an elided view of my code, to show the implementation I'm using.</p>
  
  <pre><code>var context = ...
  var gainNode = ...
  
  var playBuffer = function(buf) {
     var source = context.createBufferSource();
     source.buffer = buf;
     source.connect(gainNode);
     source.start();
  };
  
  var socket = ...
  socket.binaryType = 'arraybuffer';
  socket.addBinaryListener(function (data) {
       context.decodeAudioData(data, playBuffer);
  });
  socket.connect...
  </code></pre>
  
  <p>I also tried an implementation wherein I keep track of incoming buffers from the WebSocket and play them in the order received, via an AudioBufferSourceNode, after the 'ended' event is received from the previous AudioBufferSourceNode. This has the same dropout problem that the above implementation has.</p>