admin管理员组

文章数量:1417070

I have two one-second audio sources as follows:

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);

Now I want to play these two audio sources with no delay between them. For a single source I can play the audio with the following code:

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

How can I attach the second source such that there would be no delay between them.

I have two one-second audio sources as follows:

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);

Now I want to play these two audio sources with no delay between them. For a single source I can play the audio with the following code:

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

How can I attach the second source such that there would be no delay between them.

Share Improve this question edited Aug 11, 2014 at 8:50 Xan 77.7k18 gold badges197 silver badges217 bronze badges asked Aug 11, 2014 at 8:47 BelaviyoBelaviyo 1872 silver badges11 bronze badges 2
  • Is the idea that you want to play them simultaneously, or that you want them to play sequentially ? – Kevin Ennis Commented Aug 11, 2014 at 15:48
  • The idea is to play them sequentially with no glitch. – Belaviyo Commented Aug 11, 2014 at 19:04
Add a ment  | 

1 Answer 1

Reset to default 6
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);

本文标签: javascriptMultiple sources for AudioContext()Stack Overflow