merge multiple audio buffer sources

走远了吗. 提交于 2019-12-21 05:48:09

问题


Question about html5 webaudio: is it possible to merge multiple songs together?

I have different tracks that are all played at the same time using webaudio but I need to process the audio so I need all the audio inside one buffer in stead of each of the tracks having it's own buffer.

i've tried merging them by adding their channel data but I always get "Uncaught RangeError: Index is out of range. "

function mergeBuffers(recBuffers, recLength){

  var result = new Float32Array(recLength*2);
  var offset = 0;
  for (var i = 0; i < recBuffers.length; i++){
    result.set(recBuffers[0], offset);
    offset += recBuffers[0].length;
  }
  return result;
}

var recBuffersL = [];
for (var i=0;i<audioTracks.length; i++)
{
    recBuffersL[i] = audioTracks[i].currentBuffer.getChannelData(0);

}

var recBuffersR = [];
for (var i=0;i<audioTracks.length; i++)
{
    recBuffersR[i] = audioTracks[i].currentBuffer.getChannelData(1);

}


var buffers = [];
buffers.push( mergeBuffers(recBuffersL, recBuffersL.length) );
buffers.push( mergeBuffers(recBuffersR, recBuffersR.length) );

回答1:


Turns out it is possible: i had to sum the Float32Array




回答2:


I'd connect the output of both sources to a ScriptProcessorNode and process them in real-time.




回答3:


You can use an OfflineAudioContext and get the resulting buffer back. That would let you process + merge in faster than realtime.



来源:https://stackoverflow.com/questions/13709391/merge-multiple-audio-buffer-sources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!