title: Converting a Float32Array of decoded samples to an AudioBuffer
body: <p>Because one of the browsers I'm trying to support doesn't allow me to decode a specific codec using <a href="http://docs.webplatform.org/wiki/apis/webaudio/AudioContext/decodeAudioData" rel="nofollow"><code>AudioContext.decodeAudioData()</code></a> I'm using <a href="https://github.com/audiocogs/aurora.js" rel="nofollow">Aurora.js</a> to decode a audio files.</p>
  
  <p>How can I change the decoded samples received from Aurora.js into an AudioBuffer I can actually use to playback the audio?</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>var AudioContext = (window.AudioContext || window.webkitAudioContext);
  var context = new AudioContext();
  var segmentUrls = [
      '/segments/00.wav',
      '/segments/05.wav',
      '/segments/10.wav',
      '/segments/15.wav',
      '/segments/20.wav',
      '/segments/25.wav',
      '/segments/30.wav',
      '/segments/35.wav',
      '/segments/40.wav',
      '/segments/45.wav',
      '/segments/50.wav',
      '/segments/55.wav'
  ];
  
  Promise.all(segmentUrls.map(loadSound))
      .then(function(buffers) {
          var startAt = 0;
          buffers.forEach(function(buffer) {
              playSound(startAt, buffer);
              startAt += buffer.duration;
          });
      })
      .catch(function(err) {
          console.error(err);
      });
  
  function playSound(offset, buffer) {
      var source = context.createBufferSource();
      source.buffer = buffer;
      source.connect(context.destination);
      source.start(offset);
  }
  
  function loadSound(url) {
      return new Promise(function(resolve, reject) {
          var request = new XMLHttpRequest();
          request.open('GET', url, true);
          request.responseType = 'arraybuffer';
  
          request.onload = function onLoad() {
              resolve(decodeAudioData(request.response));
          };
  
          request.onerror = function onError() {
              reject('Could not request file');
          };
          request.send();
      });
  }
  
  function decodeAudioData(audioData) {
      return new Promise(function(resolve, reject) {
          var asset = AV.Asset.fromBuffer(audioData);
          asset.decodeToBuffer(function(buffer) {
              // Create an AudioBuffer here
          });
      });
  }
  </code></pre>