1function e(e,t){let n=e*e,r=n*e,i=.00833333333332249+n*(-.0001984126982985795+n*(27557313707070068e-22+n*(-2.5050760253406863e-8+n*158969099521155e-24)));return e-(n*(.5*t-r*i)-t-r*-.16666666666666632)}function t(e,t){let n=e*e,r=n*(.0416666666666666+n*(-.001388888888887411+n*(2480158728947673e-20+n*(-2.7557314351390663e-7+n*(2.087572321298175e-9+n*-11359647557788195e-27))))),i=.5*n,a=1-i;return a+(1-a-i+(n*r-e*t))}let n=0,r=0;function i(e){let t=Math.round(e*.6366197723675814),i=e-t*1.5707963267341256,a=t*6077100506303966e-26,o;return o=i-a,a=t*20222662487959506e-37-(i-o-a),n=o-a,r=o-n-a,t}function a(a){if(!Number.isFinite(a))return NaN;if(Math.abs(a)<.7853981633974483)return e(a,0);let o=i(a)&3;return o===0?e(n,r):o===1?t(n,r):o===2?-e(n,r):-t(n,r)}function o(a){if(!Number.isFinite(a))return NaN;if(Math.abs(a)<.7853981633974483)return t(a,0);let o=i(a)&3;return o===0?t(n,r):o===1?-e(n,r):o===2?-t(n,r):e(n,r)}function s(e,t){return Math.sqrt(e*e+t*t)}const c=6.283185307179586;function l(e){return e-c*Math.floor((e+Math.PI)/c)}var u=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:s}=this.cfg,[c,l,u,d]=[e[0],e[1],e[2],e[3]],f=c-l,p=o(f),m=a(f),h=t+n*m*m,g=(i*u-r*d*p)/(r*r*i*h),_=(r*(t+n)*d-i*n*u*p)/(r*i*i*n*h);return{w1:g,w2:_,T:.5*(u*g+d*_),V:(t+n)*s*r*(1-o(c))+n*s*i*(1-o(l))}}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:s,g:c}=this.cfg,l=e[0],u=e[1],d=e[2],f=e[3],p=l-u,m=o(p),h=a(p),g=n+r*h*h,_=(s*d-i*f*m)/(i*i*s*g),v=(i*(n+r)*f-s*r*d*m)/(i*s*s*r*g),y=d*f*h/(i*s*g),b=(s*s*r*d*d+i*i*(n+r)*f*f-2*i*s*r*d*f*m)*a(2*p)/(2*i*i*s*s*g*g),x=.5*(d*_+f*v),S=(n+r)*c*i*(1-o(l))+r*c*s*(1-o(u)),C=0;if(this.controlled){let e=.02*this.vTop,t=4/this.tau;C=(this.eTarget-(x+S))/(this.tau*(2*x+e)),C>t?C=t:C<-t&&(C=-t)}C-=this.damping,t[0]=_,t[1]=v,t[2]=-(n+r)*c*i*a(l)-y+b+C*d,t[3]=-r*c*s*a(u)+y-b+C*f}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:s}=this.cfg,c=Math.max(e,1e-6)*this.vTop,l=Math.min(Math.PI,3*Math.sqrt(c/(r*this.cfg.g*Math.min(i,s)))),u=0,d=0,f=0;for(let e=0;e<1e3&&(u=(2*t()-1)*l,d=(2*t()-1)*l,f=this.derived([u,d,0,0]).V,!(f<.9*c));e++)u=d=0,f=0;let p=c-f,m=t()*2*Math.PI,h=o(m),g=a(m),_=o(u-d),v=(n+r)*i*i,y=r*i*s*_,b=r*s*s,x=.5*(v*h*h+2*y*h*g+b*g*g),S=Math.sqrt(p/x),C=S*h,w=S*g;this.y[0]=u,this.y[1]=d,this.y[2]=v*C+y*w,this.y[3]=y*C+b*w,this.t=0}};function d(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 f(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 p(e,t,n){let r=e.y;if(!(t>0))return;let i=r[2],c=r[3],l=s(i,c);if(l>1e-9)i/=l,c/=l;else{let e=n()*2*Math.PI;i=o(e),c=a(e)}let u=e.derived(),d=i*u.w1+c*u.w2,f=e.derived([r[0],r[1],i,c]),p=i*f.w1+c*f.w2,m=(-d+Math.sqrt(Math.max(0,d*d+2*p*t)))/p;r[2]+=m*i,r[3]+=m*c}function m(e,t,n,r){let{l1:i,l2:c,m2:u}=e.cfg,d=e.y,f=i+c,p=Math.sqrt(2*e.vTop/u)+1e-9,m=a(d[0]),h=o(d[0]),g=a(d[1]),_=o(d[1]);switch(t){case`x2`:return(i*m+c*g)/f;case`y2`:return-(i*h+c*_)/f;case`vx2`:return(i*h*n+c*_*r)/p;case`vy2`:return(i*m*n+c*g*r)/p;case`x1`:return m;case`vx1`:return i*h*n/p;case`θ1`:return l(d[0])/Math.PI;case`θ2`:return l(d[1])/Math.PI;case`θ2−θ1`:return l(d[1]-d[0])/Math.PI;case`ω1`:return n*i/p;case`ω2`:return r*c/p;case`p1`:return d[2]/(p*(1+u)*i*i+1e-9);case`p2`:return d[3]/(p*u*c*c+1e-9);case`speed2`:return s(i*h*n+c*_*r,i*m*n+c*g*r)/p}}var h=class extends AudioWorkletProcessor{s=null;p=new u({m1:1,m2:1,l1:1,l2:1,g:1});rand=d(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){p(this.p,e,this.rand)}signal(e,t,n){return m(this.p,e,t,n)}process(e,t){let n=t[0],r=n[0],i=n[1]??n[0],a=this.s;if(!a)return!0;let o=r.length,s=this.p,c=f(s),l=2*Math.PI*a.pitch/c,u=l/sampleRate,d=Math.max(1,Math.ceil(u/.004)),p=u/d,m=a.ringTime>0?13.8156/(a.ringTime*l):0,h=1-2*Math.PI*a.dcCut/sampleRate,g=2*Math.PI/c;s.tau=Math.max(.05,a.follow*g);for(let e=0;e<o;e++){if(a.mode===`sustain`)this.phase=`sustaining`,s.controlled=!0,s.eTarget=a.energy*s.vTop,s.damping=0;else if(a.mode===`swell`){if(this.t<a.swellTime){s.controlled=!0;let e=this.t/Math.max(.01,a.swellTime);s.eTarget=(this.swellFrom+(a.energy-this.swellFrom)*e*e)*s.vTop,s.damping=0,this.phase=`swelling`}else s.controlled=!1,s.damping=m,this.phase=`ringing`}else s.controlled=!1,s.damping=m,this.phase=`ringing`;for(let e=0;e<d;e++)s.step(p);this.t+=1/sampleRate,a.restrike>0&&this.t>=a.restrike&&this.strike();let t=s.derived(),n=this.signal(a.left,t.w1,t.w2),o=a.right===a.left?n:this.signal(a.right,t.w1,t.w2),c=n-this.dcL.x+h*this.dcL.y;this.dcL.x=n,this.dcL.y=c;let l=o-this.dcR.x+h*this.dcR.y;if(this.dcR.x=o,this.dcR.y=l,n=Math.tanh(a.gain*c),o=Math.tanh(a.gain*l),r[e]=Number.isFinite(n)?n:0,i[e]=Number.isFinite(o)?o:0,Number.isFinite(s.y[0])||this.strike(),++this.sampleCount%2==0){let e=s.y,t=s.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+=o,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:s.energyNorm(),phase:this.phase,trail:e,k:l};this.port.postMessage(t,[e.buffer])}return currentTime,!0}};registerProcessor(`pendulum-voice`,h);