// Uses up a lot of chars and isn't /super/ readable, but a major timesaver when creating
// Particularly the NaN handing
m = mix = (x, vol = 1, dist = 0) => ((x * vol * (1 + dist)) % (256 * vol))||0,
// Array Creators || MT2023 and Greaserpirate
bfc=(SIZE)=>new Float32Array(SIZE),
bfc2=(A,B)=>Array(A).fill(B).flat(9),
// Buffers
t||(
F=bfc(4e6),
d_fx=[],
alp_fx=[],
g_fx=bfc2(1572864,0)
),
// Iterators
I=0,d_fxi=0,alp_fxi=0,g_fxi=0,
// Time Units
t2=t,dt=t,
// Filters || feeshbread
lpf=lowPass=function(a,c){
lpf_i=I++,
F[lpf_i]=a*c+F[lpf_i]*(1-c)
return F[lpf_i]
},
hpf=highPass=(a,c)=>a-lpf(a,c),
bpf=bandPassFilter=(a,hc, lc)=>hpf(lpf(a,lc), hc),
nf=notchFilter=(a,lc, hc)=>(hpf(a, hc)+lpf(a,lc))/1.75,
lbf=lowBoostFilter=(a,c,v)=>a+lpf(a,c)*v,
hbf=highBoostFilter=(a,c,v)=>a+hpf(a,c)*v,
bbf=(a,hc,lc,v)=>a+bpf(a,hc,lc)*v,
// Limiter || MT2023
limiter = function(a, threshold, c) {
let rmsIdx = I++;
mem[rmsIdx] = (1 - c) * (F[rmsIdx] || 0) + c * (x * x);
let rms = sqrt(F[rmsIdx]);
let gain = 1.0;
if (rms > threshold) {
gain = threshold / rms;
}
let gIdx = I++;
F[gIdx] = (1 - c) * (F[gIdx] || 1) + c * gain;
return a * F[gIdx];
},
// Asyncompressor || feeshbread
alp=asyncLowPass=(a,cu,cd)=>(
alpf_fxii=alp_fxi++,
alp_fx[alpf_fxii]||=0,
alp_r=alp_fx[alpf_fxii],
alp_fx[alpf_fxii]+=(a-alp_r)-(alp_r<a?cu:cd)
),
cmp=compressor=(a, th, ra, at, rl, sc=a)=>(
a/(alp(max(abs(sc)-th,0), at, rl)/th*ra+1)
),
// Downsample || Greaserpirate
this.dsp ??= downsample = (x,res) => (
x = g_fx[g_fxi] = t2 % res ? g_fx[g_fxi] : x,
x
),
// Self-explanatoy
t?0:lpr_fx=[],
lpr_fxi=0,
lpr=(a,c,r)=>(
c+=1e-14,
lpr_fx[++lpr_fxi]??=[0,0],
lpr_fx[lpr_fxi][0]+=lpr_fx[lpr_fxi][1]+=(
a-lpr_fx[lpr_fxi][0]-lpr_fx[lpr_fxi][1]*(1-sqrt(r)**.7)/c)*c
),
hpr=(a,c,r)=>a-lpr(a,c,r),
bpr=(a,h,l,r)=>hpr(lpr(a,l,r),h,r),
nr=(a,l,h,r)=>(lpr(a,l,r)+hpr(a,h,r))/1.75,
lbr=(a,c,r,v)=>a+lpr(a,c,r)*v,
hbr=(a,c,r,v)=>a+hpr(a,c,r)*v,
bbr=(a,h,l,r,v)=>a+bpr(a,h,l,r)*v,
del=(i,d,f,c=0)=>(d_fx[++d_fxi]??=Array(d).fill(0),out=i+d_fx[d_fxi][(t+c|0)%d],d_fx[d_fxi][t%d]=out*f,out),
rev=(m,a,s,v,f,d,w,E=x=>x)=>{var out=0;for(let i=0;i<a;i++){out+=E((del(m,s+(v*i),f,i*1568+12e3+(cos(t/32e3*(i/70+.8))*96))-m)/a)};return m*d+(out*w);},bt=x=>(x&255)/128-1,pwm=(X,Y)=>bt(((X/2&127)+Y)&128),
gain=(dB)=>10**(dB/20),
A4=392,
sR=48e3,
BPM=92,
sPB=32768,
ts=abs(t*BPM/(60*sR/sPB)),
q=(30*sR)/(BPM*2/3),
bar=ts>>16,
p=((ar=[[0,4,7,11],[-1,2,6,9],[-3,0,4,7],[-5,-1,2,6]])[3&ts>>18])[3&ts>>15],
a=(t/sR*128)*A4*2**(p/12),
organ=x=>tanh((sin(x*PI/512)+sin(x*PI/256)+sin(x*PI/128)+sin(x*PI/64)+sin(x*PI/32))/5),
aud=j=>m(organ(a*j)*(1-(ts%32768/32768))**.75,.3)+m((ts>1048576)*bpr(pwm((t/sR*128)*A4*j*2**(ar[3&ts>>18][t%4]/12),abs(sin(ts*PI/524288)**2*128)),.01,.2*abs(sin(ts*PI/524288)**2),.3),.3)+m(lpf(lpf((t/sR*128*j*A4/256*2**([0,-1,-3,-5][3&ts>>18]/12)&1)*(ts>>15&1),.375),min(1,ts/1048576)),.16),
ms=(i,j)=>
(mix=tanh(dsp(rev(aud(j),24,i?900:1000,i?750:850,.94,.35,15,x=>bpr(x,.1,.01,.3))+m(tan(sin(8*j*cbrt(ts%131072)**.75)),i?.5/4:.55/4),(bar<32||bar>96?8:4)))*128/2,
mix=(tanh(mix/255-.1))*255, // subtle asymetric saturation
mix=hbf(lbf(mix,.001,11),.25,2), // low & high boost
mix=(tanh(hpf(mix, .001)/128*1.4)+1)*127, // cut DC offset + soft cliping
floor(((mix&255)/128-1)*31)/31
),
[ms(0,.995),ms(1,1.005)]