5

I have audio files and I am using Web Audio API to play them on browser. Now I want to play all the audio files simultaneously.

I got audio buffers for all the audio files using Web Audio API. I can loop through all and can play them but I want to merge all the audio buffers into one single audio buffer and then play it.

Does anyone have an idea to merge two audio buffers in Web Audio API?

3 Answers 3

3

If you want to play all of the simultaneously, just connect each of your buffers to context.destination (or most any other node that is connected to the destination) and start them all at the same time.

Sign up to request clarification or add additional context in comments.

Comments

3

If you sum two or more audio PCM arrays, i.e. buffer1[i] + buffer2[i] for each sample, you will have a third audio containing both sounding together.

You can even use a multiply factor over each track to control its volume, for example.

Hope this helps. This is just the begining.

1 Comment

This should be the right answer. The Buffer is just the sine wave and you can just add Buffers to one another
2

If you need just to play it you should to connect both of sources to destination.

To really merge two buffers into another one, you can use offlineAudioContext or merge arrays yourself like this https://github.com/audiojs/audio-buffer-utils

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.