You are not recognized as the original poster of this topic.
let easeFunctions=[(x,a)=>x>=a?1:0,(x,a)=>Math.pow(x,1+a),(x,a)=>Math.pow(x,1/(1+a)),(x,a)=>((Math.pow(Math.abs(2*(x-.5)),1+2*a)*Math.sign(x-.5))+1)/2,(x,a)=>((Math.pow(Math.abs(2*(x-.5)),1/(1+a))*Math.sign(x-.5))+1)/2,(x,a)=>Math.min(x/(1-a),Math.max(.5,1-((1-x)/(1-a)))),x=>.5+Math.sin(Math.PI*(x-.5))*.5,x=>(3*x*x)-(2*x*x*x),(x,a)=>a===0?x:(Math.exp(a*x)-1)/(Math.exp(a)-1),(x,a)=>x+a*x*(1-x),(x,a)=>{if(a===0)return x;a=(1/(1-a))-1;let s=a*(x-.5),mn=Math.atan(-a*.5),mx=-mn;return(Math.atan(s)-mn)/(mx-mn);},(x,a)=>a===0?x:Math.floor(x/a)*a],
mod=(n,m)=>(n%m+m)%m,oscify=(f,x,...p)=>2*f(1-2*Math.abs(.5-mod(x,1)),...p)-1,
noteHz=n=>440*Math.pow(2,n/12),TAU=Math.PI*2;
let notes=[ //(n)ote, (s)tart, (d)uration…
/*{n:0,s:0,d:.3},{n:-3,s:.2,d:.5},
{n:2,s:2,d:1},{n:5,s:2.4,d:1},
{n:2,s:4.5,d:1},{n:7,s:5.5,d:1},
{n:-15,s:0,d:2},{n:-5,s:0,d:2},
{n:-10,s:2,d:2},{n:-3,s:2,d:2},
{n:-14,s:4,d:2},{n:-3,s:4,d:2},
{n:-12,s:6,d:2},{n:-5,s:6,d:2}*/
//console.log(JSON.stringify([...notes,...(notes.map(x=>({n:x.n-2,s:x.s+4,d:x.d})))]));
{n:-20,s:0,d:4},{n:-17,s:.5,d:4},{n:-13,s:1,d:4},{n:-10,s:1.5,d:4},{n:-6,s:0,d:4},{n:-5,s:0,d:4},{n:-3,s:0,d:4},
{n:-22,s:4,d:4},{n:-19,s:4,d:4},{n:-15,s:4,d:4},{n:-12,s:4,d:4},{n:-8,s:4,d:4},{n:-7,s:4.5,d:4},{n:-5,s:5,d:4},
{n:28,s:0,d:9,v:.1},{n:14,s:0,d:9,v:.2},{n:11,s:3.5,d:2,v:.4},{n:16,s:7.5,d:.5,v:1.4}
],humanizeNote=({n,s,d,...rest})=>({n:n+(Math.random()-.5)*.4,s:s+(Math.random()-.5)*.05,d:d+Math.random()*.05,...rest});
notes=notes.flatMap(n=>[humanizeNote(n),humanizeNote(n),humanizeNote(n)]);
notes=notes.map(({...keys})=>({...keys,p:(Math.random()*2)-1}));
return function DSP(t){
let output=[0,0];
t=mod(t*1.05,8);
for(const note of notes){
let start=note.s,dur=note.d,end=start+dur;
if(t>=start&&t<end){
let localT=t-start,freq=noteHz(note.n),
attack=.01,release=1,env=Math.min(localT/attack,1,(dur-localT)/release);
//output+=Math.sin(TAU*freq*localT)*env;
//output-=oscify(easeFunctions[1],freq*localT,(sin(localT)+1)*.5)*env;
let osc=oscify(easeFunctions[mod(floor(note.n+localT*4),easeFunctions.length)],freq*localT,(sin(localT*3+note.n+t*.1)+1)*.5)*env*("v"in note?note.v:1);
output[0]-=osc*(1-note.p);output[1]-=osc*note.p;
}
}
return[Math.tanh(output[0]*.1),Math.tanh(output[1]*.1)];
};