You are not recognized as the original poster of this topic.
let TAU=Math.PI*2,notes="C,Db,D,Eb,E,F,Gb,G,Ab,A,Bb,B".split(",").reduce((o,k,i)=>(o[k]=i,o),{}),noteHz=n=>Math.pow(2,(n-49)/12)*440,read=note=>{
if(note.includes("-"))return note.split("-").map(read);
let n=40;
while(note.startsWith("_")){n-=12;note=note.replace("_","");}
while(note.startsWith("^")){n+=12;note=note.replace("^","");}
return n+notes[note];
},chords=`\
__C-C-Eb-G-Ab-Bb //Cm7b6
__F-_Bb-C-Eb-G-Ab-^Db //Fm11b6
__Bb-C-Db-F-Ab-Bb-^C-^Eb //Bbm11
__Eb-C-Db-Eb-F-Ab-Bb-^C //Eb13sus4`.replace(/\/\/.+$/gm,"").trim().split(/\s+/gm).map(read);/*,tempo=40/60;return t=>{
let at=(t*tempo)%chords.length,
a=chords[floor(at)],
o=0;
for(let i=0;i<a.length;i++)
o+=sin(t*noteHz(a[i])*TAU)**3;
return o*.1
};*/
let sampleRate=8000,timer={bar:0,maxCount:2**5,count:0,wait:sampleRate/13,tick:0},voices=[];
class synth{
constructor(n){
this.duration=timer.wait+(timer.wait*7*Math.random());
this.t=0;
this.channel=+(Math.random()<.5);
this.freq=noteHz(n+.3)+3*((Math.random()*2)-1);
this.tm=1/sampleRate;
this.e=1+floor(Math.random()*10);this.sign=Math.random()<.5?-1:1;
}
process(){
let{t,tm,freq,duration,e,sign}=this,time=t*tm;
let o=(sin(time*freq*TAU)**e)*sign*(1-(t/duration))*min(t*.001,1);
this.t++;
return o;
}
}
return t=>{
with(timer){
if(tick>=wait){
tick%=wait; //could be decimal
count++;
for(let i=0;i<chords[bar].length;i++)voices.push(new synth(chords[bar][i]-.1),new synth(chords[bar][i]),new synth(chords[bar][i]+.1),new synth(chords[bar][i]-12),new synth(chords[bar][i]-24));
if(count>=maxCount){ //next bar
count=0;
bar=(bar+1)%chords.length;
}
}
tick++;
}
let o=[0,0];
for(let i=0;i<voices.length;i++){
let v=voices[i];
o[v.channel]+=v.process();
if(v.t>=v.duration){
voices.splice(i,1);i--;
}
}
return[o[0]*.15,o[1]*.15];
};