charlieroberts / genish.js

a js library to compile optimized audio callbacks inspired by gen~
http://www.charlie-roberts.com/genish
MIT License
119 stars 14 forks source link

Play multiple graphs at the same time? #20

Open WesleyAC opened 2 years ago

WesleyAC commented 2 years ago

Hi! Genish looks really great — I started playing with it, and it looks almost exactly like what I want. However, I can't figure out how to play multiple different graphs at the same time.

Is this something that's supported?

Thanks!

charlieroberts commented 2 years ago

The easiest way is to just use add() and stick all the graphs you want to use in there. Or are you looking to have a different AudioWorklet for each graph?

WesleyAC commented 2 years ago

I'm trying to overlay multiple synthesized sounds that are triggered at different times. Having a different worklet for each graph seemed like the simplest way to go about that, but if there's something easier, I'd be happy to hear about it :)

raphaelbastide commented 2 years ago

I tried to play multiple worklets at the same time, I am wondering in it would be the right way to do it, because it behaves strangely: it appears some ugens get the priority, other doesn’t.

window.onload = function() {
  genish.export( window )
  utilities.createContext( 2048 )
  speed = add( .5, phasor( .25, 0, { min:0, max:17 }) )
  const march = seq( [11025, 1050, 200], [220,330,440,550,660,880,1010] )
  const june  = seq( [5512, 11025], [220,330,440,550], speed )
  const sun  = seq( [11025], [140, 0] )
  window.onclick = ()=> {
    utilities.playWorklet(mul( cycle( march ), .2) )
    utilities.playWorklet(mul( cycle( june ), .2) )
    utilities.playWorklet(mul( cycle( sun ), .2) ) // comment that one and march and june will play
  }
}
charlieroberts commented 2 years ago

better handling of generated worklet(s) would be great to add in; I'll try and take a look soon.