Skip to content Skip to sidebar Skip to footer

How To Play Multiple Audiobuffersourcenode Synchronized?

I have multiple audio files that must be played in sync. I have read that Web Audio API is the best solution for this. But, I can't find any document that shows how to achieve this

Solution 1:

There is a single clock for the audio context, and the buffer playback is on that clock - so yes, they will stay in sync.

Even calling start(0); start(0); as above will be perfectly synchronized, because start() is setting up a scheduling request on the audio thread, and the actual scheduling of both of those will happen together. "now" is actually slightly in the future (the audio system latency).

Solution 2:

You can schedule them slightly in the future.

var source1, source2;
varwhen = context.currentTime + 0.01;

source1.start(when);
source2.start(when);

That'll schedule both sounds to play exactly 10ms from the moment you define when. It's quick enough that it'll be perceived as immediate, but gives a bit of breathing room for the overhead of actually calling start on the first source node.

There are better ways to do this if you have a ton of nodes, but for simple situations, this should be fine.

Post a Comment for "How To Play Multiple Audiobuffersourcenode Synchronized?"