Spaces:
Running
Running
Download web-engine/codec-worker.js from mrfakename/zonos3-mini-webgpu: direct link, hf CLI and curl.
- Browser
- Download file 8.89 kB
-
https://huggingface.co/spaces/mrfakename/zonos3-mini-webgpu/resolve/main/web-engine/codec-worker.js
- Command line
-
hf download hf://spaces/mrfakename/zonos3-mini-webgpu/web-engine/codec-worker.js
-
curl -L -o codec-worker.js https://huggingface.co/spaces/mrfakename/zonos3-mini-webgpu/resolve/main/web-engine/codec-worker.js
8.89 kB
| var e=class{n;m;factors=[];wc;ws;cos;sin;leaf=/* @__PURE__ */ new Map;xr;xi;yr;yi;tr;ti;ur;ui;vr;vi;constructor(e){if(this.n=e,!Number.isInteger(e)||e<2||e%2)throw Error(`irfft: n=${e} must be even`);let t=this.m=e/2,n=t;for(let e of[2,3])for(;n%e===0;)this.factors.push(e),n/=e;for(let e=5;n>1;e+=2)for(;n%e===0;)this.factors.push(e),n/=e;this.factors.sort((e,t)=>e-t),this.wc=new Float64Array(t),this.ws=new Float64Array(t),this.cos=new Float64Array(t),this.sin=new Float64Array(t);for(let n=0;n<t;n++)this.wc[n]=Math.cos(2*Math.PI*n/e),this.ws[n]=Math.sin(2*Math.PI*n/e),this.cos[n]=Math.cos(2*Math.PI*n/t),this.sin[n]=Math.sin(2*Math.PI*n/t);for(let e of this.factors){if(e<5||this.leaf.has(e))continue;let t=(e-1)/2,n=new Float64Array(t*t),r=new Float64Array(t*t);for(let i=1;i<=t;i++)for(let a=1;a<=t;a++){let o=2*Math.PI*(i*a%e)/e;n[(i-1)*t+a-1]=Math.cos(o),r[(i-1)*t+a-1]=Math.sin(o)}this.leaf.set(e,{c:n,s:r})}this.xr=new Float64Array(t),this.xi=new Float64Array(t),this.yr=new Float64Array(t),this.yi=new Float64Array(t);let r=this.factors.length?this.factors[this.factors.length-1]:1;this.tr=new Float64Array(r),this.ti=new Float64Array(r);let i=r-1>>1;this.ur=new Float64Array(i),this.ui=new Float64Array(i),this.vr=new Float64Array(i),this.vi=new Float64Array(i)}exec(e,t,n){let{n:r,m:i,xr:a,xi:o,yr:s,yi:c,wc:l,ws:u}=this;for(let t=0;t<i;t++){let n=t?e[2*t-1]:e[0],s=t?e[2*t]:0,c=i-t,d=c===i?e[r-1]:e[2*c-1],f=c===i?0:-e[2*c],p=n+d,m=s+f,h=n-d,g=s-f,_=l[t],v=u[t];a[t]=p-(_*g+v*h),o[t]=m+(_*h-v*g)}this.factors.length?this.rec(0,1,0,0,i):(s[0]=a[0],c[0]=o[0]);for(let e=0;e<i;e++)t[2*e]=s[e]*n,t[2*e+1]=c[e]*n}rec(e,t,n,r,i){let{xr:a,xi:o,yr:s,yi:c,tr:l,ti:u,cos:d,sin:f,m:p}=this,m=this.factors[r],h=i/m;if(h===1){for(let n=0;n<m;n++)l[n]=a[e+n*t],u[n]=o[e+n*t];this.dft(m,n,1);return}for(let i=0;i<m;i++)this.rec(e+i*t,t*m,n+i*h,r+1,h);let g=p/i;if(m===2)for(let e=0,t=0;e<h;e++,t+=g){let r=n+e,i=r+h,a=s[i],o=c[i],l=d[t],u=f[t],p=a*l-o*u,m=a*u+o*l,g=s[r],_=c[r];s[r]=g+p,c[r]=_+m,s[i]=g-p,c[i]=_-m}else for(let e=0;e<h;e++){l[0]=s[n+e],u[0]=c[n+e];for(let t=1,r=e*g;t<m;t++,r+=e*g){let i=s[n+t*h+e],a=c[n+t*h+e],o=d[r],p=f[r];l[t]=i*o-a*p,u[t]=i*p+a*o}this.dft(m,n+e,h)}}dft(e,t,n){let{yr:r,yi:i,tr:a,ti:o}=this;if(e===2){r[t]=a[0]+a[1],i[t]=o[0]+o[1],r[t+n]=a[0]-a[1],i[t+n]=o[0]-o[1];return}if(e===3){let e=-.5,s=Math.sqrt(3)/2,c=a[1]+a[2],l=o[1]+o[2],u=a[1]-a[2],d=o[1]-o[2],f=a[0]+e*c,p=o[0]+e*l;r[t]=a[0]+c,i[t]=o[0]+l,r[t+n]=f-s*d,i[t+n]=p+s*u,r[t+2*n]=f+s*d,i[t+2*n]=p-s*u;return}let{ur:s,ui:c,vr:l,vi:u}=this,{c:d,s:f}=this.leaf.get(e),p=(e-1)/2,m=a[0],h=o[0];for(let t=1;t<=p;t++){let n=a[t],r=o[t],i=a[e-t],d=o[e-t];s[t-1]=n+i,c[t-1]=r+d,l[t-1]=n-i,u[t-1]=r-d,m+=n+i,h+=r+d}r[t]=m,i[t]=h;for(let m=1;m<=p;m++){let h=a[0],g=o[0],_=0,v=0,y=(m-1)*p;for(let e=0;e<p;e++){let t=d[y+e],n=f[y+e];h+=s[e]*t,g+=c[e]*t,_+=u[e]*n,v+=l[e]*n}r[t+m*n]=h-_,i[t+m*n]=g+v,r[t+(e-m)*n]=h+_,i[t+(e-m)*n]=g-v}}},t=class{data=/* @__PURE__ */ new Float32Array;len=0;resize(e){if(e>this.data.length){let t=new Float32Array(Math.max(e,2*this.data.length));t.set(this.data.subarray(0,this.len)),this.data=t}else e>this.len&&this.data.fill(0,this.len,e);this.len=e}erase(e){this.data.copyWithin(0,e,this.len),this.len-=e}clear(){this.len=0}},n=class{nFft;hop;windows;mixer;fir;maxLogMag;irfft;hc;buf;ola=[new t,new t];env=[new t,new t];olaBase=[0,0];mixIn=[new t,new t];mixAvail=[0,0];mixBase=0;mixNext=0;headFrames=0;headDone=!1;constructor(t){if(this.nFft=t.nFft,this.hop=t.hop,this.fir=t.mixer.length/2,!Number.isInteger(this.fir)||this.fir%2!=1)throw Error(`istft: mixer has ${t.mixer.length} taps, expected 2 x odd`);for(let e=0;e<2;e++)if(t.windows[e].length!==t.nFft[e])throw Error(`istft: window ${e} has ${t.windows[e].length} taps, expected ${t.nFft[e]}`);this.windows=t.windows,this.mixer=t.mixer,this.maxLogMag=t.maxLogMag,this.irfft=[new e(t.nFft[0]),new e(t.nFft[1])],this.hc=[new Float64Array(t.nFft[0]),new Float64Array(t.nFft[1])],this.buf=[new Float32Array(t.nFft[0]),new Float32Array(t.nFft[1])]}get frames(){return this.headFrames}reset(){for(let e=0;e<2;e++)this.ola[e].clear(),this.env[e].clear(),this.mixIn[e].clear(),this.olaBase[e]=0,this.mixAvail[e]=0;this.mixBase=0,this.mixNext=0,this.headFrames=0,this.headDone=!1}push(e,t,n){if(this.headDone)throw Error(`istft: push after flush`);this.headFrames===0&&this.init();let r=[e,t],i=this.hop;for(let e=0;e<2;e++){let t=this.nFft[e],a=t/2+1;if(r[e].length<n*(t+2))throw Error(`istft: branch ${e} has ${r[e].length} values, expected ${n*(t+2)}`);let o=this.windows[e],s=this.hc[e],c=this.buf[e],l=r[e],u=this.maxLogMag,d=this.ola[e],f=this.env[e];for(let r=0;r<n;r++){let n=this.headFrames+r,p=r*(t+2),m=p+a,h=e=>Math.exp(Math.min(l[p+e],u));s[0]=h(0)*Math.cos(l[m]);for(let e=1;e<t/2;e++){let t=h(e);s[2*e-1]=t*Math.cos(l[m+e]),s[2*e]=t*Math.sin(l[m+e])}s[t-1]=h(t/2)*Math.cos(l[m+t/2]),this.irfft[e].exec(s,c,1/t);let g=n*i+t-this.olaBase[e];d.len<g&&(d.resize(g),f.resize(g));let _=n*i-this.olaBase[e],v=d.data,y=f.data;for(let e=0;e<t;e++)v[_+e]+=o[e]*c[e],y[_+e]+=o[e]*o[e]}}this.headFrames+=n;for(let e=0;e<2;e++)this.olaFinalize(e,this.headFrames*i);return this.mixEmit()}flush(){if(this.headDone||this.headFrames===0)return/* @__PURE__ */ new Float32Array;this.headDone=!0;let e=(this.fir-1)/2;for(let t=0;t<2;t++){this.olaFinalize(t,this.olaBase[t]+this.ola[t].len);let n=e+this.headFrames*this.hop-this.mixBase;this.mixIn[t].resize(n),this.mixIn[t].resize(n+e),this.mixAvail[t]=this.mixBase+n+e}return this.mixEmit()}init(){let e=(this.fir-1)/2;for(let t=0;t<2;t++)this.mixIn[t].clear(),this.mixIn[t].resize(e),this.mixAvail[t]=e;this.mixBase=0,this.mixNext=0}olaFinalize(e,t){let n=this.nFft[e]/2,r=t-this.olaBase[e];if(r<=0)return;let i=this.ola[e],a=this.env[e],o=this.mixIn[e],s=Math.min(r,Math.max(0,n-this.olaBase[e])),c=o.len;o.resize(c+r-s);let l=o.data,u=i.data,d=a.data;for(let e=s;e<r;e++)l[c+e-s]=u[e]/d[e];this.mixAvail[e]+=r-s,i.erase(r),a.erase(r),this.olaBase[e]=t}mixEmit(){let e=this.fir,t=Math.min(this.mixAvail[0],this.mixAvail[1])-e+1;if(t<=this.mixNext)return/* @__PURE__ */ new Float32Array;let n=t-this.mixNext,r=new Float32Array(n);for(let t=0;t<2;t++){let i=this.mixIn[t].data,a=this.mixNext-this.mixBase,o=t*e;for(let t=0;t<e;t++){let e=this.mixer[o+t];for(let o=0;o<n;o++)r[o]+=e*i[a+o+t]}}this.mixNext=t;for(let e=0;e<2;e++)this.mixNext>this.mixBase&&this.mixIn[e].erase(this.mixNext-this.mixBase);return this.mixBase=this.mixNext,r}},r=class{kernel;orig;nw;width;buf=/* @__PURE__ */ new Float32Array;len=0;base=0;inCount=0;nextBlock=0;kl;lo;hi;constructor(e,t=736,n=735,r=17){if(this.kernel=e,this.orig=t,this.nw=n,this.width=r,this.kl=2*r+t,e.length!==n*this.kl)throw Error(`resampler: kernel has ${e.length} taps, expected ${n*this.kl}`);this.lo=new Int32Array(n),this.hi=new Int32Array(n);for(let t=0;t<n;t++){let n=t*this.kl,r=0;for(;r<this.kl&&e[n+r]===0;)r++;let i=this.kl;for(;i>r&&e[n+i-1]===0;)i--;this.lo[t]=r,this.hi[t]=i}}push(e){if(this.len+e.length>this.buf.length){let t=new Float32Array(Math.max(this.len+e.length,2*this.buf.length));t.set(this.buf.subarray(0,this.len)),this.buf=t}return this.buf.set(e,this.len),this.len+=e.length,this.inCount+=e.length,this.run(!1)}flush(){return this.run(!0)}reset(){this.len=0,this.base=0,this.inCount=0,this.nextBlock=0}run(e){let{orig:t,nw:n,width:r,kl:i,kernel:a,lo:o,hi:s}=this,c=e?Math.floor((n*this.inCount+t-1)/t):-1,l=[],u=new Float32Array(i);for(;;this.nextBlock++){let d=this.nextBlock,f=d*t-r;if(e?d*n>=c:f+i>this.inCount)break;for(let e=0;e<i;e++){let t=f+e;u[e]=t<0||t>=this.inCount?0:this.buf[t-this.base]}let p=e?Math.min(n,c-d*n):n,m=new Float32Array(p);for(let e=0;e<p;e++){let t=e*i,n=0;for(let r=o[e];r<s[e];r++)n+=a[t+r]*u[r];m[e]=n}l.push(m)}let d=Math.min(this.inCount,Math.max(0,this.nextBlock*t-r));if(d>this.base){let e=d-this.base;this.buf.copyWithin(0,e,this.len),this.len-=e,this.base=d}let f=new Float32Array(l.reduce((e,t)=>e+t.length,0)),p=0;for(let e of l)f.set(e,p),p+=e.length;return f}},i=class{istft;rs;constructor(e){this.istft=new n(e),this.rs=new r(e.resampleKernel)}async push(e,t,n){return this.rs.push(this.istft.push(e,t,n))}async flush(){let e=this.rs.push(this.istft.flush()),t=this.rs.flush(),n=new Float32Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}reset(){this.istft.reset(),this.rs.reset()}};function a(e){let t=null,n=`not initialized`,r=Promise.resolve(),a=(t,n=[])=>e.postMessage(t,n),o=async e=>{if(e.type===`init`)try{t=new i(e)}catch(e){t=null,n=e instanceof Error?e.message:String(e)}else if(e.type===`reset`)t?.reset();else try{if(!t)throw Error(n);let r=e.type===`push`?await t.push(e.s0,e.s1,e.cols):await t.flush();a({type:`pcm`,pcm:r},[r.buffer])}catch(e){a({type:`error`,message:e instanceof Error?e.message:String(e)})}};e.onmessage=e=>{let t=e.data;r=r.then(()=>o(t))}}self.onmessage=e=>{e.data.type===`port`&&e.ports[0]&&a(e.ports[0])}; |