codetemplar
codetemplar

Reputation: 681

Html5 web API AudioBufferSourceNode sound syncing

I have 4 wav files all designed to be played at the same time. I have created the 4 sound buffers and play them with the start function. All 4 sounds are played successfully but they are slightly out of sync with each other. I guess each call to start takes long enough for the subsequent call to be out of sync. Is there anyway I can force them to sync? Thanks

Upvotes: 0

Views: 125

Answers (1)

Oskar Eriksson
Oskar Eriksson

Reputation: 2641

Without seeing you code, these are the spontaneous ideas I have. Make sure to check the following:

  1. Give the exact same start time to the start method (maybe save context.currentTime + a little bit in a var and pass it to the start method of each source node, don't pass context.currentTime to each source in a for loop or similar (the context time might update while that's executing, thus the time passed to each source is different)).

  2. Make sure that the audio files are cut exactly the same in the beginning of the file. If you have 10 ms extra silence in one of the files, that file will always be 10ms off (unless you compensate for it in the code).

If none of that works/applies, please add some code to your question explaining what you're doing right now.

Upvotes: 2

Related Questions