function mix(a, b, x) { return a+x*(b-a) } class testS { constructor(opt) { this.t = 0; } process(note, env, tick, opt) { this.t += midi_to_hz(note) * ditty.dt; var r = Math.random()*Math.random(); var t = this.t*10; t *= (Math.floor(tick*r*3)*(4/3)); return Math.sin(t)*env.value; } } var test = synth.def(testS, {attack: 0.001, release: 1, duration: 1, freq: 65}); function hash(x) { x *= 999; return Math.sin(x*345.34+Math.sin(5345.345*x+345.3453*Math.sin(534.3634*x))*634.6345); } function noise(x) { return mix(hash(Math.floor(x)), hash(Math.floor(x)+1), x%1); } class baseS { constructor(opt) { this.t = 0; } process(note, env, tick, opt) { var m = 5*(Math.floor(tick*4)%Math.floor( hash(Math.floor(tick/2+10))*5+2 ))+(hash(Math.floor(tick/5))>0.5); var s = Math.exp(-(tick%1))*noise(tick*500*m)*Math.exp(-(tick%5)*0.5); return s; } } var base = synth.def(baseS, {attack: 0.001, release: 1, duration: 100, freq: 65}); base.play(); var dur = 2.0; var slp = 1.5; var k = 0; var m = 0; loop( () => { test.play(c4, { attack: 0.01, release: 0.5, duration: dur }); sleep(slp); if (m != 1) { test.play(d4, { attack: 0.01, release: 0.5, duration: dur }); sleep(slp); test.play(e4, { attack: 0.01, release: 0.5, duration: dur }); sleep(slp); } else { m = 0; test.play(e4, { attack: 0.01, release: 1.0, duration: dur*2+Math.random() }); sleep(slp); } test.play(g4, { attack: 0.01, release: 0.5, duration: dur }); sleep(slp*0.5); if (k++ == 1) { k = 0; m += 1; test.play(d4, { attack: 0.01, release: 1, duration: dur*3.0 }); sleep(slp*2.0); } }, { name: 'test' }); loop( () => { base.play(); sleep(100000); }, { name: 'test1' });