0

我有两个一秒钟的音频源,如下所示:

var context = system.AudioContext();
var source = context.createBufferSource();

var audioBuffer1 = context.createBuffer(1, float32Array_1.length, context.sampleRate);
audioBuffer1.getChannelData(0).set(float32Array_1);

var audioBuffer2 = context.createBuffer(1, float32Array_2.length, context.sampleRate);
audioBuffer2.getChannelData(0).set(float32Array_2);

现在我想播放这两个音频源,它们之间没有延迟。对于单一来源,我可以使用以下代码播放音频:

source.buffer = audioBuffer1;
source.connect(context.destination);
source.start(0);

我怎样才能附加第二个来源,以便它们之间没有延迟。

4

1 回答 1

5
var context = system.AudioContext();
var source = context.createBufferSource();
var source2 = context.createBufferSource();

var audioBuffer1 = context.createBuffer(1, float32Array_1.length, context.sampleRate);
audioBuffer1.getChannelData(0).set(float32Array_1);

var audioBuffer2 = context.createBuffer(1, float32Array_2.length, context.sampleRate);
audioBuffer2.getChannelData(0).set(float32Array_2);

source.buffer = audioBuffer1;
source.connect(context.destination);

source2.buffer = audioBuffer2;
source2.connect(context.destination);

var time = context.currentTime;

source.start(time);
source2.start(time+audioBuffer1.duration);
于 2014-08-11T16:54:40.770 回答