Repository navigation
Expand file tree
/
Copy pathscript.min.js
More file actions
1 lines (1 loc) · 4.76 KB
/
Copy pathscript.min.js
File metadata and controls
1 lines (1 loc) · 4.76 KB
1
const e=document.getElementById("visualizer"),t=e.getContext("2d"),n={transitionSpeed:.5,stretchedToArchSpeed:.18,sineArchPhaseSpeed:2.5,fullWavePhaseSpeed:3.5,baselinePhaseSpeed:.4,ampSmoothing:{attack:.4,release:.6},freqSmoothing:{attack:.3,release:.7},silenceSmoothing:{attack:.12,release:.04},silenceThreshold:.005,silenceScaleThreshold:.002,maxAmpScale:.7,stretchedEnergyDecay:.985,stretchedEnergyThreshold:.15,stretchedInitialSpeed:60,stretchedOscillationStrength:.14,stretchedNormalStrength:.25,stretchedSpeedBlend:.03,normalSpeedBase:8,normalSpeedFreqScale:14,durations:{TWIN_LOBES:1e4,SINGLE_LOBE:1e4,STRETCHED:6e3,SINE_ARCH:9e3,FULL_WAVE:8e3},singleLobeToStretchedTransitionSpeed:1.8};function r(){e.width=window.innerWidth,e.height=window.innerHeight}r(),window.addEventListener("resize",r);let i=0,a=new Array(128).fill(0),o=0,h=2,s=0;const E={TWIN_LOBES:0,STRETCHED:1,SINGLE_LOBE:2,SINE_ARCH:3,FULL_WAVE:4},S=[E.TWIN_LOBES,E.SINGLE_LOBE,E.STRETCHED,E.SINE_ARCH,E.FULL_WAVE];let c=0,l=E.TWIN_LOBES,d=E.TWIN_LOBES,T=1,L=!1,A=0,_=!1,I=!1;const f={[E.SINE_ARCH]:0,[E.FULL_WAVE]:0};let C=0,H=n.stretchedInitialSpeed,R=1,m=!1,p=0,g=0;function u(e,t,n){const r=(e-t)/n;return Math.exp(-r*r)}function N(e){return e===E.STRETCHED?.5:e===E.SINE_ARCH?1:22}function W(e,t){const n=Math.pow(Math.sin(Math.PI*e),1.5);switch(t){case E.TWIN_LOBES:return(u(e,.3,.1)+u(e,.7,.1)+.15*u(e,.5,.035))*n;case E.STRETCHED:return.8*n;case E.SINGLE_LOBE:return u(e,.5,.18)*n;case E.SINE_ARCH:return.9;case E.FULL_WAVE:return.75;default:return 0}}function M(e){return e===E.SINE_ARCH?f[E.SINE_ARCH]:e===E.FULL_WAVE?f[E.FULL_WAVE]:0}function y(e){return e===E.SINE_ARCH||e===E.FULL_WAVE}window.livelyAudioListener=e=>{a=e},requestAnimationFrame(function r(u){requestAnimationFrame(r);const F=Math.min((u-i)/1e3||.016,.05);i=u;let D=0,w=0;for(let e=0;e<64;e++)D+=a[e];for(let e=64;e<128;e++)w+=a[e];D/=64,w/=64,o=o*n.ampSmoothing.release+D*n.ampSmoothing.attack,h=h*n.freqSmoothing.release+w*n.freqSmoothing.attack;const U=n.normalSpeedBase+h*n.normalSpeedFreqScale;l===E.STRETCHED?(R*=Math.pow(n.stretchedEnergyDecay,60*F),H=H*(1-n.stretchedSpeedBlend)+U*n.stretchedSpeedBlend,C+=F*H):L&&I?(R*=Math.pow(n.stretchedEnergyDecay,60*F),C+=F*H):L&&I||l!==E.STRETCHED&&(R=1,H=n.stretchedInitialSpeed);const V=l===E.FULL_WAVE||d===E.FULL_WAVE;if((l===E.SINE_ARCH||d===E.SINE_ARCH)&&(f[E.SINE_ARCH]+=F*n.sineArchPhaseSpeed),V&&(f[E.FULL_WAVE]+=F*n.fullWavePhaseSpeed),g+=F*n.baselinePhaseSpeed,L){let e;e=I?n.stretchedToArchSpeed:_?n.singleLobeToStretchedTransitionSpeed:n.transitionSpeed,T=Math.min(1,T+F*e),T>=1&&(l=d,L=!1,_=!1,I=!1,A=u)}if(!L){const e=Object.keys(E).find(e=>E[e]===l),t=n.durations[e]??1e4;(u-A>t||l===E.STRETCHED&&R<n.stretchedEnergyThreshold)&&(c=(c+1)%S.length,B=S[c],L||(_=l===E.SINGLE_LOBE&&B===E.STRETCHED,I=l===E.STRETCHED&&B===E.SINE_ARCH,frozenPhase=M(l),d=B,T=0,L=!0,m=!1,B===E.SINE_ARCH&&(f[E.SINE_ARCH]=0,p=0),B===E.FULL_WAVE&&(f[E.FULL_WAVE]=0),B===E.STRETCHED&&(R=1,H=n.stretchedInitialSpeed,C=0)))}var B;const P=T<.5?2*T*T:(4-2*T)*T-1,O=l===E.SINE_ARCH||d===E.SINE_ARCH;I?p=P:O&&L?p=P<.5?Math.max(0,1-2*P):Math.min(1,2*(P-.5)):l!==E.SINE_ARCH||L?O||(p=0):p=1;const x=o<n.silenceThreshold;s+=((x?0:1)-s)*(x?n.silenceSmoothing.release:n.silenceSmoothing.attack),t.fillStyle="#050505",t.fillRect(0,0,e.width,e.height);const k=.5*e.height,v=Math.max(720,Math.floor(e.width)),q=e.height*n.maxAmpScale*Math.sqrt(o)*s;if(s<n.silenceScaleThreshold)return t.strokeStyle="#ffffff",t.lineWidth=8,t.beginPath(),t.moveTo(0,k),t.lineTo(e.width,k),void t.stroke();const b=N(l),G=N(d),z=L?b*(1-P)+G*P:b;let j=1;if(L){j=(l===E.STRETCHED?3:1)*(1-P)+(d===E.STRETCHED?3:1)*P}else j=l===E.STRETCHED?3:1;const J=new Array(v),K=l!==E.SINE_ARCH&&d!==E.SINE_ARCH?1:p;for(let t=0;t<v;t++){const r=t/(v-1),i=r*e.width,a=W(r,l)*(1-P)+W(r,d)*P;let o=z,h=K,s=0,S=Math.pow(Math.sin(Math.PI*r),j);const c=l===E.STRETCHED&&d!==E.STRETCHED?1-P:d===E.STRETCHED?P:l===E.STRETCHED?1:0;if(c>0){const T=I?P:h*(1-c);s=Math.sin(C)*c;let L=0;y(d)&&(L=M(d));let A=0;o>.001&&(A=-Math.cos((r-.5)*Math.PI*2*o+L));const _=l===E.FULL_WAVE&&d!==E.FULL_WAVE?1-P:d===E.FULL_WAVE?P:0,f=_>0?Math.sin((r-.5)*Math.PI*1.5+g)*e.height*.35*_:0,H=n.stretchedOscillationStrength*R;J[t]={x:i,y:k+f+A*q*T*a+s*q*H*S};continue}let T=0;{const e=y(l),t=y(d);e&&t?T=M(l)*(1-P)+M(d)*P:e&&!t?T=frozenPhase*(1-P):!e&&t&&(T=M(d))}let L=0;o>.001&&(L=-Math.cos((r-.5)*Math.PI*2*o+T));const A=l===E.FULL_WAVE&&d!==E.FULL_WAVE?1-P:d===E.FULL_WAVE?P:0,_=A>0?Math.sin((r-.5)*Math.PI*1.5+g)*e.height*.35*A:0;J[t]={x:i,y:k+_+L*q*h*a+s*q*n.stretchedNormalStrength*S}}t.strokeStyle="#ffffff",t.lineWidth=8,t.lineJoin="round",t.lineCap="round",t.beginPath(),t.moveTo(J[0].x,J[0].y);for(let e=1;e<J.length-1;e++){const n=(J[e].x+J[e+1].x)/2,r=(J[e].y+J[e+1].y)/2;t.quadraticCurveTo(J[e].x,J[e].y,n,r)}t.lineTo(J[v-1].x,J[v-1].y),t.stroke()});