Web audio API: scheduling sounds and exporting the mix

前端 未结 1 717
花落未央
花落未央 2020-12-14 23:58

I\'ve been checking Web Audio API documentation and the tutorials but haven\'t quiet figured out how to approach this problem.

Let\'s say I load few wav files via XM

相关标签:
1条回答
  • 2020-12-15 00:56

    Just did something a bit like this.

    Essentially, you'll need to create an offline context:

    var offline = new webkitOfflineAudioContext(numChannels, lengthInSamples, sampleRate)
    

    You'll have to recreate all your BufferSources using this new context:

    var newBufferSource = offline.createBufferSource();
    newBufferSource.buffer = someAudioBuffer;
    newBufferSource.connect(offline.destination);
    

    Then schedule your playback:

    newBufferSource.start(offline.currentTime + 10);
    

    Then bind to the complete event for your offline rendering:

    offline.onComplete = function( ev ){
      doSomething(ev.renderedBuffer);
    }
    

    Then start 'rendering':

    offline.startRendering();
    

    Once you have ev.renderedBuffer, you can do whatever you want with it. In my app, I have a WAV encoder that I ended up writing myself - but you could modify Recorder.js to do the same thing pretty easily.

    Just a heads-up: webkitOfflineAudioContext is Chrome-only at the moment. Here's a link if you're interested: OfflineAudioContext

    0 讨论(0)
提交回复
热议问题