var e=class{cfg;y=/* @__PURE__ */ new Float64Array(4);t=0;eTarget=0;tau=2;controlled=!0;damping=0;k1=/* @__PURE__ */ new Float64Array(4);k2=/* @__PURE__ */ new Float64Array(4);k3=/* @__PURE__ */ new Float64Array(4);k4=/* @__PURE__ */ new Float64Array(4);tmp=/* @__PURE__ */ new Float64Array(4);constructor(e){this.cfg={...e}}get vTop(){let{m1:e,m2:t,l1:n,l2:r,g:i}=this.cfg;return 2*(e+t)*i*n+2*t*i*r}get p2Scale(){let{m2:e,l2:t}=this.cfg;return Math.sqrt(e*t*t*this.vTop)}derived(e=this.y){let{m1:t,m2:n,l1:r,l2:i,g:a}=this.cfg,[o,s,c,l]=[e[0],e[1],e[2],e[3]],u=o-s,d=Math.cos(u),f=Math.sin(u),p=t+n*f*f,m=(i*c-r*l*d)/(r*r*i*p),h=(r*(t+n)*l-i*n*c*d)/(r*i*i*n*p);return{w1:m,w2:h,T:.5*(c*m+l*h),V:(t+n)*a*r*(1-Math.cos(o))+n*a*i*(1-Math.cos(s))}}energy(e=this.y){let t=this.derived(e);return t.T+t.V}energyNorm(){return this.energy()/this.vTop}deriv(e,t){let{m1:n,m2:r,l1:i,l2:a,g:o}=this.cfg,s=e[0],c=e[1],l=e[2],u=e[3],d=s-c,f=Math.cos(d),p=Math.sin(d),m=n+r*p*p,h=(a*l-i*u*f)/(i*i*a*m),g=(i*(n+r)*u-a*r*l*f)/(i*a*a*r*m),_=l*u*p/(i*a*m),v=(a*a*r*l*l+i*i*(n+r)*u*u-2*i*a*r*l*u*f)*Math.sin(2*d)/(2*i*i*a*a*m*m),y=.5*(l*h+u*g),b=(n+r)*o*i*(1-Math.cos(s))+r*o*a*(1-Math.cos(c)),x=0;if(this.controlled){let e=.02*this.vTop,t=4/this.tau;x=(this.eTarget-(y+b))/(this.tau*(2*y+e)),x>t?x=t:x<-t&&(x=-t)}x-=this.damping,t[0]=h,t[1]=g,t[2]=-(n+r)*o*i*Math.sin(s)-_+v+x*l,t[3]=-r*o*a*Math.sin(c)+_-v+x*u}step(e){let{y:t,k1:n,k2:r,k3:i,k4:a,tmp:o}=this;this.deriv(t,n);for(let r=0;r<4;r++)o[r]=t[r]+.5*e*n[r];this.deriv(o,r);for(let n=0;n<4;n++)o[n]=t[n]+.5*e*r[n];this.deriv(o,i);for(let n=0;n<4;n++)o[n]=t[n]+e*i[n];this.deriv(o,a);for(let o=0;o<4;o++)t[o]+=e/6*(n[o]+2*r[o]+2*i[o]+a[o]);this.t+=e}randomize(e,t){let{m1:n,m2:r,l1:i,l2:a}=this.cfg,o=Math.max(e,1e-6)*this.vTop,s=Math.min(Math.PI,3*Math.sqrt(o/(r*this.cfg.g*Math.min(i,a)))),c=0,l=0,u=0;for(let e=0;e<1e3&&(c=(2*t()-1)*s,l=(2*t()-1)*s,u=this.derived([c,l,0,0]).V,!(u<.9*o));e++)c=l=0,u=0;let d=o-u,f=t()*2*Math.PI,p=Math.cos(f),m=Math.sin(f),h=Math.cos(c-l),g=(n+r)*i*i,_=r*i*a*h,v=r*a*a,y=.5*(g*p*p+2*_*p*m+v*m*m),b=Math.sqrt(d/y),x=b*p,S=b*m;this.y[0]=c,this.y[1]=l,this.y[2]=g*x+_*S,this.y[3]=_*x+v*S,this.t=0}};function t(e){let t=e>>>0;return()=>{t=t+0x6d2b79f5>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function n(e){let{m1:t,m2:n,l1:r,l2:i,g:a}=e.cfg,o=(t+n)*r*r,s=n*r*i,c=n*i*i,l=(t+n)*a*r,u=n*a*i,d=o*c-s*s,f=(l*c+u*o)/d,p=l*u/d,m=(f-Math.sqrt(Math.max(0,f*f-4*p)))/2;return Math.sqrt(Math.max(m,1e-9))}function r(e,t,n){let r=e.y;if(!(t>0))return;let i=r[2],a=r[3],o=Math.hypot(i,a);if(o>1e-9)i/=o,a/=o;else{let e=n()*2*Math.PI;i=Math.cos(e),a=Math.sin(e)}let s=e.derived(),c=i*s.w1+a*s.w2,l=e.derived([r[0],r[1],i,a]),u=i*l.w1+a*l.w2,d=(-c+Math.sqrt(Math.max(0,c*c+2*u*t)))/u;r[2]+=d*i,r[3]+=d*a}function i(e,t,n,r){let{l1:i,l2:a,m2:o}=e.cfg,s=e.y,c=i+a,l=Math.sqrt(2*e.vTop/o)+1e-9,u=Math.sin(s[0]),d=Math.cos(s[0]),f=Math.sin(s[1]),p=Math.cos(s[1]);switch(t){case`x2`:return(i*u+a*f)/c;case`y2`:return-(i*d+a*p)/c;case`vx2`:return(i*d*n+a*p*r)/l;case`vy2`:return(i*u*n+a*f*r)/l;case`x1`:return u;case`vx1`:return i*d*n/l;case`θ1`:return Math.atan2(u,d)/Math.PI;case`θ2`:return Math.atan2(f,p)/Math.PI;case`θ2−θ1`:return Math.atan2(Math.sin(s[1]-s[0]),Math.cos(s[1]-s[0]))/Math.PI;case`ω1`:return n*i/l;case`ω2`:return r*a/l;case`p1`:return s[2]/(l*(1+o)*i*i+1e-9);case`p2`:return s[3]/(l*o*a*a+1e-9);case`speed2`:return Math.hypot(i*d*n+a*p*r,i*u*n+a*f*r)/l}}var a=class extends AudioWorkletProcessor{s=null;p=new e({m1:1,m2:1,l1:1,l2:1,g:1});rand=t(12345);t=0;swellFrom=0;phase=`silent`;dcL={x:0,y:0};dcR={x:0,y:0};trail=/* @__PURE__ */ new Float32Array(1536);trailW=0;sinceSnap=0;sampleCount=0;constructor(){super(),this.p.controlled=!1,this.port.onmessage=e=>{if(e.data.type===`settings`){let t=!this.s;this.s=e.data.s,this.p.cfg.m2=this.s.massRatio,this.p.cfg.l2=this.s.lengthRatio,t&&(this.p.y.fill(0),this.strike())}else e.data.type===`strike`&&this.strike()}}strike(){let e=this.s;e&&(this.t=0,e.mode===`swell`?(this.swellFrom=this.p.energyNorm(),this.phase=`swelling`,this.swellFrom<1e-6&&this.kick(1e-4*this.p.vTop)):this.kick(e.strikeEnergy*this.p.vTop))}kick(e){r(this.p,e,this.rand)}signal(e,t,n){return i(this.p,e,t,n)}process(e,t){let r=t[0],i=r[0],a=r[1]??r[0],o=this.s;if(!o)return!0;let s=i.length,c=this.p,l=n(c),u=2*Math.PI*o.pitch/l,d=u/sampleRate,f=Math.max(1,Math.ceil(d/.004)),p=d/f,m=o.ringTime>0?13.8156/(o.ringTime*u):0,h=1-2*Math.PI*o.dcCut/sampleRate,g=2*Math.PI/l;c.tau=Math.max(.05,o.follow*g);for(let e=0;e0&&this.t>=o.restrike&&this.strike();let t=c.derived(),n=this.signal(o.left,t.w1,t.w2),r=o.right===o.left?n:this.signal(o.right,t.w1,t.w2),s=n-this.dcL.x+h*this.dcL.y;this.dcL.x=n,this.dcL.y=s;let l=r-this.dcR.x+h*this.dcR.y;if(this.dcR.x=r,this.dcR.y=l,n=Math.tanh(o.gain*s),r=Math.tanh(o.gain*l),i[e]=Number.isFinite(n)?n:0,a[e]=Number.isFinite(r)?r:0,Number.isFinite(c.y[0])||this.strike(),++this.sampleCount%2==0){let e=c.y,t=c.cfg,n=4*this.trailW,r=t.l1*Math.sin(e[0]),i=t.l1*Math.cos(e[0]);this.trail[n]=r,this.trail[n+1]=i,this.trail[n+2]=r+t.l2*Math.sin(e[1]),this.trail[n+3]=i+t.l2*Math.cos(e[1]),this.trailW=(this.trailW+1)%384}}if(this.sinceSnap+=s,this.sinceSnap>=sampleRate/60){this.sinceSnap=0;let e=/* @__PURE__ */ new Float32Array(1536);e.set(this.trail.subarray(4*this.trailW)),e.set(this.trail.subarray(0,4*this.trailW),4*(384-this.trailW));let t={type:`snap`,energy:c.energyNorm(),phase:this.phase,trail:e,k:u};this.port.postMessage(t,[e.buffer])}return currentTime,!0}};registerProcessor(`pendulum-voice`,a);