Skip to content

Example for playing multiple sounds and/or tracks #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
designbyadrian opened this issue Apr 13, 2021 · 7 comments
Closed

Example for playing multiple sounds and/or tracks #16

designbyadrian opened this issue Apr 13, 2021 · 7 comments

Comments

@designbyadrian
Copy link

Hello,

Is there any example you could provide for playing multiple simultaneous sounds and/or tracks? Something that looks like a mini piano would be really helpful!

I'm trying to have one global audio context, then connecting multiple audio nodes to it. Each process has its own player object. I get no errors, but also no sound.

If you're curious about where I'm doing something wrong, here's the gist of it (pun intended): https://gist.github.com/designbyadrian/947d4090bea34b4aff498cf09f0d7711

@designbyadrian
Copy link
Author

designbyadrian commented Apr 13, 2021

As a side note, if I've got more than ten different sounds I'd like to trigger, is it better to concatenate them into one file, then play using play([MEMORY LOCATION])?

@gaborszanto
Copy link
Member

Create on node only, and put all your audio processing code inside that single node, just like in the examples. To support multiple simultaneous sounds, just create that many AdvancedAudioPlayers.

@designbyadrian
Copy link
Author

I'm still having trouble with this. The problem lies with the processAudio function. Without it, I just get a loud noise. With it... well, I don't know how to process multiple tracks at once.

I'm using your time stretching example: https://gist.github.com/designbyadrian/5ecb91fe3cc2cac49911dc178d1fef36

@logesh2496
Copy link

logesh2496 commented May 6, 2021

@designbyadrian i'm into the same situation. things are fine with just one player.
Were you able to solve the issue?- How do I handle the silence in processAudio when multiple players are created?

Thanks

@designbyadrian
Copy link
Author

@logesh2496 No, I'm clueless. In my humble opinion, more examples should be provided for developers who don't come from iOS/Android.

@logesh2496
Copy link

@designbyadrian agree. And if you are still stuck with processStereo for multiple player, perhaps i can help you:

let silence = this.playerTwo.processStereo(outputBuffer.pointer, false, buffersize, 1) if ( // Add if conditions to each and every players except the first one this.playerTwo.processStereo(outputBuffer.pointer, !silence, buffersize, 1) ) { silence = false } if (silence === true) { for (let n = 0; n < buffersize * 2; n++) outputBuffer.array[n] = 0 }

@designbyadrian
Copy link
Author

@logesh2496 I had a non-working example using a similar check, but I had messed up the part where I write zeroes to the output buffer.

Here's a working example using 8 short MP3 files here: https://github.com/designbyadrian/web-audio-javascript-webassembly-SDK-interactive-audio/tree/example/multiple/example_multiple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants