Example for playing multiple sounds and/or tracks
designbyadrian opened this issue · 7 comments
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
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])?
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.
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
@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
@logesh2496 No, I'm clueless. In my humble opinion, more examples should be provided for developers who don't come from iOS/Android.
@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 }
@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