const e=(e,t)=>e[t],t=(e,t)=>e[t],n=e=>e.geometry===`membrane`||e.geometry===`plate`||e.geometry===`disc`,r=(...e)=>t=>e.includes(t.geometry),i=(...e)=>t=>e.includes(t.exciter),a=[`bow`,`reed`,`selfosc`,`noise`],o=[[`off`,`Off`],[`pitch`,`Pitch`],[`amp`,`Amplitude`],[`position`,`Excite position`],[`pickup`,`Pickup position`],[`tension`,`Tension coupling`],[`cascade`,`Cascade coupling`],[`damping`,`Damping`],[`feedback`,`Feedback gain`],[`exciter`,`Exciter intensity`]],s=[[`sine`,`Sine`],[`tri`,`Triangle`],[`saw`,`Saw`],[`square`,`Square`],[`sh`,`Sample & hold`],[`smooth`,`Smooth random`]];function c(e){let t=t=>t[`lfo${e}Target`]!==`off`;return[{kind:`enum`,id:`lfo${e}Target`,label:`LFO ${e} →`,group:`Modulation`,options:o,def:`off`},{kind:`enum`,id:`lfo${e}Shape`,label:`Shape`,group:`Modulation`,options:s,def:`sine`,show:t},{kind:`num`,id:`lfo${e}Rate`,label:`Rate`,group:`Modulation`,min:.01,max:40,def:1,scale:`log`,unit:`Hz`,show:t},{kind:`num`,id:`lfo${e}Depth`,label:`Depth`,group:`Modulation`,min:0,max:1,def:.3,scale:`pow2`,show:t}]}const l=[{kind:`enum`,id:`geometry`,label:`Geometry`,group:`Body`,model:!0,def:`string`,options:[[`string`,`String`],[`bar`,`Bar (free–free)`],[`tube_co`,`Tube (closed–open)`],[`tube_oo`,`Tube (open–open)`],[`membrane`,`Membrane (circular)`],[`plate`,`Plate (rectangular)`],[`disc`,`Disc (cymbal / gong)`],[`ring`,`Bell / ring`],[`free`,`Free spectrum (kᵖ)`]],hint:`Sets the mode frequency ratios and mode shapes`},{kind:`num`,id:`modes`,label:`Modes`,group:`Body`,min:4,max:256,def:64,int:!0,model:!0,scale:`log`},{kind:`num`,id:`aspect`,label:`Aspect ratio`,group:`Body`,min:.2,max:1,def:.71,model:!0,show:r(`plate`)},{kind:`num`,id:`powerExp`,label:`Exponent p`,group:`Body`,min:.3,max:3,def:1.5,model:!0,show:r(`free`)},{kind:`num`,id:`discExp`,label:`Chladni exponent`,group:`Body`,min:1,max:2.5,def:2,model:!0,show:r(`disc`),hint:`f ∝ (m + 2n)^p: 2 = flat plate; lower for domed cymbals and gongs`},{kind:`num`,id:`stretch`,label:`Stretch`,group:`Body`,min:.5,max:2,def:1,model:!0,digits:3,hint:`ratio → ratio^s (bar with s≈1.368 gives the 1:4:10 marimba tuning)`},{kind:`num`,id:`inharm`,label:`Stiffness B`,group:`Body`,min:0,max:.05,def:0,scale:`pow2`,model:!0,digits:5,hint:`ratio·√(1+B·ratio²): piano-like stretched partials`},{kind:`num`,id:`harmonize`,label:`Harmonize`,group:`Body`,min:0,max:1,def:0,model:!0,hint:`pull partials toward integer multiples`},{kind:`num`,id:`jitter`,label:`Detune jitter`,group:`Body`,min:0,max:200,def:0,scale:`pow2`,unit:`¢`,model:!0},{kind:`num`,id:`seed`,label:`Seed`,group:`Body`,min:1,max:999,def:1,int:!0,model:!0,hint:`random detune, coupling topology and radiation`},{kind:`num`,id:`t60`,label:`Decay T60`,group:`Damping`,min:.05,max:60,def:4,scale:`log`,unit:`s`},{kind:`num`,id:`hfDamp`,label:`HF damping`,group:`Damping`,min:0,max:100,def:2,scale:`pow2`,unit:`/s@1k`,hint:`extra decay rate σ = c·(f/1kHz)²`},{kind:`num`,id:`damper`,label:`Damper T60`,group:`Damping`,min:.02,max:20,def:.3,scale:`log`,unit:`s`,hint:`applied on key release; max = no damper`},{kind:`num`,id:`tension`,label:`Tension modulation`,group:`Nonlinear`,min:0,max:2,def:0,scale:`pow2`,digits:3,hint:`amplitude-dependent pitch (glides)`},{kind:`num`,id:`cascade`,label:`Cascade coupling`,group:`Nonlinear`,min:0,max:20,def:0,scale:`pow2`,digits:3,hint:`random quartic coupling: energy spreads across modes (gong/cymbal shimmer)`},{kind:`num`,id:`curvature`,label:`Curvature (3-wave)`,group:`Nonlinear`,min:0,max:3,def:0,scale:`pow2`,digits:3,hint:`quadratic forces: sum/difference tones, crashes`},{kind:`num`,id:`terms`,label:`Coupling terms`,group:`Nonlinear`,min:1,max:16,def:6,int:!0,model:!0},{kind:`num`,id:`nlModes`,label:`Coupled modes`,group:`Nonlinear`,min:4,max:128,def:48,int:!0,model:!0,scale:`log`},{kind:`num`,id:`glide`,label:`Pitch glide`,group:`Nonlinear`,min:-12,max:12,def:0,unit:`st`,hint:`pitch offset while loud, relaxing as the note decays: + falls (like tension), − rises (Chinese opera gong)`},{kind:`num`,id:`crossTension`,label:`Cross-note tension`,group:`Nonlinear`,min:0,max:2,def:0,scale:`pow2`,digits:3,hint:`notes share one tension: they bend each other`},{kind:`num`,id:`crossLink`,label:`Cross-note link`,group:`Nonlinear`,min:0,max:2,def:0,scale:`pow2`,digits:3,hint:`sympathetic coupling + intermodulation between notes`},{kind:`num`,id:`buzz`,label:`Barrier stiffness`,group:`Collision`,min:0,max:1,def:0,scale:`pow2`,digits:3,hint:`sitar bridge, snare wires, rattles`},{kind:`num`,id:`buzzGap`,label:`Gap`,group:`Collision`,min:0,max:2,def:.2,digits:3,show:e=>e.buzz>0},{kind:`num`,id:`buzzPos`,label:`Position`,group:`Collision`,min:0,max:1,def:.02,digits:3,show:e=>e.buzz>0},{kind:`num`,id:`buzzPosY`,label:`Position Y`,group:`Collision`,min:0,max:1,def:.5,show:e=>e.buzz>0&&n(e)},{kind:`enum`,id:`buzzSides`,label:`Barrier`,group:`Collision`,options:[[`one`,`One-sided (bridge)`],[`two`,`Two-sided (rattle)`]],def:`one`,show:e=>e.buzz>0},{kind:`enum`,id:`exciter`,label:`Key exciter`,group:`Exciter`,def:`strike`,options:[[`strike`,`Strike (hammer / mallet)`],[`pluck`,`Pluck`],[`impulse`,`Impulse`],[`bow`,`Bow`],[`reed`,`Reed / blow`],[`selfosc`,`Self-oscillator`],[`noise`,`Noise`]]},{kind:`num`,id:`strength`,label:`Strength`,group:`Exciter`,min:0,max:6,def:1,scale:`pow2`,hint:`>1 pushes the body into its nonlinear regime`},{kind:`num`,id:`exPos`,label:`Position`,group:`Exciter`,min:0,max:1,def:.13,digits:3},{kind:`num`,id:`exPosY`,label:`Position Y`,group:`Exciter`,min:0,max:1,def:.37,show:n},{kind:`num`,id:`exWidth`,label:`Contact width`,group:`Exciter`,min:0,max:1,def:.05,scale:`pow2`},{kind:`num`,id:`hammerMass`,label:`Hammer mass`,group:`Exciter`,min:.005,max:5,def:.1,scale:`log`,digits:3,show:i(`strike`)},{kind:`num`,id:`hardness`,label:`Contact time`,group:`Exciter`,min:.05,max:20,def:1,scale:`log`,unit:`ms`,show:i(`strike`,`impulse`)},{kind:`num`,id:`feltExp`,label:`Felt exponent`,group:`Exciter`,min:1,max:4,def:2.5,show:i(`strike`)},{kind:`num`,id:`bowForce`,label:`Bow force`,group:`Exciter`,min:0,max:4,def:1,scale:`pow2`,show:i(`bow`)},{kind:`num`,id:`bowSpeed`,label:`Bow speed`,group:`Exciter`,min:0,max:2,def:.4,scale:`pow2`,show:i(`bow`),hint:`scaled by key velocity: sets the loudness`},{kind:`num`,id:`bowNoise`,label:`Bow noise`,group:`Exciter`,min:0,max:1,def:0,scale:`pow2`,show:i(`bow`),hint:`random bow-force fluctuation: rosin and hair noise`},{kind:`num`,id:`reedPressure`,label:`Mouth pressure`,group:`Exciter`,min:0,max:1.5,def:.6,show:i(`reed`)},{kind:`num`,id:`reedGain`,label:`Reed opening`,group:`Exciter`,min:0,max:2,def:.5,show:i(`reed`)},{kind:`num`,id:`breath`,label:`Breath noise`,group:`Exciter`,min:0,max:1,def:.05,scale:`pow2`,show:i(`reed`)},{kind:`num`,id:`selfGain`,label:`Negative damping`,group:`Exciter`,min:0,max:4,def:.5,scale:`pow2`,show:i(`selfosc`)},{kind:`num`,id:`selfSat`,label:`Saturation level`,group:`Exciter`,min:.02,max:4,def:.5,scale:`log`,show:i(`selfosc`)},{kind:`num`,id:`noiseLevel`,label:`Noise level`,group:`Exciter`,min:0,max:4,def:1,scale:`pow2`,show:i(`noise`)},{kind:`num`,id:`noiseColor`,label:`Noise cutoff`,group:`Exciter`,min:50,max:16e3,def:3e3,scale:`log`,unit:`Hz`,show:i(`noise`,`reed`,`bow`)},{kind:`num`,id:`attack`,label:`Attack`,group:`Exciter`,min:1,max:3e3,def:40,scale:`log`,unit:`ms`,show:i(...a)},{kind:`num`,id:`release`,label:`Release`,group:`Exciter`,min:5,max:5e3,def:150,scale:`log`,unit:`ms`,show:i(...a)},{kind:`num`,id:`fbGain`,label:`Feedback gain`,group:`Feedback`,min:0,max:8,def:0,scale:`pow2`,hint:`output → delay → band-pass → saturate → back into the body (while a key is held)`},{kind:`num`,id:`fbDelay`,label:`Delay`,group:`Feedback`,min:.05,max:600,def:5,scale:`log`,unit:`ms`,show:e=>e.fbGain>0},{kind:`num`,id:`fbFreq`,label:`Band centre`,group:`Feedback`,min:30,max:12e3,def:800,scale:`log`,unit:`Hz`,show:e=>e.fbGain>0},{kind:`num`,id:`fbQ`,label:`Band Q`,group:`Feedback`,min:.3,max:30,def:1.5,scale:`log`,show:e=>e.fbGain>0},{kind:`num`,id:`fbSat`,label:`Saturation`,group:`Feedback`,min:.01,max:4,def:.4,scale:`log`,show:e=>e.fbGain>0},...c(1),...c(2),{kind:`num`,id:`vibDepth`,label:`Vibrato depth`,group:`Modulation`,min:0,max:100,def:0,scale:`pow2`,unit:`¢`,hint:`per-note vibrato, each note with its own phase and rate`},{kind:`num`,id:`vibRate`,label:`Vibrato rate`,group:`Modulation`,min:1,max:12,def:5.5,unit:`Hz`,show:e=>e.vibDepth>0},{kind:`num`,id:`vibDelay`,label:`Vibrato onset`,group:`Modulation`,min:0,max:2e3,def:300,unit:`ms`,show:e=>e.vibDepth>0,hint:`vibrato fades in after the note starts`},{kind:`num`,id:`bendRange`,label:`Pitch-bend range`,group:`Modulation`,min:0,max:24,def:2,int:!0,unit:`st`},{kind:`enum`,id:`soundbox`,label:`Soundbox`,group:`Soundbox`,def:`off`,options:[[`off`,`Off`],[`violin`,`Violin`],[`viola`,`Viola`],[`cello`,`Cello`],[`bass`,`Double bass`],[`guitar`,`Guitar`]],hint:`fixed resonances that every note passes through (they don't transpose)`},{kind:`num`,id:`boxSize`,label:`Size`,group:`Soundbox`,min:.4,max:3,def:1,scale:`log`,digits:3,show:e=>e.soundbox!==`off`,hint:`>1 lowers every resonance`},{kind:`num`,id:`boxDamp`,label:`Damping`,group:`Soundbox`,min:.3,max:4,def:1,scale:`log`,show:e=>e.soundbox!==`off`,hint:`scales every resonance's bandwidth`},{kind:`num`,id:`boxMix`,label:`Mix`,group:`Soundbox`,min:0,max:1,def:1,show:e=>e.soundbox!==`off`},{kind:`num`,id:`pickup`,label:`Pickup position`,group:`Output`,min:0,max:1,def:.77,digits:3},{kind:`num`,id:`pickupY`,label:`Pickup Y`,group:`Output`,min:0,max:1,def:.61,show:n},{kind:`num`,id:`width`,label:`Stereo width`,group:`Output`,min:0,max:1,def:.3,hint:`right pickup is offset from the left one`},{kind:`num`,id:`spread`,label:`Whole-body radiation`,group:`Output`,min:0,max:1,def:.2,hint:`0 = point pickup, 1 = every mode radiates equally`},{kind:`num`,id:`tilt`,label:`Spectral tilt`,group:`Output`,min:-12,max:12,def:0,unit:`dB/oct`},{kind:`num`,id:`level`,label:`Level`,group:`Output`,min:-24,max:36,def:0,unit:`dB`,hint:`instrument level (saved with presets; Volume is not)`},{kind:`num`,id:`voices`,label:`Max notes`,group:`Output`,min:1,max:16,def:8,int:!0},{kind:`num`,id:`drive`,label:`Saturation`,group:`Output`,min:0,max:1,def:0},{kind:`num`,id:`delayMix`,label:`Delay mix`,group:`Output`,min:0,max:1,def:0},{kind:`num`,id:`delayTime`,label:`Delay time`,group:`Output`,min:10,max:1500,def:350,scale:`log`,unit:`ms`,show:e=>e.delayMix>0},{kind:`num`,id:`delayFb`,label:`Delay feedback`,group:`Output`,min:0,max:.95,def:.35,show:e=>e.delayMix>0},{kind:`num`,id:`reverbMix`,label:`Reverb mix`,group:`Output`,min:0,max:1,def:.15},{kind:`num`,id:`reverbSize`,label:`Reverb time`,group:`Output`,min:.2,max:12,def:2.5,scale:`log`,unit:`s`,show:e=>e.reverbMix>0},{kind:`num`,id:`volume`,label:`Volume`,group:`Output`,min:-40,max:12,def:-6,unit:`dB`},{kind:`bool`,id:`seqOn`,label:`Auto-play`,group:`Auto`,def:!1},{kind:`enum`,id:`seqMode`,label:`Pattern`,group:`Auto`,def:`mixed`,options:[[`mixed`,`Mixed (changes every 4 bars)`],[`melody`,`Melody`],[`arpeggio`,`Arpeggio`],[`chords`,`Chords`],[`rhythm`,`Rhythm (one pitch)`],[`drone`,`Drone + sparse melody`]]},{kind:`num`,id:`seqTempo`,label:`Tempo`,group:`Auto`,min:20,max:400,def:110,int:!0,unit:`bpm`},{kind:`num`,id:`seqDensity`,label:`Density`,group:`Auto`,min:0,max:1,def:.5},{kind:`enum`,id:`seqScale`,label:`Scale`,group:`Auto`,def:`pentatonic`,options:[[`chromatic`,`Chromatic`],[`major`,`Major`],[`minor`,`Natural minor`],[`dorian`,`Dorian`],[`pentatonic`,`Pentatonic`],[`wholetone`,`Whole tone`],[`harmonic`,`Harmonic series`]]},{kind:`num`,id:`seqRoot`,label:`Root`,group:`Auto`,min:24,max:84,def:48,int:!0},{kind:`num`,id:`seqRange`,label:`Range`,group:`Auto`,min:1,max:4,def:2,int:!0,unit:`oct`},{kind:`num`,id:`seqGate`,label:`Note length`,group:`Auto`,min:.05,max:8,def:.5,scale:`log`,unit:`beats`},{kind:`num`,id:`seqPoly`,label:`Notes per step`,group:`Auto`,min:1,max:4,def:1,int:!0,show:e=>e.seqMode===`melody`||e.seqMode===`mixed`},{kind:`num`,id:`seqVelRand`,label:`Velocity spread`,group:`Auto`,min:0,max:1,def:.3},{kind:`num`,id:`seqPosRand`,label:`Position spread`,group:`Auto`,min:0,max:1,def:0,hint:`randomize where each note is excited`}];Object.fromEntries(l.map(e=>[e.id,e]));const u=Object.fromEntries(l.map(e=>[e.id,e.def])),d=l.filter(e=>e.model).map(e=>e.id),f=Math.SQRT2,p=Math.PI;function m(e,t){let n=Math.ceil(Math.abs(t)+e)+24,r=0;for(let i=0;i<=n;i++){let a=p*i/n;r+=(i===0||i===n?.5:1)*Math.cos(e*a-t*Math.sin(a))}return r/n}function h(e,t){let n=[],r=e===0?.5:e,i=m(e,r);for(let a=r+.05;a<=t;a+=.05){let t=m(e,a);if(i*t<0){let t=r,o=a,s=i;for(let n=0;n<50;n++){let n=.5*(t+o),r=m(e,n);s*r<=0?o=n:(t=n,s=r)}n.push(.5*(t+o))}r=a,i=t}return n}const g=[4.730040745,7.853204624,10.99560784,14.13716549,17.27875966],_=e=>ef*Math.sin((e+1)*p*t)};case`tube_co`:for(let e=0;ef*Math.cos((2*e+1)*p*t/2)};case`tube_oo`:for(let e=0;ef*Math.cos((e+1)*p*t)};case`bar`:{let e=_(0),n=new Float64Array(t),r=2048;for(let i=0;in[e]*v(e,_(e),t)}}case`ring`:{let e=[],n=[],r=0,i=0,c=2;for(;e.length{let i=2*p*r*e[t];return f*(n[t]===0?Math.cos(i):Math.sin(i))}}}case`plate`:{let e=Math.ceil(3*Math.sqrt(t))+3,r=[];for(let t=1;t<=e;t++)for(let i=1;i<=e;i++)r.push([t*t+(i/n)**2,t,i]);r.sort((e,t)=>e[0]-t[0]);let i=new Int32Array(t),c=new Int32Array(t),l=r[0][0];for(let e=0;e2*Math.sin(i[e]*p*t)*Math.sin(c[e]*p*n)}}case`membrane`:{let e=2*Math.sqrt(t)+6,n=[];for(;;){n=[];for(let t=0;t<=Math.ceil(e);t++)for(let r of h(t,e))n.push([r,t,0]),t>0&&n.push([r,t,1]);if(n.length>=t)break;e*=1.3}n.sort((e,t)=>e[0]-t[0]||e[2]-t[2]);let r=n[0][0],i=new Int32Array(t),c=new Int32Array(t),l=new Float64Array(t),u=new Float64Array(t);for(let e=0;e0&&r.push([n*1.0004,t,i,1])}r.sort((e,t)=>e[0]-t[0]);let c=r.slice(0,t),l=c.reduce((e,t)=>Math.max(e,t[1]),0),u=c.reduce((e,t)=>Math.max(e,t[2]),0),d=[];for(let e=0;e<=l;e++)d.push(x(e,u+1));let f=new Int32Array(t),m=new Int32Array(t),h=new Float64Array(t),g=c[0][0];for(let e=0;ee===0?-m(1,t):.5*(m(e-1,t)-m(e+1,t)),r=[],i=e===0?.5:Math.max(.3,e*.8),a=n(i);for(let e=i+.05;r.length{let a=o[e];if(!a){a=/* @__PURE__ */ new Float64Array(258);for(let n=0;n<=256;n++)a[n]=m(t[e],r[e]*n/256);if(a[257]=a[256],o[e]=a,!i){let n=0;for(let e=0;e<=256;e++)n+=(e===0||e===256?.5:1)*a[e]*a[e]*e/256/256;s[e]=1/Math.sqrt(Math.max(1e-12,(t[e]===0?2:1)*n))}}let c=n*256,l=Math.floor(c),u=c-l;return a[l]*(1-u)+a[l+1]*u};return{...e,view:`disk`,dim:2,shape:(e,r,i)=>{let a=2*r-1,o=2*i-1,l=Math.hypot(a,o);if(l>=1)return 0;let u=c(e,l),d=t[e],f=d===0?1:n[e]===0?Math.cos(d*Math.atan2(o,a)):Math.sin(d*Math.atan2(o,a));return s[e]*u*f}}}function C(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 w(e){let t=Math.max(e(),1e-12);return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}const ee=e=>d.map(t=>String(e[t])).join(`|`);function T(n){let r=Math.round(e(n,`modes`)),i=b(t(n,`geometry`),r,e(n,`aspect`),e(n,`powerExp`),e(n,`discExp`)),a=Math.round(e(n,`seed`)),o=C(a*7919+13),s=e(n,`stretch`),c=e(n,`inharm`),l=e(n,`harmonize`),u=e(n,`jitter`),d=0;for(let e=0;e0){let e=t<.75?.5:Math.max(1,Math.round(t));t=t**(1-l)*e**+l}let n=w(o);e!==d&&u>0&&(t*=2**(u*n/1200)),f[e]=t}let p=Int32Array.from({length:r},(e,t)=>t).sort((e,t)=>f[e]-f[t]),m=new Float64Array(r),h=new Float64Array(r),g=0;for(let e=0;ee+t.length,0),E=new Int32Array(v+1),D=new Int32Array(T),O=new Int32Array(T),te=new Float64Array(T),k=0;for(let e=0;ei.shape(p[e],t,n)}}const E={violin:{name:`Violin`,low:[[275,22,0],[405,30,-12],[470,40,-8],[460,32,0],[540,32,2]],hill:2600,hillDb:6,top:5500},viola:{name:`Viola`,low:[[230,22,0],[340,30,-12],[390,40,-8],[380,32,0],[445,32,2]],hill:2100,hillDb:5,top:4800},cello:{name:`Cello`,low:[[102,20,0],[145,30,-10],[170,40,-8],[178,30,1],[210,30,2]],hill:1500,hillDb:4,top:3500},bass:{name:`Double bass`,low:[[62,18,0],[92,28,-10],[104,38,-8],[112,30,1],[138,30,2]],hill:900,hillDb:3,top:2400},guitar:{name:`Guitar`,low:[[98,18,0],[204,28,3],[230,35,-6],[390,30,-3],[440,35,-2]],hill:2500,hillDb:2,top:5e3}};function D(e,t,n,r=1){let i=E[e];if(!i)return[];let a=C(r*6151+17),o=[];for(let[e,r,s]of i.low){let i=10**(s/20);o.push({f:e/t,q:r/n,gL:i,gR:i*(.8+.4*a())})}let s=1.2*Math.max(...i.low.map(e=>e[0]));for(;s<4.5*i.top;){let e=Math.log2(s/i.hill),r=-6+i.hillDb*Math.exp(-(e*e)/.72);r-=12*Math.max(0,Math.log2(s/i.top));let c=10**((r+3*w(a))/20),l=10**((r+3*w(a))/20);o.push({f:s/t,q:(20+25*a())/n,gL:c*(a()<.5?-1:1),gR:l*(a()<.5?-1:1)}),s*=1+.07*(.5+a())}return o}function O(e,t){let n=0,r=0,i=0,a=0;for(let o of e){let e=t/o.f,s=1-e*e,c=e/o.q,l=s*s+c*c,u=c*c/l,d=c*s/l;n+=o.gL*u,r+=o.gL*d,i+=o.gR*u,a+=o.gR*d}return .5*(n*n+r*r+i*i+a*a)}var te=class{n=0;b0=/* @__PURE__ */ new Float64Array;a1=/* @__PURE__ */ new Float64Array;a2=/* @__PURE__ */ new Float64Array;gL=/* @__PURE__ */ new Float64Array;gR=/* @__PURE__ */ new Float64Array;x1=0;x2=0;y1=/* @__PURE__ */ new Float64Array;y2=/* @__PURE__ */ new Float64Array;key=``;configure(e,t,n,r){let i=`${e}|${t}|${n}|${r}`;if(i===this.key)return;this.key=i;let a=D(e,t,n).filter(e=>e.f<.45*r),o=0,s=0;if(a.length){let e=.8*a[0].f,t=Math.min(1e4,.45*r);for(let n=0;n<=200;n++)o+=O(a,e*(t/e)**(n/200)),s++}let c=s?1/Math.sqrt(o/s):0,l=a.length,u=this.n!==l;if(this.n=l,u)for(let e of[`b0`,`a1`,`a2`,`gL`,`gR`,`y1`,`y2`])this[e]=new Float64Array(l);a.forEach((e,t)=>{let n=2*Math.PI*e.f/r,i=Math.sin(n)/(2*e.q),a=1+i;this.b0[t]=i/a,this.a1[t]=-2*Math.cos(n)/a,this.a2[t]=(1-i)/a,this.gL[t]=e.gL*c,this.gR[t]=e.gR*c})}reset(){this.x1=this.x2=0,this.y1.fill(0),this.y2.fill(0)}tick(e,t){let n=this.n,r=this.b0,i=this.a1,a=this.a2,o=this.y1,s=this.y2,c=this.gL,l=this.gR,u=e-this.x2;this.x2=this.x1,this.x1=e;let d=0,f=0;for(let e=0;e{let t=Math.abs(e);return t+Math.log1p(Math.exp(-2*t))-Math.LN2},ne=6.907755,re=10**-9,ie=.1;var ae=class{idx;active=!1;note=60;baseHz=261.6;vel=1;gate=!1;held=!1;sustained=!1;touching=!1;damped=!0;order=0;N=0;nAct=0;nTune=0;cull=1/0;nNL=0;nNLTune=0;q=/* @__PURE__ */ new Float64Array;qp=/* @__PURE__ */ new Float64Array;qn=/* @__PURE__ */ new Float64Array;A=/* @__PURE__ */ new Float64Array;B=/* @__PURE__ */ new Float64Array;C=/* @__PURE__ */ new Float64Array;om=/* @__PURE__ */ new Float64Array;sw=/* @__PURE__ */ new Float64Array;sw2=/* @__PURE__ */ new Float64Array;grad=/* @__PURE__ */ new Float64Array;pv=/* @__PURE__ */ new Float64Array;gp=/* @__PURE__ */ new Float64Array;phiE=/* @__PURE__ */ new Float64Array;phiB=/* @__PURE__ */ new Float64Array;wL=/* @__PURE__ */ new Float64Array;wR=/* @__PURE__ */ new Float64Array;wsum=0;omega1=1;Z0=1;tunedPitch=-1;tunedDamp=-1;tunedGate=!1;glideMul=1;tunedGlide=1;vibMul=1;tunedVib=1;vibPh=0;vibAge=0;vibRateJ=1;dirtyTune=!0;dirtyVec=!0;posX=-1;posY=-1;ham=!1;hz=0;hzp=0;hzn=0;hamISM=1;hamK=0;hamA=2.5;hamTimer=0;gz=0;buzzK=0;buzzGap=0;buzzPhi1=1;beta=.11;env=0;fLaw=0;nz=0;f=0;fb=/* @__PURE__ */ new Float32Array(32768);fbW=0;bx1=0;bx2=0;by1=0;by2=0;S=0;X=0;Vv=0;useG=!1;fast=!1;tc=0;tq=0;pred=!1;energy=0;outMono=0;constructor(e){this.idx=e}alloc(e){let t=t=>{let n=new Float64Array(e);return n.set(t.subarray(0,Math.min(e,t.length))),n};this.q=t(this.q),this.qp=t(this.qp),this.qn=new Float64Array(e);for(let t of[`A`,`B`,`C`,`om`,`sw`,`sw2`,`grad`,`pv`,`gp`,`phiE`,`phiB`,`wL`,`wR`])this[t]=new Float64Array(e);this.N=e,this.dirtyTune=this.dirtyVec=!0}reset(){this.q.fill(0),this.qp.fill(0),this.qn.fill(0),this.ham=!1,this.env=0,this.fLaw=0,this.fb.fill(0),this.bx1=this.bx2=this.by1=this.by2=0,this.energy=0,this.uncull()}uncull(){this.cull=1/0,this.nAct=this.nTune,this.nNL=this.nNLTune}};const oe=e=>440*2**((e-69)/12),se=e=>e<0?0:e>1?1:e,P=e=>e-Math.floor(e);var ce=class{sr;h;p={...u};model;voices=[];act=[];eps=A;vMax=0;vHold=0;psi=Math.sqrt(A);psiReset=!1;order=0;bend=0;sustain=!1;lastNote=60;focus=null;touchVoice=null;pending=[];post=()=>{};paramVersion=0;rngS=0x9e3779b9;lfoPh=[0,0];lfoA=[0,0];lfoB=[0,0];kt=0;kc=0;cc=0;ct=0;cl=0;crossOn=!1;buzzA=1.5;buzzTwo=!1;ampMul=1;fbMul=1;excMul=1;pitchMul=1;dampMul=1;posOff=0;pickOff=0;vecVersion=-1;lastPosOff=0;lastPickOff=0;law=0;lwF=0;lwVb=0;lwGam=0;lwD=0;lawK=/* @__PURE__ */ new Float64Array(3);envAtt=0;envRel=0;noiseC=0;noiseNorm=1;fbD=1;fb0=0;fb2=0;fa1=0;fa2=0;snapCount=0;cpuMs=0;cpuWall=0;cpu=0;lastTouch=null;box=new te;boxOut=/* @__PURE__ */ new Float64Array(2);constructor(e){this.sr=e,this.h=1/e,this.model=T(this.p);for(let e=0;e<16;e++){let t=new ae(e);t.alloc(this.model.N),this.voices.push(t)}}message(e){e.type===`params`?this.setParams(e.params):this.pending.push(e)}setParams(n){if(this.p={...u,...n},this.paramVersion++,ee(this.p)!==this.model.key){this.model=T(this.p);for(let e of this.voices)e.alloc(this.model.N);this.psiReset=!0}for(let e of this.voices)e.dirtyTune=e.dirtyVec=!0;let r=t(this.p,`soundbox`);r===`off`?(this.box.configure(``,1,1,this.sr),this.box.reset()):this.box.configure(r,e(this.p,`boxSize`),e(this.p,`boxDamp`),this.sr)}handle(e){switch(e.type){case`noteOn`:this.noteOn(e.note,e.vel,e.x,e.y);break;case`noteOff`:this.noteOff(e.note);break;case`sustain`:if(this.sustain=e.on,!e.on)for(let e of this.voices)e.sustained&&(e.sustained=!1,this.updateGate(e));break;case`bend`:this.bend=e.value;break;case`touchStart`:this.touchStart(e.x,e.y,e.vel);break;case`touchMove`:this.lastTouch={x:e.x,y:e.y},this.touchVoice&&(this.touchVoice.posX=e.x,this.touchVoice.posY=e.y,this.touchVoice.dirtyVec=!0);break;case`touchEnd`:this.lastTouch=null,this.touchVoice&&=(this.touchVoice.touching=!1,this.updateGate(this.touchVoice),null);break;case`panic`:for(let e of this.voices)e.reset(),e.active=!1;this.box.reset(),this.psi=Math.sqrt(this.eps)}}allocVoice(t){let n=this.voices.find(e=>e.active&&e.note===t);if(n)return n;let r=Math.round(e(this.p,`voices`)),i=this.voices.filter(e=>e.active);return i.length>=r?(i.sort((e,t)=>Number(e.gate)-Number(t.gate)||e.energy-t.energy||e.order-t.order),n=i[0]):n=this.voices.find(e=>!e.active),n.reset(),n.active=!0,n.glideMul=1,n.vibMul=1,n.vibPh=this.rand(),n.vibRateJ=1+.1*(this.rand()*2-1),n.note=t,n.baseHz=oe(t),n.held=n.sustained=n.touching=!1,n.gate=!1,n.dirtyTune=n.dirtyVec=!0,n.tunedPitch=-1,this.psiReset=!0,n}updateGate(e){let t=e.held||e.sustained||e.touching;t!==e.gate&&(e.gate=t,e.dirtyTune=!0)}noteOn(e,t,n,r){let i=this.allocVoice(e);i.uncull(),i.order=++this.order,i.vel=Math.max(.01,Math.min(1,t)),i.held=!0,i.damped=!0,i.vibAge=0,i.posX=n??-1,i.posY=r??-1,i.dirtyVec=!0,this.updateGate(i),this.lastNote=e,this.focus=i,this.prepare(i),this.excite(i,i.vel)}noteOff(e){for(let t of this.voices)t.active&&t.note===e&&t.held&&(t.held=!1,this.sustain&&(t.sustained=!0),this.updateGate(t))}touchStart(e,t,n){this.lastTouch={x:e,y:t};let r=this.focus&&this.focus.active?this.focus:null;r||(r=this.allocVoice(this.lastNote),r.order=++this.order,r.damped=!1,this.focus=r),r.posX=e,r.posY=t,r.vel=n,r.dirtyVec=!0;let i=this.law!==0;i&&(r.touching=!0,this.touchVoice=r,this.updateGate(r)),this.prepare(r),i||this.excite(r,n)}prepare(e){e.dirtyVec&&this.vecVoice(e),(e.dirtyTune||e.tunedPitch!==this.pitchMul||e.tunedDamp!==this.dampMul||e.tunedGate!==e.gate||e.tunedGlide!==e.glideMul||e.tunedVib!==e.vibMul)&&this.tuneVoice(e)}excite(n,r){n.uncull();let i=t(this.p,`exciter`),a=k*(e(this.p,`strength`)*r)**2;if(a<=0)return;let o=n.nAct,s=n.phiE,c=n.om,l=this.h;if(i===`strike`){let t=e(this.p,`hammerMass`),r=e(this.p,`hardness`)/1e3,i=e(this.p,`feltExp`),c=Math.sqrt(2*a/t),u=Math.sqrt(2*k/t)*r/Math.PI,d=0,f=0;for(let e=0;e=d){t.A[e]=t.B[e]=t.C[e]=t.sw[e]=t.sw2[e]=0;continue}f=e+1;let l=(s+c*(r/1e3)**2)*this.dampMul+u,m=Math.exp(-l*i);if(l0&&(p=e+1)}for(let e=f;e0?g*(2*Math.PI*4e3)**2*.1*h**(1-this.buzzA):0,t.tunedPitch=this.pitchMul,t.tunedDamp=this.dampMul,t.tunedGate=t.gate,t.tunedGlide=t.glideMul,t.tunedVib=t.vibMul,t.dirtyTune=!1}vecVoice(t){let n=this.model,r=n.N,i=this.p,a=t.posX>=0?t.posX:se(e(i,`exPos`)+this.posOff),o=t.posY>=0?t.posY:se(e(i,`exPosY`)+this.posOff),s=e(i,`exWidth`)*.15,c=e(i,`buzzPos`),l=e(i,`buzzPosY`),u=P(e(i,`pickup`)+this.pickOff),d=e(i,`pickupY`),f=e(i,`width`),p=P(u+.5*f),m=P(d+.37*f),h=e(i,`spread`),g=e(i,`tilt`)/6.0206;for(let e=0;e>>17,e^=e<<5,this.rngS=e>>>0,this.rngS/4294967296}lfo(n,r){let i=this.p,a=e(i,`lfo${n+1}Rate`),o=this.lfoPh[n]+a*r;switch(o>=1&&(o-=Math.floor(o),this.lfoA[n]=this.lfoB[n],this.lfoB[n]=this.rand()*2-1),this.lfoPh[n]=o,t(i,`lfo${n+1}Shape`)){case`tri`:return 1-4*Math.abs(o-.5);case`saw`:return 2*o-1;case`square`:return o<.5?1:-1;case`sh`:return this.lfoB[n];case`smooth`:return this.lfoA[n]+(this.lfoB[n]-this.lfoA[n])*(.5-.5*Math.cos(Math.PI*o));default:return Math.sin(2*Math.PI*o)}}blockUpdate(n){let r=this.p,i=this.sr,a=n/i,o=this.bend*e(r,`bendRange`),s=1,c=0,l=0,u=e(r,`tension`),d=e(r,`cascade`),f=1,p=1,m=1;for(let n=0;n<2;n++){let i=t(r,`lfo${n+1}Target`);if(i===`off`)continue;let h=e(r,`lfo${n+1}Depth`),g=this.lfo(n,a)*h;switch(i){case`pitch`:o+=4*g;break;case`amp`:s*=Math.max(0,1+g);break;case`position`:c+=.5*g;break;case`pickup`:l+=.5*g;break;case`tension`:u*=Math.max(0,1+g);break;case`cascade`:d*=Math.max(0,1+g);break;case`damping`:f*=2**(3*g);break;case`feedback`:p*=Math.max(0,1+g);break;case`exciter`:m*=Math.max(0,1+g)}}this.pitchMul=2**(o/12),this.dampMul=f,this.ampMul=s,this.fbMul=p,this.excMul=m,this.kt=u,this.kc=this.model.M>0?d:0,this.cc=+e(r,`curvature`),this.ct=e(r,`crossTension`),this.cl=e(r,`crossLink`),this.crossOn=this.ct>0||this.cl>0,this.buzzTwo=t(r,`buzzSides`)===`two`;let h=t(r,`exciter`);this.law=h===`bow`?1:h===`reed`?2:h===`selfosc`?3:h===`noise`?4:0;let g=this.lawK;this.law===1?(g[0]=e(r,`bowSpeed`)*.5,g[1]=+e(r,`bowForce`),g[2]=e(r,`bowNoise`)):this.law===2?(g[0]=e(r,`reedGain`)*2,g[1]=e(r,`reedPressure`),g[2]=e(r,`breath`)):this.law===3&&(g[0]=+e(r,`selfGain`),g[1]=e(r,`selfSat`)),this.envAtt=1-Math.exp(-1/(e(r,`attack`)/1e3*i)),this.envRel=1-Math.exp(-1/(e(r,`release`)/1e3*i));let _=Math.min(e(r,`noiseColor`),.45*i);this.noiseC=1-Math.exp(-2*Math.PI*_/i),this.noiseNorm=Math.sqrt(3*(2-this.noiseC)/this.noiseC),this.fbD=Math.max(1,Math.min(32767,Math.round(e(r,`fbDelay`)/1e3*i)));let v=2*Math.PI*Math.min(e(r,`fbFreq`),.45*i)/i,y=Math.sin(v)/(2*e(r,`fbQ`)),b=1+y;this.fb0=y/b,this.fb2=-y/b,this.fa1=-2*Math.cos(v)/b,this.fa2=(1-y)/b;let x=c!==this.lastPosOff||l!==this.lastPickOff||this.vecVersion!==this.paramVersion;this.posOff=c,this.pickOff=l,this.lastPosOff=c,this.lastPickOff=l,this.vecVersion=this.paramVersion;let S=e(r,`vibDepth`),C=e(r,`vibRate`),w=e(r,`vibDelay`)/1e3;this.act.length=0;for(let e of this.voices)if(e.active){if(S>0){e.vibAge+=a;let t=e.vibAge,n=w>0?(t-.3*w)/(.7*w):1;n=n<0?0:n>1?1:n*n*(3-2*n),e.vibPh+=C*e.vibRateJ*(1+.06*Math.sin(2.3*t+7*e.vibRateJ))*a,e.vibPh-=Math.floor(e.vibPh);let r=2**(S*n*Math.sin(2*Math.PI*e.vibPh)/1200);(Math.abs(r/e.vibMul-1)>1e-5||n===0&&e.vibMul!==1)&&(e.vibMul=r)}else e.vibMul=1;x&&(e.dirtyVec=!0),this.prepare(e),this.act.push(e)}}nl(e){if(this.kt<=0&&this.ct<=0&&this.kc<=0&&!this.crossOn&&!e.ham&&e.buzzK<=0){e.S=e.X=e.Vv=e.gz=0,e.useG=!1;return}let t=e.nAct,n=e.q,r=e.sw,i=e.grad,a=this.model,o=0,s=!1,c=e.nNL,l=0;if(this.kt>0||this.ct>0||this.kc>0)for(let e=0;e0&&l>0){let e=3/this.kt,t=l/k;o+=this.kt*k*.5*e*e*N(t/e);let a=this.kt*e*Math.tanh(t/e);for(let e=0;e0){let t=a.Nnl,l=Math.min(c,t),d=e.pv,f=e.gp,p=this.cc,m=3/(u*a.M);for(let e=0;e0){let n=e.hamA,a=e.hamK*c**+n;o+=a*c/(n+1);for(let e=0;e.05*this.sr&&(e.ham=!1)}if(e.buzzK>0){let r=e.phiB,a=0;for(let e=0;e0){let t=e.buzzK*u**+c;o+=t*u/(c+1),l+=t}if(this.buzzTwo){let t=-a-e.buzzGap;if(t>0){let n=e.buzzK*t**+c;o+=n*t/(c+1),l-=n}}if(l!==0){for(let e=0;e0)for(let a=0;a0){let t=3/this.kt,n=a/k;e.Vv=this.kt*k*.5*t*t*N(n/t),e.tc=this.kt*t*Math.tanh(n/t),e.tq=e.tc===0?0:o,e.useG=!0}else e.Vv=0,e.tc=0,e.tq=0,e.useG=!1}lawEval(e){let t=0,n=0;if(this.law===1){let r=e-this.lwVb,i=Math.tanh(r/j),a=1+Math.abs(r)/M,o=.35+.65/a,s=-.65/(M*a*a)*(r>=0?1:-1);t=-this.lwF*i*o,n=-this.lwF*((1-i*i)/j*o+i*s)}else if(this.law===2){let r=this.lwGam-e;if(r<1){let e=Math.sqrt(Math.abs(r)+1e-9),i=this.lwF;r>=0?(t=i*(1-r)*e,n=-i*(-e+(1-r)/(2*e))):(t=-i*(1-r)*e,n=-i*(e+(1-r)/(2*e)))}}else{let r=this.lwF,i=this.lwVb;t=r*(e-e*e*e/(3*i*i)),n=r*(1-e*e/(i*i))}return this.lwD=n,t}solveLaw(e,t,n){let r=e.nAct,i=e.phiE,a=e.A,o=e.B,s=e.q,c=e.qp,l=e.qn,u=0;for(let e=0;e0?Math.max(0,1+t*n):1)}else this.law===2?(this.lwF=g[0]*h,this.lwGam=g[1]*m*(1+g[2]*n)):(this.lwF=g[0]*h*m,this.lwVb=g[1]);let _=this.lwF+1e-9,v=1e-9*_,y=e.fLaw,b=!1;for(let e=0;e<8;e++){let e=y-this.lawEval(f+p*y);if(Math.abs(e)=0));e++)n*=2;for(let e=0;e<50;e++){let e=.5*(r+i);e-this.lawEval(f+p*e)<0?r=e:i=e}y=.5*(r+i),Number.isFinite(y)||(y=0)}return e.fLaw=y,y}process(t,n,r,i=0){let a=Date.now(),o=r/this.sr;if(this.pending.length){let e=[];for(let t of this.pending)(`time`in t&&t.time!==void 0?t.time:0)<=i+o?this.handle(t):e.push(t);this.pending=e}this.blockUpdate(r);let s=this.act,c=this.h,l=c*c,u=1/c,d=this.p,f=e(d,`fbGain`)*this.fbMul,p=e(d,`fbSat`),m=e(d,`noiseLevel`),h=this.law,g=h===4||h===3||h===2&&e(d,`breath`)>0||h===1&&e(d,`bowNoise`)>0,_=this.box,v=_.n>0,y=v?e(d,`boxMix`):0,b=1-y,x=this.boxOut,S=.25*this.ampMul*u*10**(e(d,`level`)/20),C=32767,w=this.kt>0&&this.kt<=ie&&this.kc<=0&&!this.crossOn;for(let e=0;e1e-6){let e=0;if(g&&(t.nz+=this.noiseC*(this.rand()*2-1-t.nz),e=t.nz*this.noiseNorm),f>0){let e=t.fb[t.fbW-this.fbD&C],r=this.fb0*e+this.fb2*t.bx2-this.fa1*t.by1-this.fa2*t.by2;t.bx2=t.bx1,t.bx1=e,t.by2=t.by1,t.by1=r,n+=p*t.Z0*Math.tanh(f*r/p)*t.env}h===3&&(n+=.001*t.Z0*t.env*e),h===4?n+=m*t.Z0*t.env*this.excMul*e*.5:h!==0&&(n+=this.solveLaw(t,n,e))}else t.fLaw=0;t.f=n,w&&!t.ham&&t.buzzK<=0?this.nlTension(t):(t.fast=!1,this.nl(t)),r+=t.Vv,i+=t.X,t.useG&&(a=!0)}if(this.crossOn&&s.length){let e=i/k;r+=k*3*3*N(e/3);let t=3*Math.tanh(e/3),n=this.ct,a=+this.cl,o=this.model.bx,c=this.model.Nnl;for(let e of s){let r=e.nNL,i=e.grad,s=e.q,l=e.sw;for(let e=0;ethis.vMax&&(this.vMax=r),this.psiReset&&(this.eps=.01);let e=Math.sqrt(2*r+this.eps),t=1/e;if(this.psiReset)this.psi=e,this.psiReset=!1;else{let t=this.psi+.01*(e-this.psi);Math.abs(t)0);for(let t of this.act){let i=t.nAct,a=t.q,o=t.qp,s=t.om,c=0,l=0;for(let e=0;el&&(l=r)}if(r&&!t.ham&&t.buzzK<=0&&(this.law===0||t.env<=1e-6)){let e=l*re,r=i;for(;r>1;){let t=r-1,i=(a[t]-o[t])*n;if(.5*(i*i+s[t]*s[t]*a[t]*a[t])>e)break;r--}if(r1e8){t.reset(),t.active=!1,this.psiReset=!0;continue}t.energy=c;let u=e(this.p,`glide`),d=1;if(u!==0){let e=4*c/k;d=2**(u*e/(1+e)/12)}(Math.abs(d/t.glideMul-1)>2e-5||d===1&&t.glideMul!==1)&&(t.glideMul=d),!t.gate&&!t.ham&&c<1e-10&&t.env<1e-4&&(t.active=!1)}let i=0;for(let e of this.act)e.active&&(i+=e.energy);this.vHold=Math.max(this.vMax,this.vHold*.95),this.vMax=0;let a=Math.max(A,.02*i+2*this.vHold);if(a=this.sr/30&&(this.snapCount=0,this.cpuWall>0&&(this.cpu=this.cpuMs/this.cpuWall),this.cpuMs=this.cpuWall=0,this.snapshot())}snapshot(){let e=this.focus&&this.focus.active?this.focus:null;if(!e)for(let t of this.voices)t.active&&(!e||t.order>e.order)&&(e=t);let t=this.model.N,n=new Float32Array(t),r=new Float32Array(t),i=new Float32Array(t),a=new Float32Array(t);if(e){let o=1/this.h;for(let s=0;s{let t=e.data;t.type===`init`&&(R={...u,...t.sound},z=R,L=new ce(F),L.message({type:`params`,params:R}),B=t.stem,q=Math.max(1,t.slow??1),V=t.fromFrame,H=t.fromFrame,ue=t.sendFrame,W=t.sendFrame,le=t.playerPort,le.onmessage=e=>{W=e.data.playhead,de=e.data.ahead,ve()},t.scorePort.onmessage=e=>{let t=e.data;if(t.type===`cmds`){for(let e of t.cmds)G.push(e);H=Math.max(H,Math.floor(t.horizon*F))}else t.type===`end`&&(U=Math.round(t.t*F),H=Math.max(H,U));ve()})};function ve(){K||(K=!0,setTimeout(xe,0))}function ye(e){switch(e.type){case`noteOn`:L.message({type:`noteOn`,note:e.note,vel:e.vel}),pe.set(e.note,e.t);break;case`noteOff`:if(e.on!==void 0&&(pe.get(e.note)??-1/0)>e.on)break;L.message({type:`noteOff`,note:e.note});break;case`params`:z={...z,...e.params},L.message({type:`params`,params:z});break;case`bend`:L.message({type:`bend`,value:e.value});break;case`gain`:me=e.value,Y=e.tau,X=!!e.normalize;break;case`hold`:{if(he)break;he=!0;let t=e.hold+e.fade,n=Math.min(60,Math.max(R.t60,6*t)),r=n/R.t60;z={...z,t60:n,hfDamp:R.hfDamp/r},L.message({type:`params`,params:z}),ge=e.t+Math.max(e.hold,.005),_e=Math.max(.01,e.fade);break}}}const Q=/* @__PURE__ */ new Float32Array(128),$=/* @__PURE__ */ new Float32Array(128);function be(e,t,n){let r=V/F,i=(V+128)/F;for(;G.length&&G[0].t1e-10&&(Z+=(e-Z)*(1-Math.exp(-128/F/1.5)))}let a=X?Math.max(.05,Math.min(20,I/Math.sqrt(Z))):1,o=me*a,s=J;J=Y>0?J+(o-J)*(1-Math.exp(-128/F/Y)):o;for(let r=0;r<128;r++){let i=s+(J-s)*(r+1)/128,a=(V+r)/F;if(a>=ge){let e=Math.min(1,(a-ge)/_e),t=Math.cos(Math.PI/2*e);i*=t*t}e[n+r]=Q[r]*i,t[n+r]=$[r]*i}V+=128}function xe(){if(K=!1,!L)return;if(V>=U){fe||(fe=!0,Se({type:`done`,stem:B,frame:U}));return}let e=Math.min(H,W+de,U+128-1),t=Math.min(2048,Math.floor((e-V)/128)*128);if(t<=0)return;let n=V,r=new Float32Array(t),i=new Float32Array(t),a=performance.now();for(let e=0;e1){let e=performance.now()+(q-1)*(performance.now()-a);for(;performance.now()ue){let e=Math.max(0,ue-n),t=e?r.slice(e):r,a=e?i.slice(e):i;Se({type:`chunk`,stem:B,frame:n+e,L:t,R:a},[t.buffer,a.buffer])}ve()}function Se(e,t=[]){le.postMessage(e,t)}