class Imprint { constructor(frequancy, absorbsion, weight=1) { this.x = 0; this.v = 0; this.a = 0; this.weight= weight; this.frequancy = frequancy; this.absorbsion = absorbsion; } sample(s) { this.v *= this.absorbsion; this.v += s;//Math.max(Math.min(s*50, 1), -1); this.v -= this.x; this.x += this.v*this.frequancy; return this.x*this.weight; } } let reverb = filter.def(class { constructor(options) { this.mem = []; this.max =0; for (let i = 0; i < 256; i++) { let res = Math.random()*options.frequancy/44000; let weight = 1/res; this.max += weight; this.mem.push(new Imprint(res,1-options.decay, weight)); } } process(input) { let s = input[0] // actual sound let out = 0; for (let i of this.mem) { out += i.sample(s); } out /= this.max; return [out, out]; } }) 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' }).connect(reverb.create({frequancy:3000, decay:0.001})); loop( () => { base.play(); sleep(100000); }, { name: 'test1' }).connect(reverb.create({frequancy:2000, decay:0.0001}));