@jadujoel/web-audio-clip-node 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/processor.js CHANGED
@@ -1,4 +1,4 @@
1
- var P={Initial:0,Started:1,Stopped:2,Paused:3,Scheduled:4,Ended:5,Disposed:6};var _=128;function i(V=[]){let A=V[0]?.length??0,F=A>0;return{totalLength:F?A:null,committedLength:F?A:0,streamEnded:F,streaming:!1,writtenSpans:F?[{startSample:0,endSample:A}]:[],pendingWrites:[],lowWaterThreshold:_*4,lowWaterNotified:!1,lastUnderrunSample:null}}function G0(V){return V[0]?.length??0}function o(V){return V.streamBuffer.totalLength??G0(V.buffer)}function H0(V,A){return Array.from({length:V},()=>new Float32Array(A))}function E0(V,A){let F=[...V,A].sort((J,k)=>J.startSample-k.startSample),T=[];for(let J of F){let k=T[T.length-1];if(!k||J.startSample>k.endSample){T.push({...J});continue}k.endSample=Math.max(k.endSample,J.endSample)}return T}function I0(V){let A=0;for(let F of V){if(F.startSample>A)break;A=Math.max(A,F.endSample)}return A}function w0(V,A){if(V.committedLength-Math.floor(A)>=V.lowWaterThreshold)V.lowWaterNotified=!1}function R0(V,A,F){let T=G0(V.buffer),J=V.buffer.length;if(T>=F&&J>=A)return;let k=Math.max(T,F),Q=Math.max(J,A),X=H0(Q,k);for(let U=0;U<J;U++)X[U].set(V.buffer[U].subarray(0,T));if(V.buffer=X,V.streamBuffer.totalLength==null||V.streamBuffer.totalLength<k)V.streamBuffer.totalLength=k}function B0(V,A){let F=Math.max(Math.floor(A.startSample),0),T=A.channelData[0]?.length??0,J=A.totalLength??null,k=Math.max(F+T,J??0);R0(V,Math.max(A.channelData.length,V.buffer.length,1),k);for(let Q=0;Q<A.channelData.length;Q++)V.buffer[Q].set(A.channelData[Q],F);if(J!=null)V.streamBuffer.totalLength=J;if(T>0)V.streamBuffer.writtenSpans=E0(V.streamBuffer.writtenSpans,{startSample:F,endSample:F+T}),V.streamBuffer.committedLength=I0(V.streamBuffer.writtenSpans);if(A.streamEnded===!0)V.streamBuffer.streamEnded=!0;w0(V.streamBuffer,V.playhead)}function y0(V){if(V.streamBuffer.pendingWrites.length===0)return;for(let A of V.streamBuffer.pendingWrites)B0(V,A);V.streamBuffer.pendingWrites=[]}function _0(V,A){V.buffer=A,V.streamBuffer=i(A)}function v0(V={},A){let{buffer:F=[],streamBuffer:T=i(F),duration:J=-1,loop:k=!1,loopStart:Q=0,loopEnd:X=(F[0]?.length??0)/A,loopCrossfade:U=0,playhead:$=0,offset:M=0,startWhen:Y=0,stopWhen:j=0,pauseWhen:z=0,resumeWhen:C=0,playedSamples:N=0,state:K=P.Initial,timesLooped:w=0,fadeInDuration:v=0,fadeOutDuration:Z=0,enableFadeIn:E=v>0,enableFadeOut:O=Z>0,enableLoopStart:R=!0,enableLoopEnd:d=!0,enableLoopCrossfade:b=U>0,enableHighpass:c=!0,enableLowpass:g=!0,enableGain:s=!0,enablePan:t=!0,enableDetune:r=!0,enablePlaybackRate:p=!0}=V;return{buffer:F,streamBuffer:T,loop:k,loopStart:Q,loopEnd:X,loopCrossfade:U,duration:J,playhead:$,offset:M,startWhen:Y,stopWhen:j,pauseWhen:z,resumeWhen:C,playedSamples:N,state:K,timesLooped:w,fadeInDuration:v,fadeOutDuration:Z,enableFadeIn:E,enableFadeOut:O,enableLoopStart:R,enableLoopEnd:d,enableHighpass:c,enableLowpass:g,enableGain:s,enablePan:t,enableDetune:r,enablePlaybackRate:p,enableLoopCrossfade:b}}function b0(V,A){return o(V)/A}function n(V,A){let F=b0(V,A);if(F<=0){V.loopStart=0,V.loopEnd=0;return}if(!Number.isFinite(V.loopStart)||V.loopStart<0)V.loopStart=0;if(V.loopStart>=F)V.loopStart=0;if(!Number.isFinite(V.loopEnd)||V.loopEnd<=V.loopStart||V.loopEnd>F)V.loopEnd=F}function e(V,A,F){if(A===void 0)return V.offset=0,0;if(A<0)return e(V,o(V)+A,F);if(A>(o(V)||1)-1)return e(V,o(V)%A,F);let T=Math.floor(A*F);return V.offset=T,T}function L0(V){let{playhead:A,bufferLength:F,loop:T,loopStartSamples:J,loopEndSamples:k}=V,Q=128;if(!T&&A+128>F)Q=Math.max(F-A,0);let X=Array(Q);if(!T){for(let Y=0,j=A;Y<Q;Y++,j++)X[Y]=j;let M=A+Q;return{playhead:M,indexes:X,looped:!1,ended:M>=F}}let U=A,$=!1;for(let M=0;M<Q;M++,U++){if(U>=k)U=J+(U-k),$=!0;X[M]=U}return{indexes:X,looped:$,ended:!1,playhead:U}}function x0(V){let{playhead:A,bufferLength:F,loop:T,loopStartSamples:J,loopEndSamples:k,playbackRates:Q}=V,X=128;if(!T&&A+128>F)X=Math.max(F-A,0);let U=Array(X),$=A,M=!1;if(T){for(let Y=0;Y<X;Y++){U[Y]=Math.min(Math.max(Math.floor($),0),F-1);let j=Q[Y]??Q[0]??1;if($+=j,j>=0&&($>k||$>F))$=J,M=!0;else if(j<0&&($<J||$<0))$=k,M=!0}return{playhead:$,indexes:U,looped:M,ended:!1}}for(let Y=0;Y<X;Y++)U[Y]=Math.min(Math.max(Math.floor($),0),F-1),$+=Q[Y]??Q[0]??1;return{playhead:$,indexes:U,looped:!1,ended:$>=F||$<0}}function m0(V,A,F){let T=Math.min(V.length,A.length);for(let J=0;J<F.length;J++)for(let k=0;k<T;k++)V[k][J]=A[k][F[J]];for(let J=T;J<V.length;J++)for(let k=0;k<V[J].length;k++)V[J][k]=0;for(let J=F.length;J<V[0].length;J++)for(let k=0;k<T;k++)V[k][J]=0}function h(V){for(let A=0;A<V.length;A++)for(let F=0;F<V[A].length;F++)V[A][F]=0}function S0(V){if(V.length>=2)for(let A=0;A<V[0].length;A++)V[1][A]=V[0][A];else{let A=new Float32Array(V[0].length);for(let F=0;F<V[0].length;F++)A[F]=V[0][F];V.push(A)}}function M0(V,A){for(let F=A.length;F<V.length;F++)A[F]=new Float32Array(V[F].length);for(let F=0;F<V.length;F++)for(let T=0;T<V[F].length;T++)A[F][T]=V[F][T]}function c0(V){let A=0;for(let F=0;F<V.length;F++)for(let T=0;T<V[F].length;T++)if(Number.isNaN(V[F][T]))A++,V[F][T]=0;return A}function V0(){return[{x_1:0,x_2:0,y_1:0,y_2:0},{x_1:0,x_2:0,y_1:0,y_2:0}]}function g0(V,A){if(A.length===1){let T=A[0];if(T===1)return;for(let J of V)for(let k=0;k<J.length;k++)J[k]*=T;return}let F=A[0];for(let T of V)for(let J=0;J<T.length;J++)F=A[J]??F,T[J]*=F}function h0(V,A){let F=A[0];for(let T=0;T<V[0].length;T++){F=A[T]??F;let J=F<=0?1:1-F,k=F>=0?1:1+F;V[0][T]*=J,V[1][T]*=k}}function d0(V,A,F,T){for(let J=0;J<V.length;J++){let k=V[J],{x_1:Q,x_2:X,y_1:U,y_2:$}=T[J]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let M=A[0];if(M>=20000)return;let Y=2*Math.PI*M/F,j=Math.sin(Y)/2,z=(1-Math.cos(Y))/2,C=1-Math.cos(Y),N=(1-Math.cos(Y))/2,K=1+j,w=-2*Math.cos(Y),v=1-j,Z=z/K,E=C/K,O=N/K,R=w/K,d=v/K;for(let b=0;b<k.length;b++){let c=k[b],g=Z*c+E*Q+O*X-R*U-d*$;X=Q,Q=c,$=U,U=g,k[b]=g}}else{let M=A[0];for(let Y=0;Y<k.length;Y++){let j=A[Y]??M,z=2*Math.PI*j/F,C=Math.sin(z)/2,N=(1-Math.cos(z))/2,K=1-Math.cos(z),w=(1-Math.cos(z))/2,v=1+C,Z=-2*Math.cos(z),E=1-C,O=k[Y],R=N/v*O+K/v*Q+w/v*X-Z/v*U-E/v*$;X=Q,Q=O,$=U,U=R,k[Y]=R}}T[J]={x_1:Q,x_2:X,y_1:U,y_2:$}}}function u0(V,A,F,T){for(let J=0;J<V.length;J++){let k=V[J],{x_1:Q,x_2:X,y_1:U,y_2:$}=T[J]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let M=A[0];if(M<=20)return;let Y=2*Math.PI*M/F,j=Math.sin(Y)/2,z=(1+Math.cos(Y))/2,C=-(1+Math.cos(Y)),N=(1+Math.cos(Y))/2,K=1+j,w=-2*Math.cos(Y),v=1-j;for(let Z=0;Z<k.length;Z++){let E=k[Z],O=z/K*E+C/K*Q+N/K*X-w/K*U-v/K*$;X=Q,Q=E,$=U,U=O,k[Z]=O}}else{let M=A[0];for(let Y=0;Y<k.length;Y++){let j=A[Y]??M,z=2*Math.PI*j/F,C=Math.sin(z)/2,N=(1+Math.cos(z))/2,K=-(1+Math.cos(z)),w=(1+Math.cos(z))/2,v=1+C,Z=-2*Math.cos(z),E=1-C,O=k[Y],R=N/v*O+K/v*Q+w/v*X-Z/v*U-E/v*$;X=Q,Q=O,$=U,U=R,k[Y]=R}}T[J]={x_1:Q,x_2:X,y_1:U,y_2:$}}}function P0(V,A,F,T){let{type:J,data:k}=A;switch(J){case"buffer":return _0(V,k),n(V,T),[];case"bufferInit":{let Q=k;return V.buffer=H0(Q.channels,Q.totalLength),V.streamBuffer={...i(),totalLength:Q.totalLength,streamEnded:!1,streaming:Q.streaming??!0},n(V,T),[]}case"bufferRange":return V.streamBuffer.pendingWrites.push(k),[];case"bufferEnd":{let Q=k;if(Q?.totalLength!=null)V.streamBuffer.totalLength=Q.totalLength;return V.streamBuffer.streamEnded=!0,[]}case"bufferReset":return V.buffer=[],V.streamBuffer=i(),n(V,T),[];case"start":V.timesLooped=0;{let Q=k;if(V.duration=Q?.duration??-1,V.duration===-1)V.duration=V.loop?Number.MAX_SAFE_INTEGER:(V.buffer[0]?.length??0)/T;e(V,Q?.offset,T),n(V,T),V.playhead=V.offset,V.startWhen=Q?.when??F,V.stopWhen=V.startWhen+V.duration,V.playedSamples=0,V.state=P.Scheduled}return[{type:"scheduled"}];case"stop":if(V.state===P.Ended||V.state===P.Initial)return[];return V.stopWhen=k??V.stopWhen,V.state=P.Stopped,[{type:"stopped"}];case"pause":return V.state=P.Paused,V.pauseWhen=k??F,[{type:"paused"}];case"resume":return V.state=P.Started,V.startWhen=k??F,[{type:"resume"}];case"dispose":return V.state=P.Disposed,V.buffer=[],V.streamBuffer=i(),[{type:"disposed"}];case"loop":{let Q=k,X=V.state;if(Q&&(X===P.Scheduled||X===P.Started))V.stopWhen=Number.MAX_SAFE_INTEGER,V.duration=Number.MAX_SAFE_INTEGER;if(V.loop=Q,Q)n(V,T);return[]}case"loopStart":return V.loopStart=k,[];case"loopEnd":return V.loopEnd=k,[];case"loopCrossfade":return V.loopCrossfade=k,[];case"playhead":return V.playhead=Math.floor(k),[];case"fadeIn":return V.fadeInDuration=k,[];case"fadeOut":return V.fadeOutDuration=k,[];case"toggleGain":return V.enableGain=k??!V.enableGain,[];case"togglePan":return V.enablePan=k??!V.enablePan,[];case"toggleLowpass":return V.enableLowpass=k??!V.enableLowpass,[];case"toggleHighpass":return V.enableHighpass=k??!V.enableHighpass,[];case"toggleDetune":return V.enableDetune=k??!V.enableDetune,[];case"togglePlaybackRate":return V.enablePlaybackRate=k??!V.enablePlaybackRate,[];case"toggleFadeIn":return V.enableFadeIn=k??!V.enableFadeIn,[];case"toggleFadeOut":return V.enableFadeOut=k??!V.enableFadeOut,[];case"toggleLoopStart":return V.enableLoopStart=k??!V.enableLoopStart,[];case"toggleLoopEnd":return V.enableLoopEnd=k??!V.enableLoopEnd,[];case"toggleLoopCrossfade":return V.enableLoopCrossfade=k??!V.enableLoopCrossfade,[];case"logState":return[]}return[]}function j0(V,A,F,T,J){let k=[],Q=V.state;if(Q===P.Disposed)return{keepAlive:!1,messages:k};if(y0(V),Q===P.Initial)return{keepAlive:!0,messages:k};if(Q===P.Ended)return h(A[0]),{keepAlive:!0,messages:k};if(Q===P.Scheduled)if(T.currentTime>=V.startWhen)Q=V.state=P.Started,k.push({type:"started"});else return h(A[0]),{keepAlive:!0,messages:k};else if(Q===P.Paused){if(T.currentTime>V.pauseWhen)return h(A[0]),{keepAlive:!0,messages:k}}if(T.currentTime>V.stopWhen)return h(A[0]),V.state=P.Ended,k.push({type:"ended"}),V.playedSamples=0,{keepAlive:!0,messages:k};let X=A[0],U=o(V);if(U===0)return h(X),{keepAlive:!0,messages:k};let{playbackRate:$,detune:M,lowpass:Y,highpass:j,gain:z,pan:C}=F,{buffer:N,loopStart:K,loopEnd:w,loopCrossfade:v,stopWhen:Z,playedSamples:E,enableLowpass:O,enableHighpass:R,enableGain:d,enablePan:b,enableDetune:c,enableFadeOut:g,enableFadeIn:s,enableLoopStart:t,enableLoopEnd:r,enableLoopCrossfade:p,playhead:D,fadeInDuration:A0,fadeOutDuration:F0}=V,K0=V.streamBuffer.streaming&&V.streamBuffer.committedLength<U,k0=V.loop&&!K0,u=Math.min(N.length,X.length),W0=V.duration*T.sampleRate,Z0=Math.floor(T.sampleRate*v),q0=Math.max(U-_,0),L=t?Math.min(Math.floor(K*T.sampleRate),q0):0,x=r?Math.min(Math.floor(w*T.sampleRate),U):U,N0=x-L,T0=c&&M.length>0&&M[0]!==0,l=$;if(T0){let G=Math.max($.length,M.length,_);l=new Float32Array(G);for(let W=0;W<G;W++){let I=$[W]??$[$.length-1],H=M[W]??M[M.length-1];l[W]=I*2**(H/1200)}}let J0=V.enablePlaybackRate||T0,O0=J0&&l.length>0&&l.every((G)=>G===0);if(V.streamBuffer.streaming&&!V.streamBuffer.streamEnded&&!V.streamBuffer.lowWaterNotified&&V.streamBuffer.committedLength-Math.floor(D)<V.streamBuffer.lowWaterThreshold)k.push({type:"bufferLowWater",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength}}),V.streamBuffer.lowWaterNotified=!0;if(O0){h(X);for(let G=1;G<A.length;G++)M0(X,A[G]);return{keepAlive:!0,messages:k}}let Q0={bufferLength:U,loop:k0,playhead:D,loopStartSamples:L,loopEndSamples:x,durationSamples:W0,playbackRates:l},{indexes:a,ended:U0,looped:X0,playhead:Y0}=J0?x0(Q0):L0(Q0),f=a.find((G)=>G>=V.streamBuffer.committedLength&&G<U);if(f!==void 0&&!V.streamBuffer.streamEnded&&V.streamBuffer.lastUnderrunSample!==f)k.push({type:"bufferUnderrun",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength,requestedSample:f}}),V.streamBuffer.lastUnderrunSample=f;else if(f===void 0)V.streamBuffer.lastUnderrunSample=null;m0(X,N,a);let m=Math.min(Math.floor(v*T.sampleRate),N0),D0=k0&&D>L&&D<x,C0=p&&Z0>0&&U>_;if(D0&&C0){{let G=L+m;if(m>0&&D>L&&D<G){let W=D-L,I=Math.min(Math.floor(G-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.cos(Math.PI*B/2),q=Math.floor(x-m+W+H);if(q>=0&&q<U)for(let y=0;y<u;y++)X[y][H]+=N[y][q]*S}}}{let G=x-m;if(m>0&&D>G&&D<x){let W=D-G,I=Math.min(Math.floor(x-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.sin(Math.PI*B/2),q=Math.floor(L+W+H);if(q>=0&&q<U)for(let y=0;y<u;y++)X[y][H]+=N[y][q]*S}}}}if(s&&A0>0){let G=Math.floor(A0*T.sampleRate),W=G-E;if(W>0){let I=Math.min(W,_);for(let H=0;H<I;H++){let B=(E+H)/G,S=B*B*B;for(let q=0;q<u;q++)X[q][H]*=S}}}if(g&&F0>0){let G=Math.floor(F0*T.sampleRate),W=Math.floor(T.sampleRate*(Z-T.currentTime));if(W<G+_)for(let I=0;I<_;I++){let H=W-I;if(H>=G)continue;let B=H<=0?0:H/G,S=B*B*B;for(let q=0;q<u;q++)X[q][I]*=S}}if(O)d0(X,Y,T.sampleRate,J.lowpass);if(R)u0(X,j,T.sampleRate,J.highpass);if(d)g0(X,z);if(u===1)S0(X);if(b)h0(X,C);if(X0)V.timesLooped++,k.push({type:"looped",data:V.timesLooped});if(U0)V.state=P.Ended,k.push({type:"ended"});V.playedSamples+=a.length,V.playhead=Y0;let $0=c0(X);if($0>0)return console.log({numNans:$0,indexes:a,playhead:Y0,ended:U0,looped:X0,sourceLength:U}),{keepAlive:!0,messages:k};for(let G=1;G<A.length;G++)M0(X,A[G]);return{keepAlive:!0,messages:k}}class z0 extends AudioWorkletProcessor{static get parameterDescriptors(){return[{name:"playbackRate",automationRate:"a-rate",defaultValue:1},{name:"detune",automationRate:"a-rate",defaultValue:0},{name:"gain",automationRate:"a-rate",defaultValue:1,minValue:0},{name:"pan",automationRate:"a-rate",defaultValue:0},{name:"highpass",automationRate:"a-rate",defaultValue:20,minValue:20,maxValue:20000},{name:"lowpass",automationRate:"a-rate",defaultValue:20000,minValue:20,maxValue:20000}]}properties;filterState={lowpass:V0(),highpass:V0()};lastFrameTime=0;constructor(V){super(V);this.properties=v0(V?.processorOptions,sampleRate),this.port.onmessage=(A)=>{let F=P0(this.properties,A.data,currentTime,sampleRate);for(let T of F)this.port.postMessage(T);if(this.properties.state===P.Disposed)this.port.close()}}process(V,A,F){try{let T=j0(this.properties,A,F,{currentTime,currentFrame,sampleRate},this.filterState);for(let k of T.messages)this.port.postMessage(k);let J=currentTime-this.lastFrameTime;return this.lastFrameTime=currentTime,this.port.postMessage({type:"frame",data:[currentTime,currentFrame,Math.floor(this.properties.playhead),J*1000]}),T.keepAlive}catch(T){return this.port.postMessage({type:"processorError",data:{error:String(T),state:this.properties.state,bufferChannels:this.properties.buffer?.length,bufferLength:this.properties.buffer?.[0]?.length,paramKeys:Object.keys(F),hasPlaybackRate:!!F.playbackRate,hasDetune:!!F.detune,hasGain:!!F.gain,hasPan:!!F.pan,outputChannels:A[0]?.length}}),!0}}}registerProcessor("ClipProcessor",z0);
1
+ var j={Initial:0,Started:1,Stopped:2,Paused:3,Scheduled:4,Ended:5,Disposed:6};var _=128;function i(V=[]){let A=V[0]?.length??0,F=A>0;return{totalLength:F?A:null,committedLength:F?A:0,streamEnded:F,streaming:!1,writtenSpans:F?[{startSample:0,endSample:A}]:[],pendingWrites:[],lowWaterThreshold:_*4,lowWaterNotified:!1,lastUnderrunSample:null}}function H0(V){return V[0]?.length??0}function o(V){return V.streamBuffer.totalLength??H0(V.buffer)}function P0(V,A){return Array.from({length:V},()=>new Float32Array(A))}function E0(V,A){let F=[...V,A].sort((T,k)=>T.startSample-k.startSample),M=[];for(let T of F){let k=M[M.length-1];if(!k||T.startSample>k.endSample){M.push({...T});continue}k.endSample=Math.max(k.endSample,T.endSample)}return M}function I0(V){let A=0;for(let F of V){if(F.startSample>A)break;A=Math.max(A,F.endSample)}return A}function w0(V,A){if(V.committedLength-Math.floor(A)>=V.lowWaterThreshold)V.lowWaterNotified=!1}function R0(V,A,F){let M=H0(V.buffer),T=V.buffer.length;if(M>=F&&T>=A)return;let k=Math.max(M,F),J=Math.max(T,A),U=P0(J,k);for(let Q=0;Q<T;Q++)U[Q].set(V.buffer[Q].subarray(0,M));if(V.buffer=U,V.streamBuffer.totalLength==null||V.streamBuffer.totalLength<k)V.streamBuffer.totalLength=k}function B0(V,A){let F=Math.max(Math.floor(A.startSample),0),M=A.channelData[0]?.length??0,T=A.totalLength??null,k=Math.max(F+M,T??0);R0(V,Math.max(A.channelData.length,V.buffer.length,1),k);for(let J=0;J<A.channelData.length;J++)V.buffer[J].set(A.channelData[J],F);if(T!=null)V.streamBuffer.totalLength=T;if(M>0)V.streamBuffer.writtenSpans=E0(V.streamBuffer.writtenSpans,{startSample:F,endSample:F+M}),V.streamBuffer.committedLength=I0(V.streamBuffer.writtenSpans);if(A.streamEnded===!0)V.streamBuffer.streamEnded=!0;w0(V.streamBuffer,V.playhead)}function y0(V){if(V.streamBuffer.pendingWrites.length===0)return;for(let A of V.streamBuffer.pendingWrites)B0(V,A);V.streamBuffer.pendingWrites=[]}function _0(V,A){V.buffer=A,V.streamBuffer=i(A)}function j0(V={},A){let{buffer:F=[],streamBuffer:M=i(F),duration:T=-1,loop:k=!1,loopStart:J=0,loopEnd:U=(F[0]?.length??0)/A,loopCrossfade:Q=0,playhead:Y=0,offset:$=0,startWhen:X=0,stopWhen:v=0,pauseWhen:z=0,resumeWhen:C=0,playedSamples:N=0,state:K=j.Initial,timesLooped:w=0,fadeInDuration:P=0,fadeOutDuration:Z=0,enableFadeIn:E=P>0,enableFadeOut:O=Z>0,enableLoopStart:R=!0,enableLoopEnd:d=!0,enableLoopCrossfade:b=Q>0,enableHighpass:c=!0,enableLowpass:g=!0,enableGain:s=!0,enablePan:t=!0,enableDetune:r=!0,enablePlaybackRate:p=!0}=V;return{buffer:F,streamBuffer:M,loop:k,loopStart:J,loopEnd:U,loopCrossfade:Q,duration:T,playhead:Y,offset:$,startWhen:X,stopWhen:v,pauseWhen:z,resumeWhen:C,playedSamples:N,state:K,timesLooped:w,fadeInDuration:P,fadeOutDuration:Z,enableFadeIn:E,enableFadeOut:O,enableLoopStart:R,enableLoopEnd:d,enableHighpass:c,enableLowpass:g,enableGain:s,enablePan:t,enableDetune:r,enablePlaybackRate:p,enableLoopCrossfade:b}}function b0(V,A){return o(V)/A}function n(V,A){let F=b0(V,A);if(F<=0){V.loopStart=0,V.loopEnd=0;return}if(!Number.isFinite(V.loopStart)||V.loopStart<0)V.loopStart=0;if(V.loopStart>=F)V.loopStart=0;if(!Number.isFinite(V.loopEnd)||V.loopEnd<=V.loopStart||V.loopEnd>F)V.loopEnd=F}function e(V,A,F){if(A===void 0)return V.offset=0,0;if(A<0)return e(V,o(V)+A,F);if(A>(o(V)||1)-1)return e(V,o(V)%A,F);let M=Math.floor(A*F);return V.offset=M,M}function L0(V){let{playhead:A,bufferLength:F,loop:M,loopStartSamples:T,loopEndSamples:k}=V,J=128;if(!M&&A+128>F)J=Math.max(F-A,0);let U=Array(J);if(!M){for(let X=0,v=A;X<J;X++,v++)U[X]=v;let $=A+J;return{playhead:$,indexes:U,looped:!1,ended:$>=F}}let Q=A,Y=!1;for(let $=0;$<J;$++,Q++){if(Q>=k)Q=T+(Q-k),Y=!0;U[$]=Q}return{indexes:U,looped:Y,ended:!1,playhead:Q}}function x0(V){let{playhead:A,bufferLength:F,loop:M,loopStartSamples:T,loopEndSamples:k,playbackRates:J}=V,U=128;if(!M&&A+128>F)U=Math.max(F-A,0);let Q=Array(U),Y=A,$=!1;if(M){for(let X=0;X<U;X++){Q[X]=Math.min(Math.max(Math.floor(Y),0),F-1);let v=J[X]??J[0]??1;if(Y+=v,v>=0&&(Y>k||Y>F))Y=T,$=!0;else if(v<0&&(Y<T||Y<0))Y=k,$=!0}return{playhead:Y,indexes:Q,looped:$,ended:!1}}for(let X=0;X<U;X++)Q[X]=Math.min(Math.max(Math.floor(Y),0),F-1),Y+=J[X]??J[0]??1;return{playhead:Y,indexes:Q,looped:!1,ended:Y>=F||Y<0}}function m0(V,A,F){let M=Math.min(V.length,A.length);for(let T=0;T<F.length;T++)for(let k=0;k<M;k++)V[k][T]=A[k][F[T]];for(let T=M;T<V.length;T++)for(let k=0;k<V[T].length;k++)V[T][k]=0;for(let T=F.length;T<V[0].length;T++)for(let k=0;k<M;k++)V[k][T]=0}function h(V){for(let A=0;A<V.length;A++)for(let F=0;F<V[A].length;F++)V[A][F]=0}function S0(V){if(V.length>=2)for(let A=0;A<V[0].length;A++)V[1][A]=V[0][A];else{let A=new Float32Array(V[0].length);for(let F=0;F<V[0].length;F++)A[F]=V[0][F];V.push(A)}}function G0(V,A){for(let F=A.length;F<V.length;F++)A[F]=new Float32Array(V[F].length);for(let F=0;F<V.length;F++)for(let M=0;M<V[F].length;M++)A[F][M]=V[F][M]}function c0(V){let A=0;for(let F=0;F<V.length;F++)for(let M=0;M<V[F].length;M++)if(Number.isNaN(V[F][M]))A++,V[F][M]=0;return A}function V0(){return[{x_1:0,x_2:0,y_1:0,y_2:0},{x_1:0,x_2:0,y_1:0,y_2:0}]}function g0(V,A){if(A.length===1){let M=A[0];if(M===1)return;for(let T of V)for(let k=0;k<T.length;k++)T[k]*=M;return}let F=A[0];for(let M of V)for(let T=0;T<M.length;T++)F=A[T]??F,M[T]*=F}function h0(V,A){let F=A[0];for(let M=0;M<V[0].length;M++){F=A[M]??F;let T=F<=0?1:1-F,k=F>=0?1:1+F;V[0][M]*=T,V[1][M]*=k}}function d0(V,A,F,M){for(let T=0;T<V.length;T++){let k=V[T],{x_1:J,x_2:U,y_1:Q,y_2:Y}=M[T]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let $=A[0];if($>=20000)return;let X=2*Math.PI*$/F,v=Math.sin(X)/2,z=(1-Math.cos(X))/2,C=1-Math.cos(X),N=(1-Math.cos(X))/2,K=1+v,w=-2*Math.cos(X),P=1-v,Z=z/K,E=C/K,O=N/K,R=w/K,d=P/K;for(let b=0;b<k.length;b++){let c=k[b],g=Z*c+E*J+O*U-R*Q-d*Y;U=J,J=c,Y=Q,Q=g,k[b]=g}}else{let $=A[0];for(let X=0;X<k.length;X++){let v=A[X]??$,z=2*Math.PI*v/F,C=Math.sin(z)/2,N=(1-Math.cos(z))/2,K=1-Math.cos(z),w=(1-Math.cos(z))/2,P=1+C,Z=-2*Math.cos(z),E=1-C,O=k[X],R=N/P*O+K/P*J+w/P*U-Z/P*Q-E/P*Y;U=J,J=O,Y=Q,Q=R,k[X]=R}}M[T]={x_1:J,x_2:U,y_1:Q,y_2:Y}}}function u0(V,A,F,M){for(let T=0;T<V.length;T++){let k=V[T],{x_1:J,x_2:U,y_1:Q,y_2:Y}=M[T]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let $=A[0];if($<=20)return;let X=2*Math.PI*$/F,v=Math.sin(X)/2,z=(1+Math.cos(X))/2,C=-(1+Math.cos(X)),N=(1+Math.cos(X))/2,K=1+v,w=-2*Math.cos(X),P=1-v;for(let Z=0;Z<k.length;Z++){let E=k[Z],O=z/K*E+C/K*J+N/K*U-w/K*Q-P/K*Y;U=J,J=E,Y=Q,Q=O,k[Z]=O}}else{let $=A[0];for(let X=0;X<k.length;X++){let v=A[X]??$,z=2*Math.PI*v/F,C=Math.sin(z)/2,N=(1+Math.cos(z))/2,K=-(1+Math.cos(z)),w=(1+Math.cos(z))/2,P=1+C,Z=-2*Math.cos(z),E=1-C,O=k[X],R=N/P*O+K/P*J+w/P*U-Z/P*Q-E/P*Y;U=J,J=O,Y=Q,Q=R,k[X]=R}}M[T]={x_1:J,x_2:U,y_1:Q,y_2:Y}}}function A0(V,A,F,M){let{type:T,data:k}=A;switch(T){case"buffer":return _0(V,k),n(V,M),[];case"bufferInit":{let J=k;return V.buffer=P0(J.channels,J.totalLength),V.streamBuffer={...i(),totalLength:J.totalLength,streamEnded:!1,streaming:J.streaming??!0},n(V,M),[]}case"bufferRange":return V.streamBuffer.pendingWrites.push(k),[];case"bufferEnd":{let J=k;if(J?.totalLength!=null)V.streamBuffer.totalLength=J.totalLength;return V.streamBuffer.streamEnded=!0,[]}case"bufferReset":return V.buffer=[],V.streamBuffer=i(),n(V,M),[];case"start":V.timesLooped=0;{let J=k;if(V.duration=J?.duration??-1,V.duration===-1)V.duration=V.loop?Number.MAX_SAFE_INTEGER:(V.buffer[0]?.length??0)/M;e(V,J?.offset,M),n(V,M),V.playhead=V.offset,V.startWhen=J?.when??F,V.stopWhen=V.startWhen+V.duration,V.playedSamples=0,V.state=j.Scheduled}return[{type:"scheduled"}];case"stop":if(V.state===j.Ended||V.state===j.Initial)return[];return V.stopWhen=k??V.stopWhen,V.state=j.Stopped,[{type:"stopped"}];case"pause":return V.state=j.Paused,V.pauseWhen=k??F,[{type:"paused"}];case"resume":return V.state=j.Started,V.startWhen=k??F,[{type:"resume"}];case"dispose":return V.state=j.Disposed,V.buffer=[],V.streamBuffer=i(),[{type:"disposed"}];case"loop":{let J=k,U=V.state;if(J&&(U===j.Scheduled||U===j.Started))V.stopWhen=Number.MAX_SAFE_INTEGER,V.duration=Number.MAX_SAFE_INTEGER;if(V.loop=J,J)n(V,M);return[]}case"loopStart":return V.loopStart=k,[];case"loopEnd":return V.loopEnd=k,[];case"loopCrossfade":return V.loopCrossfade=k,V.enableLoopCrossfade=V.loopCrossfade>0,[];case"playhead":return V.playhead=Math.floor(k),[];case"fadeIn":return V.fadeInDuration=k,V.enableFadeIn=V.fadeInDuration>0,[];case"fadeOut":return V.fadeOutDuration=k,V.enableFadeOut=V.fadeOutDuration>0,[];case"toggleGain":return V.enableGain=k??!V.enableGain,[];case"togglePan":return V.enablePan=k??!V.enablePan,[];case"toggleLowpass":return V.enableLowpass=k??!V.enableLowpass,[];case"toggleHighpass":return V.enableHighpass=k??!V.enableHighpass,[];case"toggleDetune":return V.enableDetune=k??!V.enableDetune,[];case"togglePlaybackRate":return V.enablePlaybackRate=k??!V.enablePlaybackRate,[];case"toggleFadeIn":return V.enableFadeIn=k??!V.enableFadeIn,[];case"toggleFadeOut":return V.enableFadeOut=k??!V.enableFadeOut,[];case"toggleLoopStart":return V.enableLoopStart=k??!V.enableLoopStart,[];case"toggleLoopEnd":return V.enableLoopEnd=k??!V.enableLoopEnd,[];case"toggleLoopCrossfade":return V.enableLoopCrossfade=k??!V.enableLoopCrossfade,[];case"logState":return[]}return[]}function v0(V,A,F,M,T){let k=[],J=V.state;if(J===j.Disposed)return{keepAlive:!1,messages:k};if(y0(V),J===j.Initial)return{keepAlive:!0,messages:k};if(J===j.Ended)return h(A[0]),{keepAlive:!0,messages:k};if(J===j.Scheduled)if(M.currentTime>=V.startWhen)J=V.state=j.Started,k.push({type:"started"});else return h(A[0]),{keepAlive:!0,messages:k};else if(J===j.Paused){if(M.currentTime>V.pauseWhen)return h(A[0]),{keepAlive:!0,messages:k}}if(M.currentTime>V.stopWhen)return h(A[0]),V.state=j.Ended,k.push({type:"ended"}),V.playedSamples=0,{keepAlive:!0,messages:k};let U=A[0],Q=o(V);if(Q===0)return h(U),{keepAlive:!0,messages:k};let{playbackRate:Y,detune:$,lowpass:X,highpass:v,gain:z,pan:C}=F,{buffer:N,loopStart:K,loopEnd:w,loopCrossfade:P,stopWhen:Z,playedSamples:E,enableLowpass:O,enableHighpass:R,enableGain:d,enablePan:b,enableDetune:c,enableFadeOut:g,enableFadeIn:s,enableLoopStart:t,enableLoopEnd:r,enableLoopCrossfade:p,playhead:D,fadeInDuration:F0,fadeOutDuration:k0}=V,K0=V.streamBuffer.streaming&&V.streamBuffer.committedLength<Q,M0=V.loop&&!K0,u=Math.min(N.length,U.length),W0=V.duration*M.sampleRate,Z0=Math.floor(M.sampleRate*P),q0=Math.max(Q-_,0),L=t?Math.min(Math.floor(K*M.sampleRate),q0):0,x=r?Math.min(Math.floor(w*M.sampleRate),Q):Q,N0=x-L,T0=c&&$.length>0&&$[0]!==0,l=Y;if(T0){let G=Math.max(Y.length,$.length,_);l=new Float32Array(G);for(let W=0;W<G;W++){let I=Y[W]??Y[Y.length-1],H=$[W]??$[$.length-1];l[W]=I*2**(H/1200)}}let J0=V.enablePlaybackRate||T0,O0=J0&&l.length>0&&l.every((G)=>G===0);if(V.streamBuffer.streaming&&!V.streamBuffer.streamEnded&&!V.streamBuffer.lowWaterNotified&&V.streamBuffer.committedLength-Math.floor(D)<V.streamBuffer.lowWaterThreshold)k.push({type:"bufferLowWater",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength}}),V.streamBuffer.lowWaterNotified=!0;if(O0){h(U);for(let G=1;G<A.length;G++)G0(U,A[G]);return{keepAlive:!0,messages:k}}let Q0={bufferLength:Q,loop:M0,playhead:D,loopStartSamples:L,loopEndSamples:x,durationSamples:W0,playbackRates:l},{indexes:a,ended:U0,looped:X0,playhead:Y0}=J0?x0(Q0):L0(Q0),f=a.find((G)=>G>=V.streamBuffer.committedLength&&G<Q);if(f!==void 0&&!V.streamBuffer.streamEnded&&V.streamBuffer.lastUnderrunSample!==f)k.push({type:"bufferUnderrun",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength,requestedSample:f}}),V.streamBuffer.lastUnderrunSample=f;else if(f===void 0)V.streamBuffer.lastUnderrunSample=null;m0(U,N,a);let m=Math.min(Math.floor(P*M.sampleRate),N0),D0=M0&&D>L&&D<x,C0=p&&Z0>0&&Q>_;if(D0&&C0){{let G=L+m;if(m>0&&D>L&&D<G){let W=D-L,I=Math.min(Math.floor(G-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.cos(Math.PI*B/2),q=Math.floor(x-m+W+H);if(q>=0&&q<Q)for(let y=0;y<u;y++)U[y][H]+=N[y][q]*S}}}{let G=x-m;if(m>0&&D>G&&D<x){let W=D-G,I=Math.min(Math.floor(x-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.sin(Math.PI*B/2),q=Math.floor(L+W+H);if(q>=0&&q<Q)for(let y=0;y<u;y++)U[y][H]+=N[y][q]*S}}}}if(s&&F0>0){let G=Math.floor(F0*M.sampleRate),W=G-E;if(W>0){let I=Math.min(W,_);for(let H=0;H<I;H++){let B=(E+H)/G,S=B*B*B;for(let q=0;q<u;q++)U[q][H]*=S}}}if(g&&k0>0){let G=Math.floor(k0*M.sampleRate),W=Math.floor(M.sampleRate*(Z-M.currentTime));if(W<G+_)for(let I=0;I<_;I++){let H=W-I;if(H>=G)continue;let B=H<=0?0:H/G,S=B*B*B;for(let q=0;q<u;q++)U[q][I]*=S}}if(O)d0(U,X,M.sampleRate,T.lowpass);if(R)u0(U,v,M.sampleRate,T.highpass);if(d)g0(U,z);if(u===1)S0(U);if(b)h0(U,C);if(X0)V.timesLooped++,k.push({type:"looped",data:V.timesLooped});if(U0)V.state=j.Ended,k.push({type:"ended"});V.playedSamples+=a.length,V.playhead=Y0;let $0=c0(U);if($0>0)return console.log({numNans:$0,indexes:a,playhead:Y0,ended:U0,looped:X0,sourceLength:Q}),{keepAlive:!0,messages:k};for(let G=1;G<A.length;G++)G0(U,A[G]);return{keepAlive:!0,messages:k}}class z0 extends AudioWorkletProcessor{static get parameterDescriptors(){return[{name:"playbackRate",automationRate:"a-rate",defaultValue:1},{name:"detune",automationRate:"a-rate",defaultValue:0},{name:"gain",automationRate:"a-rate",defaultValue:1,minValue:0},{name:"pan",automationRate:"a-rate",defaultValue:0},{name:"highpass",automationRate:"a-rate",defaultValue:20,minValue:20,maxValue:20000},{name:"lowpass",automationRate:"a-rate",defaultValue:20000,minValue:20,maxValue:20000}]}properties;filterState={lowpass:V0(),highpass:V0()};lastFrameTime=0;constructor(V){super(V);this.properties=j0(V?.processorOptions,sampleRate),this.port.onmessage=(A)=>{if(A.data.type==="transferPort"){let M=A.data.data;M.onmessage=(T)=>{let k=A0(this.properties,T.data,currentTime,sampleRate);for(let J of k)this.port.postMessage(J)};return}let F=A0(this.properties,A.data,currentTime,sampleRate);for(let M of F)this.port.postMessage(M);if(this.properties.state===j.Disposed)this.port.close()}}process(V,A,F){try{let M=v0(this.properties,A,F,{currentTime,currentFrame,sampleRate},this.filterState);for(let k of M.messages)this.port.postMessage(k);let T=currentTime-this.lastFrameTime;return this.lastFrameTime=currentTime,this.port.postMessage({type:"frame",data:[currentTime,currentFrame,Math.floor(this.properties.playhead),T*1000]}),M.keepAlive}catch(M){return this.port.postMessage({type:"processorError",data:{error:String(M),state:this.properties.state,bufferChannels:this.properties.buffer?.length,bufferLength:this.properties.buffer?.[0]?.length,paramKeys:Object.keys(F),hasPlaybackRate:!!F.playbackRate,hasDetune:!!F.detune,hasGain:!!F.gain,hasPan:!!F.pan,outputChannels:A[0]?.length}}),!0}}}registerProcessor("ClipProcessor",z0);
2
2
 
3
- //# debugId=12FC7555EABD465B64756E2164756E21
3
+ //# debugId=78F68534B0A72CAE64756E2164756E21
4
4
  //# sourceMappingURL=processor.js.map
@@ -3,10 +3,10 @@
3
3
  "sources": ["../src/audio/types.ts", "../src/audio/processor-kernel.ts", "../src/audio/processor.ts"],
4
4
  "sourcesContent": [
5
5
  "export const State = {\n\tInitial: 0,\n\tStarted: 1,\n\tStopped: 2,\n\tPaused: 3,\n\tScheduled: 4,\n\tEnded: 5,\n\tDisposed: 6,\n} as const;\n\nexport type ClipProcessorState = (typeof State)[keyof typeof State];\n\nexport interface ClipProcessorOptions {\n\tbuffer?: Float32Array[];\n\tstreamBuffer?: StreamBufferState;\n\tloop?: boolean;\n\tloopStart?: number;\n\tloopEnd?: number;\n\tloopCrossfade?: number;\n\toffset?: number;\n\tduration?: number;\n\tplayhead?: number;\n\tstate?: ClipProcessorState;\n\tstartWhen?: number;\n\tstopWhen?: number;\n\tpauseWhen?: number;\n\tresumeWhen?: number;\n\tplayedSamples?: number;\n\ttimesLooped?: number;\n\tfadeInDuration?: number;\n\tfadeOutDuration?: number;\n\tenableFadeIn?: boolean;\n\tenableFadeOut?: boolean;\n\tenableLoopStart?: boolean;\n\tenableLoopEnd?: boolean;\n\tenableLoopCrossfade?: boolean;\n\tenableGain?: boolean;\n\tenablePan?: boolean;\n\tenableHighpass?: boolean;\n\tenableLowpass?: boolean;\n\tenableDetune?: boolean;\n\tenablePlaybackRate?: boolean;\n}\n\nexport interface ClipWorkletOptions extends AudioWorkletNodeOptions {\n\tprocessorOptions?: ClipProcessorOptions;\n}\n\nexport type ClipNodeState =\n\t| \"initial\"\n\t| \"scheduled\"\n\t| \"started\"\n\t| \"stopped\"\n\t| \"paused\"\n\t| \"resumed\"\n\t| \"ended\"\n\t| \"disposed\";\n\nexport type FrameData = readonly [\n\tcurrentTime: number,\n\tcurrentFrame: number,\n\tplayhead: number,\n\ttimeTaken: number,\n];\n\nexport type ClipProcessorToggleMessageType =\n\t| \"toggleFadeIn\"\n\t| \"toggleFadeOut\"\n\t| \"toggleLoopStart\"\n\t| \"toggleLoopEnd\"\n\t| \"toggleLoopCrossfade\"\n\t| \"toggleGain\"\n\t| \"togglePan\"\n\t| \"toggleHighpass\"\n\t| \"toggleLowpass\"\n\t| \"toggleDetune\"\n\t| \"togglePlaybackRate\";\n\n// ---------------------------------------------------------------------------\n// Processor message types (moved from processor.ts)\n// ---------------------------------------------------------------------------\n\nexport interface ClipProcessorOnmessageEvent {\n\treadonly data: ClipProcessorMessageRx;\n}\n\nexport type ClipProcessorOnmessage = (ev: ClipProcessorOnmessageEvent) => void;\n\nexport interface ProcessorWorkletOptions extends AudioWorkletNodeOptions {\n\treadonly processorOptions?: ClipProcessorOptions;\n}\n\nexport interface ClipProcessorStateMap {\n\treadonly Initial: 0;\n\treadonly Started: 1;\n\treadonly Stopped: 2;\n\treadonly Paused: 3;\n\treadonly Scheduled: 4;\n\treadonly Ended: 5;\n\treadonly Disposed: 6;\n}\n\nexport type ClipProcessorMessageRx =\n\t| ClipProcessorBufferMessageRx\n\t| ClipProcessorBufferInitMessageRx\n\t| ClipProcessorBufferRangeMessageRx\n\t| ClipProcessorBufferEndMessageRx\n\t| ClipProcessorBufferResetMessageRx\n\t| ClipProcessorStartMessageRx\n\t| ClipProcessorStopMessageRx\n\t| ClipProcessorPauseMessageRx\n\t| ClipProcessorResumeMessageRx\n\t| ClipProcessorDisposeMessageRx\n\t| ClipProcessorLoopMessageRx\n\t| ClipProcessorLoopStartMessageRx\n\t| ClipProcessorLoopEndMessageRx\n\t| ClipProcessorPlayheadMessageRx\n\t| ClipProcessorFadeInMessageRx\n\t| ClipProcessorFadeOutMessageRx\n\t| ClipProcessorLoopCrossfadeMessageRx\n\t| ClipProcessorToggleMessageRx\n\t| ClipProcessorLogStateMessageRx;\n\nexport type ClipProcessorMessageType =\n\t| \"buffer\"\n\t| \"bufferInit\"\n\t| \"bufferRange\"\n\t| \"bufferEnd\"\n\t| \"bufferReset\"\n\t| \"start\"\n\t| \"stop\"\n\t| \"pause\"\n\t| \"resume\"\n\t| \"dispose\"\n\t| \"loop\"\n\t| \"loopStart\"\n\t| \"loopEnd\"\n\t| \"playhead\"\n\t| \"playbackRate\"\n\t| \"offset\"\n\t| \"fadeIn\"\n\t| \"fadeOut\"\n\t| \"loopCrossfade\"\n\t| ClipProcessorToggleMessageType\n\t| \"logState\";\n\nexport interface ClipProcessorLogStateMessageRx {\n\treadonly type: \"logState\";\n\treadonly data?: never;\n}\n\nexport interface ClipProcessorToggleMessageRx {\n\treadonly type: ClipProcessorToggleMessageType;\n\treadonly data?: boolean;\n}\n\nexport interface ClipProcessorBufferMessageRx {\n\treadonly type: \"buffer\";\n\treadonly data: Float32Array[];\n}\n\nexport interface StreamBufferSpan {\n\tstartSample: number;\n\tendSample: number;\n}\n\nexport interface BufferRangeWrite {\n\treadonly startSample: number;\n\treadonly channelData: Float32Array[];\n\treadonly totalLength?: number | null;\n\treadonly streamEnded?: boolean;\n}\n\nexport interface StreamBufferState {\n\ttotalLength: number | null;\n\tcommittedLength: number;\n\tstreamEnded: boolean;\n\tstreaming: boolean;\n\twrittenSpans: StreamBufferSpan[];\n\tpendingWrites: BufferRangeWrite[];\n\tlowWaterThreshold: number;\n\tlowWaterNotified: boolean;\n\tlastUnderrunSample: number | null;\n}\n\nexport interface ClipProcessorBufferInitMessageRx {\n\treadonly type: \"bufferInit\";\n\treadonly data: {\n\t\treadonly channels: number;\n\t\treadonly totalLength: number;\n\t\treadonly streaming?: boolean;\n\t};\n}\n\nexport interface ClipProcessorBufferRangeMessageRx {\n\treadonly type: \"bufferRange\";\n\treadonly data: BufferRangeWrite;\n}\n\nexport interface ClipProcessorBufferEndMessageRx {\n\treadonly type: \"bufferEnd\";\n\treadonly data?: {\n\t\treadonly totalLength?: number;\n\t};\n}\n\nexport interface ClipProcessorBufferResetMessageRx {\n\treadonly type: \"bufferReset\";\n\treadonly data?: never;\n}\n\nexport interface ClipProcessorStartMessageRx {\n\treadonly type: \"start\";\n\treadonly data?: {\n\t\treadonly duration?: number;\n\t\treadonly offset?: number;\n\t\treadonly when?: number;\n\t};\n}\n\nexport interface ClipProcessorStopMessageRx {\n\treadonly type: \"stop\";\n\treadonly data?: number;\n}\n\nexport interface ClipProcessorPauseMessageRx {\n\treadonly type: \"pause\";\n\treadonly data?: number;\n}\n\nexport interface ClipProcessorResumeMessageRx {\n\treadonly type: \"resume\";\n\treadonly data?: number;\n}\n\nexport interface ClipProcessorDisposeMessageRx {\n\treadonly type: \"dispose\";\n\treadonly data?: never;\n}\n\nexport interface ClipProcessorLoopMessageRx {\n\treadonly type: \"loop\";\n\treadonly data: boolean;\n}\n\nexport interface ClipProcessorLoopStartMessageRx {\n\treadonly type: \"loopStart\";\n\treadonly data: number;\n}\n\nexport interface ClipProcessorLoopEndMessageRx {\n\treadonly type: \"loopEnd\";\n\treadonly data: number;\n}\n\nexport interface ClipProcessorPlayheadMessageRx {\n\treadonly type: \"playhead\";\n\treadonly data: number;\n}\n\nexport interface ClipProcessorFadeInMessageRx {\n\treadonly type: \"fadeIn\";\n\treadonly data: number;\n}\n\nexport interface ClipProcessorFadeOutMessageRx {\n\treadonly type: \"fadeOut\";\n\treadonly data: number;\n}\n\nexport interface ClipProcessorLoopCrossfadeMessageRx {\n\treadonly type: \"loopCrossfade\";\n\treadonly data: number;\n}\n\n// ---------------------------------------------------------------------------\n// Block parameters (used by kernel)\n// ---------------------------------------------------------------------------\n\nexport interface BlockParameters {\n\treadonly playhead: number;\n\treadonly durationSamples: number;\n\treadonly loop: boolean;\n\treadonly loopStartSamples: number;\n\treadonly loopEndSamples: number;\n\treadonly bufferLength: number;\n\treadonly playbackRates: Float32Array;\n}\n\nexport interface BlockReturnState {\n\treadonly playhead: number;\n\treadonly ended: boolean;\n\treadonly looped: boolean;\n\treadonly indexes: number[];\n}\n",
6
- "// processor-kernel.ts — Pure DSP logic, state machine, all filters\n// NO AudioWorklet or platform dependencies. Fully testable.\n\nimport {\n\ttype BlockParameters,\n\ttype BlockReturnState,\n\ttype BufferRangeWrite,\n\ttype ClipProcessorOptions,\n\tState,\n\ttype StreamBufferSpan,\n\ttype StreamBufferState,\n} from \"./types\";\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nexport const SAMPLE_BLOCK_SIZE = 128;\n\nfunction createStreamBufferState(\n\tbuffer: Float32Array[] = [],\n): StreamBufferState {\n\tconst totalLength = buffer[0]?.length ?? 0;\n\tconst hasBuffer = totalLength > 0;\n\treturn {\n\t\ttotalLength: hasBuffer ? totalLength : null,\n\t\tcommittedLength: hasBuffer ? totalLength : 0,\n\t\tstreamEnded: hasBuffer,\n\t\tstreaming: false,\n\t\twrittenSpans: hasBuffer ? [{ startSample: 0, endSample: totalLength }] : [],\n\t\tpendingWrites: [],\n\t\tlowWaterThreshold: SAMPLE_BLOCK_SIZE * 4,\n\t\tlowWaterNotified: false,\n\t\tlastUnderrunSample: null,\n\t};\n}\n\nfunction getBufferLength(buffer: Float32Array[]): number {\n\treturn buffer[0]?.length ?? 0;\n}\n\nfunction getLogicalBufferLength(\n\tproperties: Required<ClipProcessorOptions>,\n): number {\n\treturn (\n\t\tproperties.streamBuffer.totalLength ?? getBufferLength(properties.buffer)\n\t);\n}\n\nfunction createSilentBuffer(channels: number, length: number): Float32Array[] {\n\treturn Array.from({ length: channels }, () => new Float32Array(length));\n}\n\nfunction mergeWrittenSpan(\n\tspans: StreamBufferSpan[],\n\tnextSpan: StreamBufferSpan,\n): StreamBufferSpan[] {\n\tconst merged = [...spans, nextSpan].sort(\n\t\t(a, b) => a.startSample - b.startSample,\n\t);\n\tconst result: StreamBufferSpan[] = [];\n\tfor (const span of merged) {\n\t\tconst previous = result[result.length - 1];\n\t\tif (!previous || span.startSample > previous.endSample) {\n\t\t\tresult.push({ ...span });\n\t\t\tcontinue;\n\t\t}\n\t\tprevious.endSample = Math.max(previous.endSample, span.endSample);\n\t}\n\treturn result;\n}\n\nfunction getCommittedLength(spans: StreamBufferSpan[]): number {\n\tlet committedLength = 0;\n\tfor (const span of spans) {\n\t\tif (span.startSample > committedLength) break;\n\t\tcommittedLength = Math.max(committedLength, span.endSample);\n\t}\n\treturn committedLength;\n}\n\nfunction resetLowWaterState(\n\tstreamBuffer: StreamBufferState,\n\tplayhead: number,\n): void {\n\tif (\n\t\tstreamBuffer.committedLength - Math.floor(playhead) >=\n\t\tstreamBuffer.lowWaterThreshold\n\t) {\n\t\tstreamBuffer.lowWaterNotified = false;\n\t}\n}\n\nfunction ensureBufferCapacity(\n\tproperties: Required<ClipProcessorOptions>,\n\trequiredChannels: number,\n\trequiredLength: number,\n): void {\n\tconst currentLength = getBufferLength(properties.buffer);\n\tconst currentChannels = properties.buffer.length;\n\tif (currentLength >= requiredLength && currentChannels >= requiredChannels) {\n\t\treturn;\n\t}\n\n\tconst nextLength = Math.max(currentLength, requiredLength);\n\tconst nextChannels = Math.max(currentChannels, requiredChannels);\n\tconst nextBuffer = createSilentBuffer(nextChannels, nextLength);\n\tfor (let ch = 0; ch < currentChannels; ch++) {\n\t\tnextBuffer[ch].set(properties.buffer[ch].subarray(0, currentLength));\n\t}\n\tproperties.buffer = nextBuffer;\n\tif (\n\t\tproperties.streamBuffer.totalLength == null ||\n\t\tproperties.streamBuffer.totalLength < nextLength\n\t) {\n\t\tproperties.streamBuffer.totalLength = nextLength;\n\t}\n}\n\nfunction applyBufferRangeWrite(\n\tproperties: Required<ClipProcessorOptions>,\n\twrite: BufferRangeWrite,\n): void {\n\tconst startSample = Math.max(Math.floor(write.startSample), 0);\n\tconst writeLength = write.channelData[0]?.length ?? 0;\n\tconst requestedTotalLength = write.totalLength ?? null;\n\tconst requiredLength = Math.max(\n\t\tstartSample + writeLength,\n\t\trequestedTotalLength ?? 0,\n\t);\n\tensureBufferCapacity(\n\t\tproperties,\n\t\tMath.max(write.channelData.length, properties.buffer.length, 1),\n\t\trequiredLength,\n\t);\n\n\tfor (let ch = 0; ch < write.channelData.length; ch++) {\n\t\tproperties.buffer[ch].set(write.channelData[ch], startSample);\n\t}\n\n\tif (requestedTotalLength != null) {\n\t\tproperties.streamBuffer.totalLength = requestedTotalLength;\n\t}\n\tif (writeLength > 0) {\n\t\tproperties.streamBuffer.writtenSpans = mergeWrittenSpan(\n\t\t\tproperties.streamBuffer.writtenSpans,\n\t\t\t{ startSample, endSample: startSample + writeLength },\n\t\t);\n\t\tproperties.streamBuffer.committedLength = getCommittedLength(\n\t\t\tproperties.streamBuffer.writtenSpans,\n\t\t);\n\t}\n\tif (write.streamEnded === true) {\n\t\tproperties.streamBuffer.streamEnded = true;\n\t}\n\tresetLowWaterState(properties.streamBuffer, properties.playhead);\n}\n\nfunction applyPendingBufferWrites(\n\tproperties: Required<ClipProcessorOptions>,\n): void {\n\tif (properties.streamBuffer.pendingWrites.length === 0) {\n\t\treturn;\n\t}\n\tfor (const write of properties.streamBuffer.pendingWrites) {\n\t\tapplyBufferRangeWrite(properties, write);\n\t}\n\tproperties.streamBuffer.pendingWrites = [];\n}\n\nfunction setWholeBuffer(\n\tproperties: Required<ClipProcessorOptions>,\n\tbuffer: Float32Array[],\n): void {\n\tproperties.buffer = buffer;\n\tproperties.streamBuffer = createStreamBufferState(buffer);\n}\n\n// ---------------------------------------------------------------------------\n// Properties & offset\n// ---------------------------------------------------------------------------\n\nexport function getProperties(\n\topts: ClipProcessorOptions = {},\n\tsampleRate: number,\n): Required<ClipProcessorOptions> {\n\tconst {\n\t\tbuffer = [],\n\t\tstreamBuffer = createStreamBufferState(buffer),\n\t\tduration = -1,\n\t\tloop = false,\n\t\tloopStart = 0,\n\t\tloopEnd = (buffer[0]?.length ?? 0) / sampleRate,\n\t\tloopCrossfade = 0,\n\t\tplayhead = 0,\n\t\toffset = 0,\n\t\tstartWhen = 0,\n\t\tstopWhen = 0,\n\t\tpauseWhen = 0,\n\t\tresumeWhen = 0,\n\t\tplayedSamples = 0,\n\t\tstate = State.Initial,\n\t\ttimesLooped = 0,\n\t\tfadeInDuration = 0,\n\t\tfadeOutDuration = 0,\n\t\tenableFadeIn = fadeInDuration > 0,\n\t\tenableFadeOut = fadeOutDuration > 0,\n\t\tenableLoopStart = true,\n\t\tenableLoopEnd = true,\n\t\tenableLoopCrossfade = loopCrossfade > 0,\n\t\tenableHighpass = true,\n\t\tenableLowpass = true,\n\t\tenableGain = true,\n\t\tenablePan = true,\n\t\tenableDetune = true,\n\t\tenablePlaybackRate = true,\n\t} = opts;\n\n\treturn {\n\t\tbuffer,\n\t\tstreamBuffer,\n\t\tloop,\n\t\tloopStart,\n\t\tloopEnd,\n\t\tloopCrossfade,\n\t\tduration,\n\t\tplayhead,\n\t\toffset,\n\t\tstartWhen,\n\t\tstopWhen,\n\t\tpauseWhen,\n\t\tresumeWhen,\n\t\tplayedSamples,\n\t\tstate,\n\t\ttimesLooped,\n\t\tfadeInDuration,\n\t\tfadeOutDuration,\n\t\tenableFadeIn,\n\t\tenableFadeOut,\n\t\tenableLoopStart,\n\t\tenableLoopEnd,\n\t\tenableHighpass,\n\t\tenableLowpass,\n\t\tenableGain,\n\t\tenablePan,\n\t\tenableDetune,\n\t\tenablePlaybackRate,\n\t\tenableLoopCrossfade,\n\t};\n}\n\nfunction getBufferDurationSeconds(\n\tproperties: Required<ClipProcessorOptions>,\n\tsampleRate: number,\n): number {\n\treturn getLogicalBufferLength(properties) / sampleRate;\n}\n\nfunction normalizeLoopBounds(\n\tproperties: Required<ClipProcessorOptions>,\n\tsampleRate: number,\n): void {\n\tconst bufferDuration = getBufferDurationSeconds(properties, sampleRate);\n\tif (bufferDuration <= 0) {\n\t\tproperties.loopStart = 0;\n\t\tproperties.loopEnd = 0;\n\t\treturn;\n\t}\n\n\tif (!Number.isFinite(properties.loopStart) || properties.loopStart < 0) {\n\t\tproperties.loopStart = 0;\n\t}\n\tif (properties.loopStart >= bufferDuration) {\n\t\tproperties.loopStart = 0;\n\t}\n\tif (\n\t\t!Number.isFinite(properties.loopEnd) ||\n\t\tproperties.loopEnd <= properties.loopStart ||\n\t\tproperties.loopEnd > bufferDuration\n\t) {\n\t\tproperties.loopEnd = bufferDuration;\n\t}\n}\n\nexport function setOffset(\n\tproperties: Required<ClipProcessorOptions>,\n\toffset: number | undefined,\n\tsampleRate: number,\n): number {\n\tif (offset === undefined) {\n\t\tproperties.offset = 0;\n\t\treturn 0;\n\t}\n\tif (offset < 0) {\n\t\treturn setOffset(\n\t\t\tproperties,\n\t\t\tgetLogicalBufferLength(properties) + offset,\n\t\t\tsampleRate,\n\t\t);\n\t}\n\tif (offset > (getLogicalBufferLength(properties) || 1) - 1) {\n\t\treturn setOffset(\n\t\t\tproperties,\n\t\t\tgetLogicalBufferLength(properties) % offset,\n\t\t\tsampleRate,\n\t\t);\n\t}\n\tconst offs = Math.floor(offset * sampleRate);\n\tproperties.offset = offs;\n\treturn offs;\n}\n\n// ---------------------------------------------------------------------------\n// Index calculation\n// ---------------------------------------------------------------------------\n\nexport function findIndexesNormal(p: BlockParameters): BlockReturnState {\n\tconst { playhead, bufferLength, loop, loopStartSamples, loopEndSamples } = p;\n\tlet length = 128;\n\tif (!loop && playhead + 128 > bufferLength) {\n\t\tlength = Math.max(bufferLength - playhead, 0);\n\t}\n\tconst indexes: number[] = new Array(length);\n\n\tif (!loop) {\n\t\tfor (let i = 0, head = playhead; i < length; i++, head++) {\n\t\t\tindexes[i] = head;\n\t\t}\n\t\tconst nextPlayhead = playhead + length;\n\t\treturn {\n\t\t\tplayhead: nextPlayhead,\n\t\t\tindexes,\n\t\t\tlooped: false,\n\t\t\tended: nextPlayhead >= bufferLength,\n\t\t};\n\t}\n\n\tlet head = playhead;\n\tlet looped = false;\n\tfor (let i = 0; i < length; i++, head++) {\n\t\tif (head >= loopEndSamples) {\n\t\t\thead = loopStartSamples + (head - loopEndSamples);\n\t\t\tlooped = true;\n\t\t}\n\t\tindexes[i] = head;\n\t}\n\treturn { indexes, looped, ended: false, playhead: head };\n}\n\nexport function findIndexesWithPlaybackRates(\n\tp: BlockParameters,\n): BlockReturnState {\n\tconst {\n\t\tplayhead,\n\t\tbufferLength,\n\t\tloop,\n\t\tloopStartSamples,\n\t\tloopEndSamples,\n\t\tplaybackRates,\n\t} = p;\n\tlet length = 128;\n\tif (!loop && playhead + 128 > bufferLength) {\n\t\tlength = Math.max(bufferLength - playhead, 0);\n\t}\n\tconst indexes: number[] = new Array(length);\n\tlet head = playhead;\n\tlet looped = false;\n\n\tif (loop) {\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tindexes[i] = Math.min(Math.max(Math.floor(head), 0), bufferLength - 1);\n\t\t\tconst rate = playbackRates[i] ?? playbackRates[0] ?? 1;\n\t\t\thead += rate;\n\t\t\tif (rate >= 0 && (head > loopEndSamples || head > bufferLength)) {\n\t\t\t\thead = loopStartSamples;\n\t\t\t\tlooped = true;\n\t\t\t} else if (rate < 0 && (head < loopStartSamples || head < 0)) {\n\t\t\t\thead = loopEndSamples;\n\t\t\t\tlooped = true;\n\t\t\t}\n\t\t}\n\t\treturn { playhead: head, indexes, looped, ended: false };\n\t}\n\n\tfor (let i = 0; i < length; i++) {\n\t\tindexes[i] = Math.min(Math.max(Math.floor(head), 0), bufferLength - 1);\n\t\thead += playbackRates[i] ?? playbackRates[0] ?? 1;\n\t}\n\treturn {\n\t\tplayhead: head,\n\t\tindexes,\n\t\tlooped: false,\n\t\tended: head >= bufferLength || head < 0,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Buffer operations\n// ---------------------------------------------------------------------------\n\nexport function fill(\n\ttarget: Float32Array[],\n\tsource: Float32Array[],\n\tindexes: number[],\n): void {\n\tconst nc = Math.min(target.length, source.length);\n\tfor (let i = 0; i < indexes.length; i++) {\n\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\ttarget[ch][i] = source[ch][indexes[i]];\n\t\t}\n\t}\n\tfor (let ch = nc; ch < target.length; ch++) {\n\t\tfor (let i = 0; i < target[ch].length; i++) {\n\t\t\ttarget[ch][i] = 0;\n\t\t}\n\t}\n\tfor (let i = indexes.length; i < target[0].length; i++) {\n\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\ttarget[ch][i] = 0;\n\t\t}\n\t}\n}\n\nexport function fillWithSilence(buffer: Float32Array[]): void {\n\tfor (let ch = 0; ch < buffer.length; ch++) {\n\t\tfor (let j = 0; j < buffer[ch].length; j++) {\n\t\t\tbuffer[ch][j] = 0;\n\t\t}\n\t}\n}\n\nexport function monoToStereo(signal: Float32Array[]): void {\n\tif (signal.length >= 2) {\n\t\t// Output already has a second channel — copy mono data into it\n\t\tfor (let i = 0; i < signal[0].length; i++) {\n\t\t\tsignal[1][i] = signal[0][i];\n\t\t}\n\t} else {\n\t\tconst r = new Float32Array(signal[0].length);\n\t\tfor (let i = 0; i < signal[0].length; i++) {\n\t\t\tr[i] = signal[0][i];\n\t\t}\n\t\tsignal.push(r);\n\t}\n}\n\nexport function copy(source: Float32Array[], target: Float32Array[]): void {\n\tfor (let i = target.length; i < source.length; i++) {\n\t\ttarget[i] = new Float32Array(source[i].length);\n\t}\n\tfor (let ch = 0; ch < source.length; ch++) {\n\t\tfor (let i = 0; i < source[ch].length; i++) {\n\t\t\ttarget[ch][i] = source[ch][i];\n\t\t}\n\t}\n}\n\nexport function checkNans(output: Float32Array[]): number {\n\tlet numNans = 0;\n\tfor (let ch = 0; ch < output.length; ch++) {\n\t\tfor (let j = 0; j < output[ch].length; j++) {\n\t\t\tif (Number.isNaN(output[ch][j])) {\n\t\t\t\tnumNans++;\n\t\t\t\toutput[ch][j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn numNans;\n}\n\n// ---------------------------------------------------------------------------\n// Filters\n// ---------------------------------------------------------------------------\n\nexport interface BiquadState {\n\tx_1: number;\n\tx_2: number;\n\ty_1: number;\n\ty_2: number;\n}\n\nexport function createFilterState(): BiquadState[] {\n\treturn [\n\t\t{ x_1: 0, x_2: 0, y_1: 0, y_2: 0 },\n\t\t{ x_1: 0, x_2: 0, y_1: 0, y_2: 0 },\n\t];\n}\n\nexport function gainFilter(arr: Float32Array[], gains: Float32Array): void {\n\tif (gains.length === 1) {\n\t\tconst g = gains[0];\n\t\tif (g === 1) return;\n\t\tfor (const ch of arr) {\n\t\t\tfor (let i = 0; i < ch.length; i++) ch[i] *= g;\n\t\t}\n\t\treturn;\n\t}\n\tlet g = gains[0];\n\tfor (const ch of arr) {\n\t\tfor (let i = 0; i < ch.length; i++) {\n\t\t\tg = gains[i] ?? g;\n\t\t\tch[i] *= g;\n\t\t}\n\t}\n}\n\nexport function panFilter(signal: Float32Array[], pans: Float32Array): void {\n\tlet pan = pans[0];\n\tfor (let i = 0; i < signal[0].length; i++) {\n\t\tpan = pans[i] ?? pan;\n\t\tconst leftGain = pan <= 0 ? 1 : 1 - pan;\n\t\tconst rightGain = pan >= 0 ? 1 : 1 + pan;\n\t\tsignal[0][i] *= leftGain;\n\t\tsignal[1][i] *= rightGain;\n\t}\n}\n\nexport function lowpassFilter(\n\tbuffer: Float32Array[],\n\tcutoffs: Float32Array,\n\tsampleRate: number,\n\tstates: BiquadState[],\n): void {\n\tfor (let channel = 0; channel < buffer.length; channel++) {\n\t\tconst arr = buffer[channel];\n\t\tlet { x_1, x_2, y_1, y_2 } = states[channel] ?? {\n\t\t\tx_1: 0,\n\t\t\tx_2: 0,\n\t\t\ty_1: 0,\n\t\t\ty_2: 0,\n\t\t};\n\t\tif (cutoffs.length === 1) {\n\t\t\tconst cutoff = cutoffs[0];\n\t\t\tif (cutoff >= 20000) return;\n\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\tconst b0 = (1 - Math.cos(w0)) / 2;\n\t\t\tconst b1 = 1 - Math.cos(w0);\n\t\t\tconst b2 = (1 - Math.cos(w0)) / 2;\n\t\t\tconst a0 = 1 + alpha;\n\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\tconst a2 = 1 - alpha;\n\t\t\tconst h0 = b0 / a0,\n\t\t\t\th1 = b1 / a0,\n\t\t\t\th2 = b2 / a0,\n\t\t\t\th3 = a1 / a0,\n\t\t\t\th4 = a2 / a0;\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y = h0 * x + h1 * x_1 + h2 * x_2 - h3 * y_1 - h4 * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t} else {\n\t\t\tconst prevCutoff = cutoffs[0];\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst cutoff = cutoffs[i] ?? prevCutoff;\n\t\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\t\tconst b0 = (1 - Math.cos(w0)) / 2;\n\t\t\t\tconst b1 = 1 - Math.cos(w0);\n\t\t\t\tconst b2 = (1 - Math.cos(w0)) / 2;\n\t\t\t\tconst a0 = 1 + alpha;\n\t\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\t\tconst a2 = 1 - alpha;\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y =\n\t\t\t\t\t(b0 / a0) * x +\n\t\t\t\t\t(b1 / a0) * x_1 +\n\t\t\t\t\t(b2 / a0) * x_2 -\n\t\t\t\t\t(a1 / a0) * y_1 -\n\t\t\t\t\t(a2 / a0) * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t}\n\t\tstates[channel] = { x_1, x_2, y_1, y_2 };\n\t}\n}\n\nexport function highpassFilter(\n\tbuffer: Float32Array[],\n\tcutoffs: Float32Array,\n\tsampleRate: number,\n\tstates: BiquadState[],\n): void {\n\tfor (let channel = 0; channel < buffer.length; channel++) {\n\t\tconst arr = buffer[channel];\n\t\tlet { x_1, x_2, y_1, y_2 } = states[channel] ?? {\n\t\t\tx_1: 0,\n\t\t\tx_2: 0,\n\t\t\ty_1: 0,\n\t\t\ty_2: 0,\n\t\t};\n\t\tif (cutoffs.length === 1) {\n\t\t\tconst cutoff = cutoffs[0];\n\t\t\tif (cutoff <= 20) return;\n\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\tconst b0 = (1 + Math.cos(w0)) / 2;\n\t\t\tconst b1 = -(1 + Math.cos(w0));\n\t\t\tconst b2 = (1 + Math.cos(w0)) / 2;\n\t\t\tconst a0 = 1 + alpha;\n\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\tconst a2 = 1 - alpha;\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y =\n\t\t\t\t\t(b0 / a0) * x +\n\t\t\t\t\t(b1 / a0) * x_1 +\n\t\t\t\t\t(b2 / a0) * x_2 -\n\t\t\t\t\t(a1 / a0) * y_1 -\n\t\t\t\t\t(a2 / a0) * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t} else {\n\t\t\tconst prevCutoff = cutoffs[0];\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst cutoff = cutoffs[i] ?? prevCutoff;\n\t\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\t\tconst b0 = (1 + Math.cos(w0)) / 2;\n\t\t\t\tconst b1 = -(1 + Math.cos(w0));\n\t\t\t\tconst b2 = (1 + Math.cos(w0)) / 2;\n\t\t\t\tconst a0 = 1 + alpha;\n\t\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\t\tconst a2 = 1 - alpha;\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y =\n\t\t\t\t\t(b0 / a0) * x +\n\t\t\t\t\t(b1 / a0) * x_1 +\n\t\t\t\t\t(b2 / a0) * x_2 -\n\t\t\t\t\t(a1 / a0) * y_1 -\n\t\t\t\t\t(a2 / a0) * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t}\n\t\tstates[channel] = { x_1, x_2, y_1, y_2 };\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Message handler\n// ---------------------------------------------------------------------------\n\nexport interface OutboundMessage {\n\ttype: string;\n\tdata?: unknown;\n}\n\nexport function handleProcessorMessage(\n\tproperties: Required<ClipProcessorOptions>,\n\tmessage: { type: string; data?: unknown },\n\tcurrentTime: number,\n\tsampleRate: number,\n): OutboundMessage[] {\n\tconst { type, data } = message;\n\tswitch (type) {\n\t\tcase \"buffer\":\n\t\t\tsetWholeBuffer(properties, data as Float32Array[]);\n\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\treturn [];\n\t\tcase \"bufferInit\": {\n\t\t\tconst init = data as {\n\t\t\t\tchannels: number;\n\t\t\t\ttotalLength: number;\n\t\t\t\tstreaming?: boolean;\n\t\t\t};\n\t\t\tproperties.buffer = createSilentBuffer(init.channels, init.totalLength);\n\t\t\tproperties.streamBuffer = {\n\t\t\t\t...createStreamBufferState(),\n\t\t\t\ttotalLength: init.totalLength,\n\t\t\t\tstreamEnded: false,\n\t\t\t\tstreaming: init.streaming ?? true,\n\t\t\t};\n\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\treturn [];\n\t\t}\n\t\tcase \"bufferRange\":\n\t\t\tproperties.streamBuffer.pendingWrites.push(data as BufferRangeWrite);\n\t\t\treturn [];\n\t\tcase \"bufferEnd\": {\n\t\t\tconst endData = data as { totalLength?: number } | undefined;\n\t\t\tif (endData?.totalLength != null) {\n\t\t\t\tproperties.streamBuffer.totalLength = endData.totalLength;\n\t\t\t}\n\t\t\tproperties.streamBuffer.streamEnded = true;\n\t\t\treturn [];\n\t\t}\n\t\tcase \"bufferReset\":\n\t\t\tproperties.buffer = [];\n\t\t\tproperties.streamBuffer = createStreamBufferState();\n\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\treturn [];\n\t\tcase \"start\":\n\t\t\tproperties.timesLooped = 0;\n\t\t\t{\n\t\t\t\tconst d = data as\n\t\t\t\t\t| { duration?: number; offset?: number; when?: number }\n\t\t\t\t\t| undefined;\n\t\t\t\tproperties.duration = d?.duration ?? -1;\n\t\t\t\tif (properties.duration === -1) {\n\t\t\t\t\tproperties.duration = properties.loop\n\t\t\t\t\t\t? Number.MAX_SAFE_INTEGER\n\t\t\t\t\t\t: (properties.buffer[0]?.length ?? 0) / sampleRate;\n\t\t\t\t}\n\t\t\t\tsetOffset(properties, d?.offset, sampleRate);\n\t\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\t\tproperties.playhead = properties.offset;\n\t\t\t\tproperties.startWhen = d?.when ?? currentTime;\n\t\t\t\tproperties.stopWhen = properties.startWhen + properties.duration;\n\t\t\t\tproperties.playedSamples = 0;\n\t\t\t\tproperties.state = State.Scheduled;\n\t\t\t}\n\t\t\treturn [{ type: \"scheduled\" }];\n\t\tcase \"stop\":\n\t\t\tif (\n\t\t\t\tproperties.state === State.Ended ||\n\t\t\t\tproperties.state === State.Initial\n\t\t\t)\n\t\t\t\treturn [];\n\t\t\tproperties.stopWhen = (data as number | undefined) ?? properties.stopWhen;\n\t\t\tproperties.state = State.Stopped;\n\t\t\treturn [{ type: \"stopped\" }];\n\t\tcase \"pause\":\n\t\t\tproperties.state = State.Paused;\n\t\t\tproperties.pauseWhen = (data as number | undefined) ?? currentTime;\n\t\t\treturn [{ type: \"paused\" }];\n\t\tcase \"resume\":\n\t\t\tproperties.state = State.Started;\n\t\t\tproperties.startWhen = (data as number | undefined) ?? currentTime;\n\t\t\treturn [{ type: \"resume\" }];\n\t\tcase \"dispose\":\n\t\t\tproperties.state = State.Disposed;\n\t\t\tproperties.buffer = [];\n\t\t\tproperties.streamBuffer = createStreamBufferState();\n\t\t\treturn [{ type: \"disposed\" }];\n\t\tcase \"loop\": {\n\t\t\tconst loop = data as boolean;\n\t\t\tconst st = properties.state;\n\t\t\tif (loop && (st === State.Scheduled || st === State.Started)) {\n\t\t\t\tproperties.stopWhen = Number.MAX_SAFE_INTEGER;\n\t\t\t\tproperties.duration = Number.MAX_SAFE_INTEGER;\n\t\t\t}\n\t\t\tproperties.loop = loop;\n\t\t\tif (loop) {\n\t\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\t}\n\t\t\treturn [];\n\t\t}\n\t\tcase \"loopStart\":\n\t\t\tproperties.loopStart = data as number;\n\t\t\treturn [];\n\t\tcase \"loopEnd\":\n\t\t\tproperties.loopEnd = data as number;\n\t\t\treturn [];\n\t\tcase \"loopCrossfade\":\n\t\t\tproperties.loopCrossfade = data as number;\n\t\t\treturn [];\n\t\tcase \"playhead\":\n\t\t\tproperties.playhead = Math.floor(data as number);\n\t\t\treturn [];\n\t\tcase \"fadeIn\":\n\t\t\tproperties.fadeInDuration = data as number;\n\t\t\treturn [];\n\t\tcase \"fadeOut\":\n\t\t\tproperties.fadeOutDuration = data as number;\n\t\t\treturn [];\n\t\tcase \"toggleGain\":\n\t\t\tproperties.enableGain =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableGain;\n\t\t\treturn [];\n\t\tcase \"togglePan\":\n\t\t\tproperties.enablePan =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enablePan;\n\t\t\treturn [];\n\t\tcase \"toggleLowpass\":\n\t\t\tproperties.enableLowpass =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLowpass;\n\t\t\treturn [];\n\t\tcase \"toggleHighpass\":\n\t\t\tproperties.enableHighpass =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableHighpass;\n\t\t\treturn [];\n\t\tcase \"toggleDetune\":\n\t\t\tproperties.enableDetune =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableDetune;\n\t\t\treturn [];\n\t\tcase \"togglePlaybackRate\":\n\t\t\tproperties.enablePlaybackRate =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enablePlaybackRate;\n\t\t\treturn [];\n\t\tcase \"toggleFadeIn\":\n\t\t\tproperties.enableFadeIn =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableFadeIn;\n\t\t\treturn [];\n\t\tcase \"toggleFadeOut\":\n\t\t\tproperties.enableFadeOut =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableFadeOut;\n\t\t\treturn [];\n\t\tcase \"toggleLoopStart\":\n\t\t\tproperties.enableLoopStart =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLoopStart;\n\t\t\treturn [];\n\t\tcase \"toggleLoopEnd\":\n\t\t\tproperties.enableLoopEnd =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLoopEnd;\n\t\t\treturn [];\n\t\tcase \"toggleLoopCrossfade\":\n\t\t\tproperties.enableLoopCrossfade =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLoopCrossfade;\n\t\t\treturn [];\n\t\tcase \"logState\":\n\t\t\treturn [];\n\t}\n\treturn [];\n}\n\n// ---------------------------------------------------------------------------\n// Process block\n// ---------------------------------------------------------------------------\n\nexport interface ProcessContext {\n\tcurrentTime: number;\n\tcurrentFrame: number;\n\tsampleRate: number;\n}\n\nexport interface ProcessResult {\n\tkeepAlive: boolean;\n\tmessages: OutboundMessage[];\n}\n\nexport function processBlock(\n\tprops: Required<ClipProcessorOptions>,\n\toutputs: Float32Array[][],\n\tparameters: Record<string, Float32Array>,\n\tctx: ProcessContext,\n\tfilterState: { lowpass: BiquadState[]; highpass: BiquadState[] },\n): ProcessResult {\n\tconst messages: OutboundMessage[] = [];\n\tlet state = props.state;\n\tif (state === State.Disposed) return { keepAlive: false, messages };\n\n\tapplyPendingBufferWrites(props);\n\n\tif (state === State.Initial) return { keepAlive: true, messages };\n\n\tif (state === State.Ended) {\n\t\tfillWithSilence(outputs[0]);\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tif (state === State.Scheduled) {\n\t\tif (ctx.currentTime >= props.startWhen) {\n\t\t\tstate = props.state = State.Started;\n\t\t\tmessages.push({ type: \"started\" });\n\t\t} else {\n\t\t\tfillWithSilence(outputs[0]);\n\t\t\treturn { keepAlive: true, messages };\n\t\t}\n\t} else if (state === State.Paused) {\n\t\tif (ctx.currentTime > props.pauseWhen) {\n\t\t\tfillWithSilence(outputs[0]);\n\t\t\treturn { keepAlive: true, messages };\n\t\t}\n\t}\n\n\tif (ctx.currentTime > props.stopWhen) {\n\t\tfillWithSilence(outputs[0]);\n\t\tprops.state = State.Ended;\n\t\tmessages.push({ type: \"ended\" });\n\t\tprops.playedSamples = 0;\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tconst output0 = outputs[0];\n\tconst sourceLength = getLogicalBufferLength(props);\n\tif (sourceLength === 0) {\n\t\tfillWithSilence(output0);\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tconst {\n\t\tplaybackRate: playbackRates,\n\t\tdetune: detunes,\n\t\tlowpass,\n\t\thighpass,\n\t\tgain: gains,\n\t\tpan: pans,\n\t} = parameters;\n\n\tconst {\n\t\tbuffer,\n\t\tloopStart,\n\t\tloopEnd,\n\t\tloopCrossfade,\n\t\tstopWhen,\n\t\tplayedSamples,\n\t\tenableLowpass,\n\t\tenableHighpass,\n\t\tenableGain,\n\t\tenablePan,\n\t\tenableDetune,\n\t\tenableFadeOut,\n\t\tenableFadeIn,\n\t\tenableLoopStart,\n\t\tenableLoopEnd,\n\t\tenableLoopCrossfade,\n\t\tplayhead,\n\t\tfadeInDuration,\n\t\tfadeOutDuration,\n\t} = props;\n\tconst hasIncompleteStream =\n\t\tprops.streamBuffer.streaming &&\n\t\tprops.streamBuffer.committedLength < sourceLength;\n\tconst loop = props.loop && !hasIncompleteStream;\n\n\tconst nc = Math.min(buffer.length, output0.length);\n\tconst durationSamples = props.duration * ctx.sampleRate;\n\n\tconst loopCrossfadeSamples = Math.floor(ctx.sampleRate * loopCrossfade);\n\tconst maxLoopStartSample = Math.max(sourceLength - SAMPLE_BLOCK_SIZE, 0);\n\tconst loopStartSamples = enableLoopStart\n\t\t? Math.min(Math.floor(loopStart * ctx.sampleRate), maxLoopStartSample)\n\t\t: 0;\n\tconst loopEndSamples = enableLoopEnd\n\t\t? Math.min(Math.floor(loopEnd * ctx.sampleRate), sourceLength)\n\t\t: sourceLength;\n\tconst loopLengthSamples = loopEndSamples - loopStartSamples;\n\n\t// Apply detune to playback rates: effectiveRate = rate * 2^(detune/1200)\n\tconst needsDetune = enableDetune && detunes.length > 0 && detunes[0] !== 0;\n\tlet effectiveRates = playbackRates;\n\tif (needsDetune) {\n\t\tconst len = Math.max(\n\t\t\tplaybackRates.length,\n\t\t\tdetunes.length,\n\t\t\tSAMPLE_BLOCK_SIZE,\n\t\t);\n\t\teffectiveRates = new Float32Array(len);\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tconst rate = playbackRates[i] ?? playbackRates[playbackRates.length - 1];\n\t\t\tconst cents = detunes[i] ?? detunes[detunes.length - 1];\n\t\t\teffectiveRates[i] = rate * 2 ** (cents / 1200);\n\t\t}\n\t}\n\n\tconst useRateIndexing = props.enablePlaybackRate || needsDetune;\n\tconst isZeroRateBlock =\n\t\tuseRateIndexing &&\n\t\teffectiveRates.length > 0 &&\n\t\teffectiveRates.every((rate) => rate === 0);\n\n\tif (\n\t\tprops.streamBuffer.streaming &&\n\t\t!props.streamBuffer.streamEnded &&\n\t\t!props.streamBuffer.lowWaterNotified &&\n\t\tprops.streamBuffer.committedLength - Math.floor(playhead) <\n\t\t\tprops.streamBuffer.lowWaterThreshold\n\t) {\n\t\tmessages.push({\n\t\t\ttype: \"bufferLowWater\",\n\t\t\tdata: {\n\t\t\t\tplayhead: Math.floor(playhead),\n\t\t\t\tcommittedLength: props.streamBuffer.committedLength,\n\t\t\t},\n\t\t});\n\t\tprops.streamBuffer.lowWaterNotified = true;\n\t}\n\n\tif (isZeroRateBlock) {\n\t\tfillWithSilence(output0);\n\t\tfor (let i = 1; i < outputs.length; i++) {\n\t\t\tcopy(output0, outputs[i]);\n\t\t}\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tconst blockParams: BlockParameters = {\n\t\tbufferLength: sourceLength,\n\t\tloop,\n\t\tplayhead,\n\t\tloopStartSamples,\n\t\tloopEndSamples,\n\t\tdurationSamples,\n\t\tplaybackRates: effectiveRates,\n\t};\n\n\tconst {\n\t\tindexes,\n\t\tended,\n\t\tlooped,\n\t\tplayhead: updatedPlayhead,\n\t} = useRateIndexing\n\t\t? findIndexesWithPlaybackRates(blockParams)\n\t\t: findIndexesNormal(blockParams);\n\n\tconst underrunSample = indexes.find(\n\t\t(index) =>\n\t\t\tindex >= props.streamBuffer.committedLength && index < sourceLength,\n\t);\n\tif (\n\t\tunderrunSample !== undefined &&\n\t\t!props.streamBuffer.streamEnded &&\n\t\tprops.streamBuffer.lastUnderrunSample !== underrunSample\n\t) {\n\t\tmessages.push({\n\t\t\ttype: \"bufferUnderrun\",\n\t\t\tdata: {\n\t\t\t\tplayhead: Math.floor(playhead),\n\t\t\t\tcommittedLength: props.streamBuffer.committedLength,\n\t\t\t\trequestedSample: underrunSample,\n\t\t\t},\n\t\t});\n\t\tprops.streamBuffer.lastUnderrunSample = underrunSample;\n\t} else if (underrunSample === undefined) {\n\t\tprops.streamBuffer.lastUnderrunSample = null;\n\t}\n\n\tfill(output0, buffer, indexes);\n\n\t// --- Loop crossfade ---\n\tconst xfadeNumSamples = Math.min(\n\t\tMath.floor(loopCrossfade * ctx.sampleRate),\n\t\tloopLengthSamples,\n\t);\n\tconst isWithinLoopRange =\n\t\tloop && playhead > loopStartSamples && playhead < loopEndSamples;\n\tconst needsCrossfade =\n\t\tenableLoopCrossfade &&\n\t\tloopCrossfadeSamples > 0 &&\n\t\tsourceLength > SAMPLE_BLOCK_SIZE;\n\n\tif (isWithinLoopRange && needsCrossfade) {\n\t\t// Crossfade out at loop start: fade out tail of previous loop iteration.\n\t\t// Source: reads from END of loop (loopEnd - xfade to loopEnd).\n\t\t{\n\t\t\tconst endIndex = loopStartSamples + xfadeNumSamples;\n\t\t\tif (\n\t\t\t\txfadeNumSamples > 0 &&\n\t\t\t\tplayhead > loopStartSamples &&\n\t\t\t\tplayhead < endIndex\n\t\t\t) {\n\t\t\t\tconst elapsed = playhead - loopStartSamples;\n\t\t\t\tconst n = Math.min(Math.floor(endIndex - playhead), SAMPLE_BLOCK_SIZE);\n\t\t\t\tfor (let i = 0; i < n; i++) {\n\t\t\t\t\tconst position = (elapsed + i) / xfadeNumSamples;\n\t\t\t\t\tconst g = Math.cos((Math.PI * position) / 2);\n\t\t\t\t\tconst srcIdx = Math.floor(\n\t\t\t\t\t\tloopEndSamples - xfadeNumSamples + elapsed + i,\n\t\t\t\t\t);\n\t\t\t\t\tif (srcIdx >= 0 && srcIdx < sourceLength) {\n\t\t\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\t\t\toutput0[ch][i] += buffer[ch][srcIdx] * g;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Crossfade in approaching loop end: fade in head of next loop iteration.\n\t\t// Source: reads from START of loop (loopStart to loopStart + xfade).\n\t\t{\n\t\t\tconst startIndex = loopEndSamples - xfadeNumSamples;\n\t\t\tif (\n\t\t\t\txfadeNumSamples > 0 &&\n\t\t\t\tplayhead > startIndex &&\n\t\t\t\tplayhead < loopEndSamples\n\t\t\t) {\n\t\t\t\tconst elapsed = playhead - startIndex;\n\t\t\t\tconst n = Math.min(\n\t\t\t\t\tMath.floor(loopEndSamples - playhead),\n\t\t\t\t\tSAMPLE_BLOCK_SIZE,\n\t\t\t\t);\n\t\t\t\tfor (let i = 0; i < n; i++) {\n\t\t\t\t\tconst position = (elapsed + i) / xfadeNumSamples;\n\t\t\t\t\tconst g = Math.sin((Math.PI * position) / 2);\n\t\t\t\t\tconst srcIdx = Math.floor(loopStartSamples + elapsed + i);\n\t\t\t\t\tif (srcIdx >= 0 && srcIdx < sourceLength) {\n\t\t\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\t\t\toutput0[ch][i] += buffer[ch][srcIdx] * g;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Fade in ---\n\tif (enableFadeIn && fadeInDuration > 0) {\n\t\tconst fadeInSamples = Math.floor(fadeInDuration * ctx.sampleRate);\n\t\tconst remaining = fadeInSamples - playedSamples;\n\t\tif (remaining > 0) {\n\t\t\tconst n = Math.min(remaining, SAMPLE_BLOCK_SIZE);\n\t\t\tfor (let i = 0; i < n; i++) {\n\t\t\t\tconst t = (playedSamples + i) / fadeInSamples;\n\t\t\t\tconst g = t * t * t; // cubic: slow start, fast finish\n\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\toutput0[ch][i] *= g;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Fade out ---\n\tif (enableFadeOut && fadeOutDuration > 0) {\n\t\tconst fadeOutSamples = Math.floor(fadeOutDuration * ctx.sampleRate);\n\t\tconst remainingSamples = Math.floor(\n\t\t\tctx.sampleRate * (stopWhen - ctx.currentTime),\n\t\t);\n\t\tif (remainingSamples < fadeOutSamples + SAMPLE_BLOCK_SIZE) {\n\t\t\tfor (let i = 0; i < SAMPLE_BLOCK_SIZE; i++) {\n\t\t\t\tconst sampleRemaining = remainingSamples - i;\n\t\t\t\tif (sampleRemaining >= fadeOutSamples) continue; // not yet in fade zone\n\t\t\t\tconst t = sampleRemaining <= 0 ? 0 : sampleRemaining / fadeOutSamples;\n\t\t\t\tconst g = t * t * t; // cubic fade-out: fast drop, slow tail\n\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\toutput0[ch][i] *= g;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Filters ---\n\tif (enableLowpass)\n\t\tlowpassFilter(output0, lowpass, ctx.sampleRate, filterState.lowpass);\n\tif (enableHighpass)\n\t\thighpassFilter(output0, highpass, ctx.sampleRate, filterState.highpass);\n\tif (enableGain) gainFilter(output0, gains);\n\tif (nc === 1) monoToStereo(output0);\n\tif (enablePan) panFilter(output0, pans);\n\n\tif (looped) {\n\t\tprops.timesLooped++;\n\t\tmessages.push({ type: \"looped\", data: props.timesLooped });\n\t}\n\tif (ended) {\n\t\tprops.state = State.Ended;\n\t\tmessages.push({ type: \"ended\" });\n\t}\n\n\tprops.playedSamples += indexes.length;\n\tprops.playhead = updatedPlayhead;\n\n\tconst numNans = checkNans(output0);\n\tif (numNans > 0) {\n\t\tconsole.log({\n\t\t\tnumNans,\n\t\t\tindexes,\n\t\t\tplayhead: updatedPlayhead,\n\t\t\tended,\n\t\t\tlooped,\n\t\t\tsourceLength,\n\t\t});\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tfor (let i = 1; i < outputs.length; i++) {\n\t\tcopy(output0, outputs[i]);\n\t}\n\treturn { keepAlive: true, messages };\n}\n",
7
- "// AudioWorklet processor — runs in AudioWorkletGlobalScope\n// Bundled separately and served at /processor.js\n// This is a thin shell — all DSP logic lives in processor-kernel.ts\n\ndeclare const currentTime: number;\ndeclare const currentFrame: number;\ndeclare const sampleRate: number;\ndeclare class AudioWorkletProcessor {\n\treadonly port: MessagePort;\n\tconstructor(options?: AudioWorkletNodeOptions);\n\tprocess(\n\t\tinputs: Float32Array[][],\n\t\toutputs: Float32Array[][],\n\t\tparameters: Record<string, Float32Array>,\n\t): boolean;\n}\n\ndeclare function registerProcessor(\n\tname: string,\n\tctor: new (options?: AudioWorkletNodeOptions) => AudioWorkletProcessor,\n): void;\n\nimport {\n\tcreateFilterState,\n\tgetProperties,\n\thandleProcessorMessage,\n\tprocessBlock,\n} from \"./processor-kernel\";\nimport type { ClipProcessorOptions, ProcessorWorkletOptions } from \"./types\";\nimport { State } from \"./types\";\n\nclass ClipProcessor extends AudioWorkletProcessor {\n\tstatic get parameterDescriptors() {\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: \"playbackRate\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 1.0,\n\t\t\t},\n\t\t\t{ name: \"detune\", automationRate: \"a-rate\" as const, defaultValue: 0 },\n\t\t\t{\n\t\t\t\tname: \"gain\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 1,\n\t\t\t\tminValue: 0,\n\t\t\t},\n\t\t\t{ name: \"pan\", automationRate: \"a-rate\" as const, defaultValue: 0 },\n\t\t\t{\n\t\t\t\tname: \"highpass\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 20,\n\t\t\t\tminValue: 20,\n\t\t\t\tmaxValue: 20000,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"lowpass\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 20000,\n\t\t\t\tminValue: 20,\n\t\t\t\tmaxValue: 20000,\n\t\t\t},\n\t\t];\n\t}\n\n\tproperties: Required<ClipProcessorOptions>;\n\tprivate filterState = {\n\t\tlowpass: createFilterState(),\n\t\thighpass: createFilterState(),\n\t};\n\tprivate lastFrameTime = 0;\n\n\tconstructor(options?: ProcessorWorkletOptions) {\n\t\tsuper(options);\n\t\tthis.properties = getProperties(options?.processorOptions, sampleRate);\n\t\tthis.port.onmessage = (ev: MessageEvent) => {\n\t\t\tconst messages = handleProcessorMessage(\n\t\t\t\tthis.properties,\n\t\t\t\tev.data,\n\t\t\t\tcurrentTime,\n\t\t\t\tsampleRate,\n\t\t\t);\n\t\t\tfor (const msg of messages) this.port.postMessage(msg);\n\t\t\tif (this.properties.state === State.Disposed) this.port.close();\n\t\t};\n\t}\n\n\tprocess(\n\t\t_inputs: Float32Array[][],\n\t\toutputs: Float32Array[][],\n\t\tparameters: Record<string, Float32Array>,\n\t): boolean {\n\t\ttry {\n\t\t\tconst result = processBlock(\n\t\t\t\tthis.properties,\n\t\t\t\toutputs,\n\t\t\t\tparameters,\n\t\t\t\t{ currentTime, currentFrame, sampleRate },\n\t\t\t\tthis.filterState,\n\t\t\t);\n\t\t\tfor (const msg of result.messages) this.port.postMessage(msg);\n\n\t\t\t// Frame reporting\n\t\t\tconst timeTaken = currentTime - this.lastFrameTime;\n\t\t\tthis.lastFrameTime = currentTime;\n\t\t\tthis.port.postMessage({\n\t\t\t\ttype: \"frame\",\n\t\t\t\tdata: [\n\t\t\t\t\tcurrentTime,\n\t\t\t\t\tcurrentFrame,\n\t\t\t\t\tMath.floor(this.properties.playhead),\n\t\t\t\t\ttimeTaken * 1000,\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn result.keepAlive;\n\t\t} catch (e) {\n\t\t\tthis.port.postMessage({\n\t\t\t\ttype: \"processorError\",\n\t\t\t\tdata: {\n\t\t\t\t\terror: String(e),\n\t\t\t\t\tstate: this.properties.state,\n\t\t\t\t\tbufferChannels: this.properties.buffer?.length,\n\t\t\t\t\tbufferLength: this.properties.buffer?.[0]?.length,\n\t\t\t\t\tparamKeys: Object.keys(parameters),\n\t\t\t\t\thasPlaybackRate: !!parameters.playbackRate,\n\t\t\t\t\thasDetune: !!parameters.detune,\n\t\t\t\t\thasGain: !!parameters.gain,\n\t\t\t\t\thasPan: !!parameters.pan,\n\t\t\t\t\toutputChannels: outputs[0]?.length,\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nregisterProcessor(\"ClipProcessor\", ClipProcessor);\n"
6
+ "// processor-kernel.ts — Pure DSP logic, state machine, all filters\n// NO AudioWorklet or platform dependencies. Fully testable.\n\nimport {\n\ttype BlockParameters,\n\ttype BlockReturnState,\n\ttype BufferRangeWrite,\n\ttype ClipProcessorOptions,\n\tState,\n\ttype StreamBufferSpan,\n\ttype StreamBufferState,\n} from \"./types\";\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nexport const SAMPLE_BLOCK_SIZE = 128;\n\nfunction createStreamBufferState(\n\tbuffer: Float32Array[] = [],\n): StreamBufferState {\n\tconst totalLength = buffer[0]?.length ?? 0;\n\tconst hasBuffer = totalLength > 0;\n\treturn {\n\t\ttotalLength: hasBuffer ? totalLength : null,\n\t\tcommittedLength: hasBuffer ? totalLength : 0,\n\t\tstreamEnded: hasBuffer,\n\t\tstreaming: false,\n\t\twrittenSpans: hasBuffer ? [{ startSample: 0, endSample: totalLength }] : [],\n\t\tpendingWrites: [],\n\t\tlowWaterThreshold: SAMPLE_BLOCK_SIZE * 4,\n\t\tlowWaterNotified: false,\n\t\tlastUnderrunSample: null,\n\t};\n}\n\nfunction getBufferLength(buffer: Float32Array[]): number {\n\treturn buffer[0]?.length ?? 0;\n}\n\nfunction getLogicalBufferLength(\n\tproperties: Required<ClipProcessorOptions>,\n): number {\n\treturn (\n\t\tproperties.streamBuffer.totalLength ?? getBufferLength(properties.buffer)\n\t);\n}\n\nfunction createSilentBuffer(channels: number, length: number): Float32Array[] {\n\treturn Array.from({ length: channels }, () => new Float32Array(length));\n}\n\nfunction mergeWrittenSpan(\n\tspans: StreamBufferSpan[],\n\tnextSpan: StreamBufferSpan,\n): StreamBufferSpan[] {\n\tconst merged = [...spans, nextSpan].sort(\n\t\t(a, b) => a.startSample - b.startSample,\n\t);\n\tconst result: StreamBufferSpan[] = [];\n\tfor (const span of merged) {\n\t\tconst previous = result[result.length - 1];\n\t\tif (!previous || span.startSample > previous.endSample) {\n\t\t\tresult.push({ ...span });\n\t\t\tcontinue;\n\t\t}\n\t\tprevious.endSample = Math.max(previous.endSample, span.endSample);\n\t}\n\treturn result;\n}\n\nfunction getCommittedLength(spans: StreamBufferSpan[]): number {\n\tlet committedLength = 0;\n\tfor (const span of spans) {\n\t\tif (span.startSample > committedLength) break;\n\t\tcommittedLength = Math.max(committedLength, span.endSample);\n\t}\n\treturn committedLength;\n}\n\nfunction resetLowWaterState(\n\tstreamBuffer: StreamBufferState,\n\tplayhead: number,\n): void {\n\tif (\n\t\tstreamBuffer.committedLength - Math.floor(playhead) >=\n\t\tstreamBuffer.lowWaterThreshold\n\t) {\n\t\tstreamBuffer.lowWaterNotified = false;\n\t}\n}\n\nfunction ensureBufferCapacity(\n\tproperties: Required<ClipProcessorOptions>,\n\trequiredChannels: number,\n\trequiredLength: number,\n): void {\n\tconst currentLength = getBufferLength(properties.buffer);\n\tconst currentChannels = properties.buffer.length;\n\tif (currentLength >= requiredLength && currentChannels >= requiredChannels) {\n\t\treturn;\n\t}\n\n\tconst nextLength = Math.max(currentLength, requiredLength);\n\tconst nextChannels = Math.max(currentChannels, requiredChannels);\n\tconst nextBuffer = createSilentBuffer(nextChannels, nextLength);\n\tfor (let ch = 0; ch < currentChannels; ch++) {\n\t\tnextBuffer[ch].set(properties.buffer[ch].subarray(0, currentLength));\n\t}\n\tproperties.buffer = nextBuffer;\n\tif (\n\t\tproperties.streamBuffer.totalLength == null ||\n\t\tproperties.streamBuffer.totalLength < nextLength\n\t) {\n\t\tproperties.streamBuffer.totalLength = nextLength;\n\t}\n}\n\nfunction applyBufferRangeWrite(\n\tproperties: Required<ClipProcessorOptions>,\n\twrite: BufferRangeWrite,\n): void {\n\tconst startSample = Math.max(Math.floor(write.startSample), 0);\n\tconst writeLength = write.channelData[0]?.length ?? 0;\n\tconst requestedTotalLength = write.totalLength ?? null;\n\tconst requiredLength = Math.max(\n\t\tstartSample + writeLength,\n\t\trequestedTotalLength ?? 0,\n\t);\n\tensureBufferCapacity(\n\t\tproperties,\n\t\tMath.max(write.channelData.length, properties.buffer.length, 1),\n\t\trequiredLength,\n\t);\n\n\tfor (let ch = 0; ch < write.channelData.length; ch++) {\n\t\tproperties.buffer[ch].set(write.channelData[ch], startSample);\n\t}\n\n\tif (requestedTotalLength != null) {\n\t\tproperties.streamBuffer.totalLength = requestedTotalLength;\n\t}\n\tif (writeLength > 0) {\n\t\tproperties.streamBuffer.writtenSpans = mergeWrittenSpan(\n\t\t\tproperties.streamBuffer.writtenSpans,\n\t\t\t{ startSample, endSample: startSample + writeLength },\n\t\t);\n\t\tproperties.streamBuffer.committedLength = getCommittedLength(\n\t\t\tproperties.streamBuffer.writtenSpans,\n\t\t);\n\t}\n\tif (write.streamEnded === true) {\n\t\tproperties.streamBuffer.streamEnded = true;\n\t}\n\tresetLowWaterState(properties.streamBuffer, properties.playhead);\n}\n\nfunction applyPendingBufferWrites(\n\tproperties: Required<ClipProcessorOptions>,\n): void {\n\tif (properties.streamBuffer.pendingWrites.length === 0) {\n\t\treturn;\n\t}\n\tfor (const write of properties.streamBuffer.pendingWrites) {\n\t\tapplyBufferRangeWrite(properties, write);\n\t}\n\tproperties.streamBuffer.pendingWrites = [];\n}\n\nfunction setWholeBuffer(\n\tproperties: Required<ClipProcessorOptions>,\n\tbuffer: Float32Array[],\n): void {\n\tproperties.buffer = buffer;\n\tproperties.streamBuffer = createStreamBufferState(buffer);\n}\n\n// ---------------------------------------------------------------------------\n// Properties & offset\n// ---------------------------------------------------------------------------\n\nexport function getProperties(\n\topts: ClipProcessorOptions = {},\n\tsampleRate: number,\n): Required<ClipProcessorOptions> {\n\tconst {\n\t\tbuffer = [],\n\t\tstreamBuffer = createStreamBufferState(buffer),\n\t\tduration = -1,\n\t\tloop = false,\n\t\tloopStart = 0,\n\t\tloopEnd = (buffer[0]?.length ?? 0) / sampleRate,\n\t\tloopCrossfade = 0,\n\t\tplayhead = 0,\n\t\toffset = 0,\n\t\tstartWhen = 0,\n\t\tstopWhen = 0,\n\t\tpauseWhen = 0,\n\t\tresumeWhen = 0,\n\t\tplayedSamples = 0,\n\t\tstate = State.Initial,\n\t\ttimesLooped = 0,\n\t\tfadeInDuration = 0,\n\t\tfadeOutDuration = 0,\n\t\tenableFadeIn = fadeInDuration > 0,\n\t\tenableFadeOut = fadeOutDuration > 0,\n\t\tenableLoopStart = true,\n\t\tenableLoopEnd = true,\n\t\tenableLoopCrossfade = loopCrossfade > 0,\n\t\tenableHighpass = true,\n\t\tenableLowpass = true,\n\t\tenableGain = true,\n\t\tenablePan = true,\n\t\tenableDetune = true,\n\t\tenablePlaybackRate = true,\n\t} = opts;\n\n\treturn {\n\t\tbuffer,\n\t\tstreamBuffer,\n\t\tloop,\n\t\tloopStart,\n\t\tloopEnd,\n\t\tloopCrossfade,\n\t\tduration,\n\t\tplayhead,\n\t\toffset,\n\t\tstartWhen,\n\t\tstopWhen,\n\t\tpauseWhen,\n\t\tresumeWhen,\n\t\tplayedSamples,\n\t\tstate,\n\t\ttimesLooped,\n\t\tfadeInDuration,\n\t\tfadeOutDuration,\n\t\tenableFadeIn,\n\t\tenableFadeOut,\n\t\tenableLoopStart,\n\t\tenableLoopEnd,\n\t\tenableHighpass,\n\t\tenableLowpass,\n\t\tenableGain,\n\t\tenablePan,\n\t\tenableDetune,\n\t\tenablePlaybackRate,\n\t\tenableLoopCrossfade,\n\t};\n}\n\nfunction getBufferDurationSeconds(\n\tproperties: Required<ClipProcessorOptions>,\n\tsampleRate: number,\n): number {\n\treturn getLogicalBufferLength(properties) / sampleRate;\n}\n\nfunction normalizeLoopBounds(\n\tproperties: Required<ClipProcessorOptions>,\n\tsampleRate: number,\n): void {\n\tconst bufferDuration = getBufferDurationSeconds(properties, sampleRate);\n\tif (bufferDuration <= 0) {\n\t\tproperties.loopStart = 0;\n\t\tproperties.loopEnd = 0;\n\t\treturn;\n\t}\n\n\tif (!Number.isFinite(properties.loopStart) || properties.loopStart < 0) {\n\t\tproperties.loopStart = 0;\n\t}\n\tif (properties.loopStart >= bufferDuration) {\n\t\tproperties.loopStart = 0;\n\t}\n\tif (\n\t\t!Number.isFinite(properties.loopEnd) ||\n\t\tproperties.loopEnd <= properties.loopStart ||\n\t\tproperties.loopEnd > bufferDuration\n\t) {\n\t\tproperties.loopEnd = bufferDuration;\n\t}\n}\n\nexport function setOffset(\n\tproperties: Required<ClipProcessorOptions>,\n\toffset: number | undefined,\n\tsampleRate: number,\n): number {\n\tif (offset === undefined) {\n\t\tproperties.offset = 0;\n\t\treturn 0;\n\t}\n\tif (offset < 0) {\n\t\treturn setOffset(\n\t\t\tproperties,\n\t\t\tgetLogicalBufferLength(properties) + offset,\n\t\t\tsampleRate,\n\t\t);\n\t}\n\tif (offset > (getLogicalBufferLength(properties) || 1) - 1) {\n\t\treturn setOffset(\n\t\t\tproperties,\n\t\t\tgetLogicalBufferLength(properties) % offset,\n\t\t\tsampleRate,\n\t\t);\n\t}\n\tconst offs = Math.floor(offset * sampleRate);\n\tproperties.offset = offs;\n\treturn offs;\n}\n\n// ---------------------------------------------------------------------------\n// Index calculation\n// ---------------------------------------------------------------------------\n\nexport function findIndexesNormal(p: BlockParameters): BlockReturnState {\n\tconst { playhead, bufferLength, loop, loopStartSamples, loopEndSamples } = p;\n\tlet length = 128;\n\tif (!loop && playhead + 128 > bufferLength) {\n\t\tlength = Math.max(bufferLength - playhead, 0);\n\t}\n\tconst indexes: number[] = new Array(length);\n\n\tif (!loop) {\n\t\tfor (let i = 0, head = playhead; i < length; i++, head++) {\n\t\t\tindexes[i] = head;\n\t\t}\n\t\tconst nextPlayhead = playhead + length;\n\t\treturn {\n\t\t\tplayhead: nextPlayhead,\n\t\t\tindexes,\n\t\t\tlooped: false,\n\t\t\tended: nextPlayhead >= bufferLength,\n\t\t};\n\t}\n\n\tlet head = playhead;\n\tlet looped = false;\n\tfor (let i = 0; i < length; i++, head++) {\n\t\tif (head >= loopEndSamples) {\n\t\t\thead = loopStartSamples + (head - loopEndSamples);\n\t\t\tlooped = true;\n\t\t}\n\t\tindexes[i] = head;\n\t}\n\treturn { indexes, looped, ended: false, playhead: head };\n}\n\nexport function findIndexesWithPlaybackRates(\n\tp: BlockParameters,\n): BlockReturnState {\n\tconst {\n\t\tplayhead,\n\t\tbufferLength,\n\t\tloop,\n\t\tloopStartSamples,\n\t\tloopEndSamples,\n\t\tplaybackRates,\n\t} = p;\n\tlet length = 128;\n\tif (!loop && playhead + 128 > bufferLength) {\n\t\tlength = Math.max(bufferLength - playhead, 0);\n\t}\n\tconst indexes: number[] = new Array(length);\n\tlet head = playhead;\n\tlet looped = false;\n\n\tif (loop) {\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tindexes[i] = Math.min(Math.max(Math.floor(head), 0), bufferLength - 1);\n\t\t\tconst rate = playbackRates[i] ?? playbackRates[0] ?? 1;\n\t\t\thead += rate;\n\t\t\tif (rate >= 0 && (head > loopEndSamples || head > bufferLength)) {\n\t\t\t\thead = loopStartSamples;\n\t\t\t\tlooped = true;\n\t\t\t} else if (rate < 0 && (head < loopStartSamples || head < 0)) {\n\t\t\t\thead = loopEndSamples;\n\t\t\t\tlooped = true;\n\t\t\t}\n\t\t}\n\t\treturn { playhead: head, indexes, looped, ended: false };\n\t}\n\n\tfor (let i = 0; i < length; i++) {\n\t\tindexes[i] = Math.min(Math.max(Math.floor(head), 0), bufferLength - 1);\n\t\thead += playbackRates[i] ?? playbackRates[0] ?? 1;\n\t}\n\treturn {\n\t\tplayhead: head,\n\t\tindexes,\n\t\tlooped: false,\n\t\tended: head >= bufferLength || head < 0,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Buffer operations\n// ---------------------------------------------------------------------------\n\nexport function fill(\n\ttarget: Float32Array[],\n\tsource: Float32Array[],\n\tindexes: number[],\n): void {\n\tconst nc = Math.min(target.length, source.length);\n\tfor (let i = 0; i < indexes.length; i++) {\n\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\ttarget[ch][i] = source[ch][indexes[i]];\n\t\t}\n\t}\n\tfor (let ch = nc; ch < target.length; ch++) {\n\t\tfor (let i = 0; i < target[ch].length; i++) {\n\t\t\ttarget[ch][i] = 0;\n\t\t}\n\t}\n\tfor (let i = indexes.length; i < target[0].length; i++) {\n\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\ttarget[ch][i] = 0;\n\t\t}\n\t}\n}\n\nexport function fillWithSilence(buffer: Float32Array[]): void {\n\tfor (let ch = 0; ch < buffer.length; ch++) {\n\t\tfor (let j = 0; j < buffer[ch].length; j++) {\n\t\t\tbuffer[ch][j] = 0;\n\t\t}\n\t}\n}\n\nexport function monoToStereo(signal: Float32Array[]): void {\n\tif (signal.length >= 2) {\n\t\t// Output already has a second channel — copy mono data into it\n\t\tfor (let i = 0; i < signal[0].length; i++) {\n\t\t\tsignal[1][i] = signal[0][i];\n\t\t}\n\t} else {\n\t\tconst r = new Float32Array(signal[0].length);\n\t\tfor (let i = 0; i < signal[0].length; i++) {\n\t\t\tr[i] = signal[0][i];\n\t\t}\n\t\tsignal.push(r);\n\t}\n}\n\nexport function copy(source: Float32Array[], target: Float32Array[]): void {\n\tfor (let i = target.length; i < source.length; i++) {\n\t\ttarget[i] = new Float32Array(source[i].length);\n\t}\n\tfor (let ch = 0; ch < source.length; ch++) {\n\t\tfor (let i = 0; i < source[ch].length; i++) {\n\t\t\ttarget[ch][i] = source[ch][i];\n\t\t}\n\t}\n}\n\nexport function checkNans(output: Float32Array[]): number {\n\tlet numNans = 0;\n\tfor (let ch = 0; ch < output.length; ch++) {\n\t\tfor (let j = 0; j < output[ch].length; j++) {\n\t\t\tif (Number.isNaN(output[ch][j])) {\n\t\t\t\tnumNans++;\n\t\t\t\toutput[ch][j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\treturn numNans;\n}\n\n// ---------------------------------------------------------------------------\n// Filters\n// ---------------------------------------------------------------------------\n\nexport interface BiquadState {\n\tx_1: number;\n\tx_2: number;\n\ty_1: number;\n\ty_2: number;\n}\n\nexport function createFilterState(): BiquadState[] {\n\treturn [\n\t\t{ x_1: 0, x_2: 0, y_1: 0, y_2: 0 },\n\t\t{ x_1: 0, x_2: 0, y_1: 0, y_2: 0 },\n\t];\n}\n\nexport function gainFilter(arr: Float32Array[], gains: Float32Array): void {\n\tif (gains.length === 1) {\n\t\tconst g = gains[0];\n\t\tif (g === 1) return;\n\t\tfor (const ch of arr) {\n\t\t\tfor (let i = 0; i < ch.length; i++) ch[i] *= g;\n\t\t}\n\t\treturn;\n\t}\n\tlet g = gains[0];\n\tfor (const ch of arr) {\n\t\tfor (let i = 0; i < ch.length; i++) {\n\t\t\tg = gains[i] ?? g;\n\t\t\tch[i] *= g;\n\t\t}\n\t}\n}\n\nexport function panFilter(signal: Float32Array[], pans: Float32Array): void {\n\tlet pan = pans[0];\n\tfor (let i = 0; i < signal[0].length; i++) {\n\t\tpan = pans[i] ?? pan;\n\t\tconst leftGain = pan <= 0 ? 1 : 1 - pan;\n\t\tconst rightGain = pan >= 0 ? 1 : 1 + pan;\n\t\tsignal[0][i] *= leftGain;\n\t\tsignal[1][i] *= rightGain;\n\t}\n}\n\nexport function lowpassFilter(\n\tbuffer: Float32Array[],\n\tcutoffs: Float32Array,\n\tsampleRate: number,\n\tstates: BiquadState[],\n): void {\n\tfor (let channel = 0; channel < buffer.length; channel++) {\n\t\tconst arr = buffer[channel];\n\t\tlet { x_1, x_2, y_1, y_2 } = states[channel] ?? {\n\t\t\tx_1: 0,\n\t\t\tx_2: 0,\n\t\t\ty_1: 0,\n\t\t\ty_2: 0,\n\t\t};\n\t\tif (cutoffs.length === 1) {\n\t\t\tconst cutoff = cutoffs[0];\n\t\t\tif (cutoff >= 20000) return;\n\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\tconst b0 = (1 - Math.cos(w0)) / 2;\n\t\t\tconst b1 = 1 - Math.cos(w0);\n\t\t\tconst b2 = (1 - Math.cos(w0)) / 2;\n\t\t\tconst a0 = 1 + alpha;\n\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\tconst a2 = 1 - alpha;\n\t\t\tconst h0 = b0 / a0,\n\t\t\t\th1 = b1 / a0,\n\t\t\t\th2 = b2 / a0,\n\t\t\t\th3 = a1 / a0,\n\t\t\t\th4 = a2 / a0;\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y = h0 * x + h1 * x_1 + h2 * x_2 - h3 * y_1 - h4 * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t} else {\n\t\t\tconst prevCutoff = cutoffs[0];\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst cutoff = cutoffs[i] ?? prevCutoff;\n\t\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\t\tconst b0 = (1 - Math.cos(w0)) / 2;\n\t\t\t\tconst b1 = 1 - Math.cos(w0);\n\t\t\t\tconst b2 = (1 - Math.cos(w0)) / 2;\n\t\t\t\tconst a0 = 1 + alpha;\n\t\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\t\tconst a2 = 1 - alpha;\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y =\n\t\t\t\t\t(b0 / a0) * x +\n\t\t\t\t\t(b1 / a0) * x_1 +\n\t\t\t\t\t(b2 / a0) * x_2 -\n\t\t\t\t\t(a1 / a0) * y_1 -\n\t\t\t\t\t(a2 / a0) * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t}\n\t\tstates[channel] = { x_1, x_2, y_1, y_2 };\n\t}\n}\n\nexport function highpassFilter(\n\tbuffer: Float32Array[],\n\tcutoffs: Float32Array,\n\tsampleRate: number,\n\tstates: BiquadState[],\n): void {\n\tfor (let channel = 0; channel < buffer.length; channel++) {\n\t\tconst arr = buffer[channel];\n\t\tlet { x_1, x_2, y_1, y_2 } = states[channel] ?? {\n\t\t\tx_1: 0,\n\t\t\tx_2: 0,\n\t\t\ty_1: 0,\n\t\t\ty_2: 0,\n\t\t};\n\t\tif (cutoffs.length === 1) {\n\t\t\tconst cutoff = cutoffs[0];\n\t\t\tif (cutoff <= 20) return;\n\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\tconst b0 = (1 + Math.cos(w0)) / 2;\n\t\t\tconst b1 = -(1 + Math.cos(w0));\n\t\t\tconst b2 = (1 + Math.cos(w0)) / 2;\n\t\t\tconst a0 = 1 + alpha;\n\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\tconst a2 = 1 - alpha;\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y =\n\t\t\t\t\t(b0 / a0) * x +\n\t\t\t\t\t(b1 / a0) * x_1 +\n\t\t\t\t\t(b2 / a0) * x_2 -\n\t\t\t\t\t(a1 / a0) * y_1 -\n\t\t\t\t\t(a2 / a0) * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t} else {\n\t\t\tconst prevCutoff = cutoffs[0];\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst cutoff = cutoffs[i] ?? prevCutoff;\n\t\t\t\tconst w0 = (2 * Math.PI * cutoff) / sampleRate;\n\t\t\t\tconst alpha = Math.sin(w0) / 2;\n\t\t\t\tconst b0 = (1 + Math.cos(w0)) / 2;\n\t\t\t\tconst b1 = -(1 + Math.cos(w0));\n\t\t\t\tconst b2 = (1 + Math.cos(w0)) / 2;\n\t\t\t\tconst a0 = 1 + alpha;\n\t\t\t\tconst a1 = -2 * Math.cos(w0);\n\t\t\t\tconst a2 = 1 - alpha;\n\t\t\t\tconst x = arr[i];\n\t\t\t\tconst y =\n\t\t\t\t\t(b0 / a0) * x +\n\t\t\t\t\t(b1 / a0) * x_1 +\n\t\t\t\t\t(b2 / a0) * x_2 -\n\t\t\t\t\t(a1 / a0) * y_1 -\n\t\t\t\t\t(a2 / a0) * y_2;\n\t\t\t\tx_2 = x_1;\n\t\t\t\tx_1 = x;\n\t\t\t\ty_2 = y_1;\n\t\t\t\ty_1 = y;\n\t\t\t\tarr[i] = y;\n\t\t\t}\n\t\t}\n\t\tstates[channel] = { x_1, x_2, y_1, y_2 };\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Message handler\n// ---------------------------------------------------------------------------\n\nexport interface OutboundMessage {\n\ttype: string;\n\tdata?: unknown;\n}\n\nexport function handleProcessorMessage(\n\tproperties: Required<ClipProcessorOptions>,\n\tmessage: { type: string; data?: unknown },\n\tcurrentTime: number,\n\tsampleRate: number,\n): OutboundMessage[] {\n\tconst { type, data } = message;\n\tswitch (type) {\n\t\tcase \"buffer\":\n\t\t\tsetWholeBuffer(properties, data as Float32Array[]);\n\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\treturn [];\n\t\tcase \"bufferInit\": {\n\t\t\tconst init = data as {\n\t\t\t\tchannels: number;\n\t\t\t\ttotalLength: number;\n\t\t\t\tstreaming?: boolean;\n\t\t\t};\n\t\t\tproperties.buffer = createSilentBuffer(init.channels, init.totalLength);\n\t\t\tproperties.streamBuffer = {\n\t\t\t\t...createStreamBufferState(),\n\t\t\t\ttotalLength: init.totalLength,\n\t\t\t\tstreamEnded: false,\n\t\t\t\tstreaming: init.streaming ?? true,\n\t\t\t};\n\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\treturn [];\n\t\t}\n\t\tcase \"bufferRange\":\n\t\t\tproperties.streamBuffer.pendingWrites.push(data as BufferRangeWrite);\n\t\t\treturn [];\n\t\tcase \"bufferEnd\": {\n\t\t\tconst endData = data as { totalLength?: number } | undefined;\n\t\t\tif (endData?.totalLength != null) {\n\t\t\t\tproperties.streamBuffer.totalLength = endData.totalLength;\n\t\t\t}\n\t\t\tproperties.streamBuffer.streamEnded = true;\n\t\t\treturn [];\n\t\t}\n\t\tcase \"bufferReset\":\n\t\t\tproperties.buffer = [];\n\t\t\tproperties.streamBuffer = createStreamBufferState();\n\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\treturn [];\n\t\tcase \"start\":\n\t\t\tproperties.timesLooped = 0;\n\t\t\t{\n\t\t\t\tconst d = data as\n\t\t\t\t\t| { duration?: number; offset?: number; when?: number }\n\t\t\t\t\t| undefined;\n\t\t\t\tproperties.duration = d?.duration ?? -1;\n\t\t\t\tif (properties.duration === -1) {\n\t\t\t\t\tproperties.duration = properties.loop\n\t\t\t\t\t\t? Number.MAX_SAFE_INTEGER\n\t\t\t\t\t\t: (properties.buffer[0]?.length ?? 0) / sampleRate;\n\t\t\t\t}\n\t\t\t\tsetOffset(properties, d?.offset, sampleRate);\n\t\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\t\tproperties.playhead = properties.offset;\n\t\t\t\tproperties.startWhen = d?.when ?? currentTime;\n\t\t\t\tproperties.stopWhen = properties.startWhen + properties.duration;\n\t\t\t\tproperties.playedSamples = 0;\n\t\t\t\tproperties.state = State.Scheduled;\n\t\t\t}\n\t\t\treturn [{ type: \"scheduled\" }];\n\t\tcase \"stop\":\n\t\t\tif (\n\t\t\t\tproperties.state === State.Ended ||\n\t\t\t\tproperties.state === State.Initial\n\t\t\t)\n\t\t\t\treturn [];\n\t\t\tproperties.stopWhen = (data as number | undefined) ?? properties.stopWhen;\n\t\t\tproperties.state = State.Stopped;\n\t\t\treturn [{ type: \"stopped\" }];\n\t\tcase \"pause\":\n\t\t\tproperties.state = State.Paused;\n\t\t\tproperties.pauseWhen = (data as number | undefined) ?? currentTime;\n\t\t\treturn [{ type: \"paused\" }];\n\t\tcase \"resume\":\n\t\t\tproperties.state = State.Started;\n\t\t\tproperties.startWhen = (data as number | undefined) ?? currentTime;\n\t\t\treturn [{ type: \"resume\" }];\n\t\tcase \"dispose\":\n\t\t\tproperties.state = State.Disposed;\n\t\t\tproperties.buffer = [];\n\t\t\tproperties.streamBuffer = createStreamBufferState();\n\t\t\treturn [{ type: \"disposed\" }];\n\t\tcase \"loop\": {\n\t\t\tconst loop = data as boolean;\n\t\t\tconst st = properties.state;\n\t\t\tif (loop && (st === State.Scheduled || st === State.Started)) {\n\t\t\t\tproperties.stopWhen = Number.MAX_SAFE_INTEGER;\n\t\t\t\tproperties.duration = Number.MAX_SAFE_INTEGER;\n\t\t\t}\n\t\t\tproperties.loop = loop;\n\t\t\tif (loop) {\n\t\t\t\tnormalizeLoopBounds(properties, sampleRate);\n\t\t\t}\n\t\t\treturn [];\n\t\t}\n\t\tcase \"loopStart\":\n\t\t\tproperties.loopStart = data as number;\n\t\t\treturn [];\n\t\tcase \"loopEnd\":\n\t\t\tproperties.loopEnd = data as number;\n\t\t\treturn [];\n\t\tcase \"loopCrossfade\":\n\t\t\tproperties.loopCrossfade = data as number;\n\t\t\tproperties.enableLoopCrossfade = properties.loopCrossfade > 0;\n\t\t\treturn [];\n\t\tcase \"playhead\":\n\t\t\tproperties.playhead = Math.floor(data as number);\n\t\t\treturn [];\n\t\tcase \"fadeIn\":\n\t\t\tproperties.fadeInDuration = data as number;\n\t\t\tproperties.enableFadeIn = properties.fadeInDuration > 0;\n\t\t\treturn [];\n\t\tcase \"fadeOut\":\n\t\t\tproperties.fadeOutDuration = data as number;\n\t\t\tproperties.enableFadeOut = properties.fadeOutDuration > 0;\n\t\t\treturn [];\n\t\tcase \"toggleGain\":\n\t\t\tproperties.enableGain =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableGain;\n\t\t\treturn [];\n\t\tcase \"togglePan\":\n\t\t\tproperties.enablePan =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enablePan;\n\t\t\treturn [];\n\t\tcase \"toggleLowpass\":\n\t\t\tproperties.enableLowpass =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLowpass;\n\t\t\treturn [];\n\t\tcase \"toggleHighpass\":\n\t\t\tproperties.enableHighpass =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableHighpass;\n\t\t\treturn [];\n\t\tcase \"toggleDetune\":\n\t\t\tproperties.enableDetune =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableDetune;\n\t\t\treturn [];\n\t\tcase \"togglePlaybackRate\":\n\t\t\tproperties.enablePlaybackRate =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enablePlaybackRate;\n\t\t\treturn [];\n\t\tcase \"toggleFadeIn\":\n\t\t\tproperties.enableFadeIn =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableFadeIn;\n\t\t\treturn [];\n\t\tcase \"toggleFadeOut\":\n\t\t\tproperties.enableFadeOut =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableFadeOut;\n\t\t\treturn [];\n\t\tcase \"toggleLoopStart\":\n\t\t\tproperties.enableLoopStart =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLoopStart;\n\t\t\treturn [];\n\t\tcase \"toggleLoopEnd\":\n\t\t\tproperties.enableLoopEnd =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLoopEnd;\n\t\t\treturn [];\n\t\tcase \"toggleLoopCrossfade\":\n\t\t\tproperties.enableLoopCrossfade =\n\t\t\t\t(data as boolean | undefined) ?? !properties.enableLoopCrossfade;\n\t\t\treturn [];\n\t\tcase \"logState\":\n\t\t\treturn [];\n\t}\n\treturn [];\n}\n\n// ---------------------------------------------------------------------------\n// Process block\n// ---------------------------------------------------------------------------\n\nexport interface ProcessContext {\n\tcurrentTime: number;\n\tcurrentFrame: number;\n\tsampleRate: number;\n}\n\nexport interface ProcessResult {\n\tkeepAlive: boolean;\n\tmessages: OutboundMessage[];\n}\n\nexport function processBlock(\n\tprops: Required<ClipProcessorOptions>,\n\toutputs: Float32Array[][],\n\tparameters: Record<string, Float32Array>,\n\tctx: ProcessContext,\n\tfilterState: { lowpass: BiquadState[]; highpass: BiquadState[] },\n): ProcessResult {\n\tconst messages: OutboundMessage[] = [];\n\tlet state = props.state;\n\tif (state === State.Disposed) return { keepAlive: false, messages };\n\n\tapplyPendingBufferWrites(props);\n\n\tif (state === State.Initial) return { keepAlive: true, messages };\n\n\tif (state === State.Ended) {\n\t\tfillWithSilence(outputs[0]);\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tif (state === State.Scheduled) {\n\t\tif (ctx.currentTime >= props.startWhen) {\n\t\t\tstate = props.state = State.Started;\n\t\t\tmessages.push({ type: \"started\" });\n\t\t} else {\n\t\t\tfillWithSilence(outputs[0]);\n\t\t\treturn { keepAlive: true, messages };\n\t\t}\n\t} else if (state === State.Paused) {\n\t\tif (ctx.currentTime > props.pauseWhen) {\n\t\t\tfillWithSilence(outputs[0]);\n\t\t\treturn { keepAlive: true, messages };\n\t\t}\n\t}\n\n\tif (ctx.currentTime > props.stopWhen) {\n\t\tfillWithSilence(outputs[0]);\n\t\tprops.state = State.Ended;\n\t\tmessages.push({ type: \"ended\" });\n\t\tprops.playedSamples = 0;\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tconst output0 = outputs[0];\n\tconst sourceLength = getLogicalBufferLength(props);\n\tif (sourceLength === 0) {\n\t\tfillWithSilence(output0);\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tconst {\n\t\tplaybackRate: playbackRates,\n\t\tdetune: detunes,\n\t\tlowpass,\n\t\thighpass,\n\t\tgain: gains,\n\t\tpan: pans,\n\t} = parameters;\n\n\tconst {\n\t\tbuffer,\n\t\tloopStart,\n\t\tloopEnd,\n\t\tloopCrossfade,\n\t\tstopWhen,\n\t\tplayedSamples,\n\t\tenableLowpass,\n\t\tenableHighpass,\n\t\tenableGain,\n\t\tenablePan,\n\t\tenableDetune,\n\t\tenableFadeOut,\n\t\tenableFadeIn,\n\t\tenableLoopStart,\n\t\tenableLoopEnd,\n\t\tenableLoopCrossfade,\n\t\tplayhead,\n\t\tfadeInDuration,\n\t\tfadeOutDuration,\n\t} = props;\n\tconst hasIncompleteStream =\n\t\tprops.streamBuffer.streaming &&\n\t\tprops.streamBuffer.committedLength < sourceLength;\n\tconst loop = props.loop && !hasIncompleteStream;\n\n\tconst nc = Math.min(buffer.length, output0.length);\n\tconst durationSamples = props.duration * ctx.sampleRate;\n\n\tconst loopCrossfadeSamples = Math.floor(ctx.sampleRate * loopCrossfade);\n\tconst maxLoopStartSample = Math.max(sourceLength - SAMPLE_BLOCK_SIZE, 0);\n\tconst loopStartSamples = enableLoopStart\n\t\t? Math.min(Math.floor(loopStart * ctx.sampleRate), maxLoopStartSample)\n\t\t: 0;\n\tconst loopEndSamples = enableLoopEnd\n\t\t? Math.min(Math.floor(loopEnd * ctx.sampleRate), sourceLength)\n\t\t: sourceLength;\n\tconst loopLengthSamples = loopEndSamples - loopStartSamples;\n\n\t// Apply detune to playback rates: effectiveRate = rate * 2^(detune/1200)\n\tconst needsDetune = enableDetune && detunes.length > 0 && detunes[0] !== 0;\n\tlet effectiveRates = playbackRates;\n\tif (needsDetune) {\n\t\tconst len = Math.max(\n\t\t\tplaybackRates.length,\n\t\t\tdetunes.length,\n\t\t\tSAMPLE_BLOCK_SIZE,\n\t\t);\n\t\teffectiveRates = new Float32Array(len);\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tconst rate = playbackRates[i] ?? playbackRates[playbackRates.length - 1];\n\t\t\tconst cents = detunes[i] ?? detunes[detunes.length - 1];\n\t\t\teffectiveRates[i] = rate * 2 ** (cents / 1200);\n\t\t}\n\t}\n\n\tconst useRateIndexing = props.enablePlaybackRate || needsDetune;\n\tconst isZeroRateBlock =\n\t\tuseRateIndexing &&\n\t\teffectiveRates.length > 0 &&\n\t\teffectiveRates.every((rate) => rate === 0);\n\n\tif (\n\t\tprops.streamBuffer.streaming &&\n\t\t!props.streamBuffer.streamEnded &&\n\t\t!props.streamBuffer.lowWaterNotified &&\n\t\tprops.streamBuffer.committedLength - Math.floor(playhead) <\n\t\t\tprops.streamBuffer.lowWaterThreshold\n\t) {\n\t\tmessages.push({\n\t\t\ttype: \"bufferLowWater\",\n\t\t\tdata: {\n\t\t\t\tplayhead: Math.floor(playhead),\n\t\t\t\tcommittedLength: props.streamBuffer.committedLength,\n\t\t\t},\n\t\t});\n\t\tprops.streamBuffer.lowWaterNotified = true;\n\t}\n\n\tif (isZeroRateBlock) {\n\t\tfillWithSilence(output0);\n\t\tfor (let i = 1; i < outputs.length; i++) {\n\t\t\tcopy(output0, outputs[i]);\n\t\t}\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tconst blockParams: BlockParameters = {\n\t\tbufferLength: sourceLength,\n\t\tloop,\n\t\tplayhead,\n\t\tloopStartSamples,\n\t\tloopEndSamples,\n\t\tdurationSamples,\n\t\tplaybackRates: effectiveRates,\n\t};\n\n\tconst {\n\t\tindexes,\n\t\tended,\n\t\tlooped,\n\t\tplayhead: updatedPlayhead,\n\t} = useRateIndexing\n\t\t? findIndexesWithPlaybackRates(blockParams)\n\t\t: findIndexesNormal(blockParams);\n\n\tconst underrunSample = indexes.find(\n\t\t(index) =>\n\t\t\tindex >= props.streamBuffer.committedLength && index < sourceLength,\n\t);\n\tif (\n\t\tunderrunSample !== undefined &&\n\t\t!props.streamBuffer.streamEnded &&\n\t\tprops.streamBuffer.lastUnderrunSample !== underrunSample\n\t) {\n\t\tmessages.push({\n\t\t\ttype: \"bufferUnderrun\",\n\t\t\tdata: {\n\t\t\t\tplayhead: Math.floor(playhead),\n\t\t\t\tcommittedLength: props.streamBuffer.committedLength,\n\t\t\t\trequestedSample: underrunSample,\n\t\t\t},\n\t\t});\n\t\tprops.streamBuffer.lastUnderrunSample = underrunSample;\n\t} else if (underrunSample === undefined) {\n\t\tprops.streamBuffer.lastUnderrunSample = null;\n\t}\n\n\tfill(output0, buffer, indexes);\n\n\t// --- Loop crossfade ---\n\tconst xfadeNumSamples = Math.min(\n\t\tMath.floor(loopCrossfade * ctx.sampleRate),\n\t\tloopLengthSamples,\n\t);\n\tconst isWithinLoopRange =\n\t\tloop && playhead > loopStartSamples && playhead < loopEndSamples;\n\tconst needsCrossfade =\n\t\tenableLoopCrossfade &&\n\t\tloopCrossfadeSamples > 0 &&\n\t\tsourceLength > SAMPLE_BLOCK_SIZE;\n\n\tif (isWithinLoopRange && needsCrossfade) {\n\t\t// Crossfade out at loop start: fade out tail of previous loop iteration.\n\t\t// Source: reads from END of loop (loopEnd - xfade to loopEnd).\n\t\t{\n\t\t\tconst endIndex = loopStartSamples + xfadeNumSamples;\n\t\t\tif (\n\t\t\t\txfadeNumSamples > 0 &&\n\t\t\t\tplayhead > loopStartSamples &&\n\t\t\t\tplayhead < endIndex\n\t\t\t) {\n\t\t\t\tconst elapsed = playhead - loopStartSamples;\n\t\t\t\tconst n = Math.min(Math.floor(endIndex - playhead), SAMPLE_BLOCK_SIZE);\n\t\t\t\tfor (let i = 0; i < n; i++) {\n\t\t\t\t\tconst position = (elapsed + i) / xfadeNumSamples;\n\t\t\t\t\tconst g = Math.cos((Math.PI * position) / 2);\n\t\t\t\t\tconst srcIdx = Math.floor(\n\t\t\t\t\t\tloopEndSamples - xfadeNumSamples + elapsed + i,\n\t\t\t\t\t);\n\t\t\t\t\tif (srcIdx >= 0 && srcIdx < sourceLength) {\n\t\t\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\t\t\toutput0[ch][i] += buffer[ch][srcIdx] * g;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Crossfade in approaching loop end: fade in head of next loop iteration.\n\t\t// Source: reads from START of loop (loopStart to loopStart + xfade).\n\t\t{\n\t\t\tconst startIndex = loopEndSamples - xfadeNumSamples;\n\t\t\tif (\n\t\t\t\txfadeNumSamples > 0 &&\n\t\t\t\tplayhead > startIndex &&\n\t\t\t\tplayhead < loopEndSamples\n\t\t\t) {\n\t\t\t\tconst elapsed = playhead - startIndex;\n\t\t\t\tconst n = Math.min(\n\t\t\t\t\tMath.floor(loopEndSamples - playhead),\n\t\t\t\t\tSAMPLE_BLOCK_SIZE,\n\t\t\t\t);\n\t\t\t\tfor (let i = 0; i < n; i++) {\n\t\t\t\t\tconst position = (elapsed + i) / xfadeNumSamples;\n\t\t\t\t\tconst g = Math.sin((Math.PI * position) / 2);\n\t\t\t\t\tconst srcIdx = Math.floor(loopStartSamples + elapsed + i);\n\t\t\t\t\tif (srcIdx >= 0 && srcIdx < sourceLength) {\n\t\t\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\t\t\toutput0[ch][i] += buffer[ch][srcIdx] * g;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Fade in ---\n\tif (enableFadeIn && fadeInDuration > 0) {\n\t\tconst fadeInSamples = Math.floor(fadeInDuration * ctx.sampleRate);\n\t\tconst remaining = fadeInSamples - playedSamples;\n\t\tif (remaining > 0) {\n\t\t\tconst n = Math.min(remaining, SAMPLE_BLOCK_SIZE);\n\t\t\tfor (let i = 0; i < n; i++) {\n\t\t\t\tconst t = (playedSamples + i) / fadeInSamples;\n\t\t\t\tconst g = t * t * t; // cubic: slow start, fast finish\n\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\toutput0[ch][i] *= g;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Fade out ---\n\tif (enableFadeOut && fadeOutDuration > 0) {\n\t\tconst fadeOutSamples = Math.floor(fadeOutDuration * ctx.sampleRate);\n\t\tconst remainingSamples = Math.floor(\n\t\t\tctx.sampleRate * (stopWhen - ctx.currentTime),\n\t\t);\n\t\tif (remainingSamples < fadeOutSamples + SAMPLE_BLOCK_SIZE) {\n\t\t\tfor (let i = 0; i < SAMPLE_BLOCK_SIZE; i++) {\n\t\t\t\tconst sampleRemaining = remainingSamples - i;\n\t\t\t\tif (sampleRemaining >= fadeOutSamples) continue; // not yet in fade zone\n\t\t\t\tconst t = sampleRemaining <= 0 ? 0 : sampleRemaining / fadeOutSamples;\n\t\t\t\tconst g = t * t * t; // cubic fade-out: fast drop, slow tail\n\t\t\t\tfor (let ch = 0; ch < nc; ch++) {\n\t\t\t\t\toutput0[ch][i] *= g;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Filters ---\n\tif (enableLowpass)\n\t\tlowpassFilter(output0, lowpass, ctx.sampleRate, filterState.lowpass);\n\tif (enableHighpass)\n\t\thighpassFilter(output0, highpass, ctx.sampleRate, filterState.highpass);\n\tif (enableGain) gainFilter(output0, gains);\n\tif (nc === 1) monoToStereo(output0);\n\tif (enablePan) panFilter(output0, pans);\n\n\tif (looped) {\n\t\tprops.timesLooped++;\n\t\tmessages.push({ type: \"looped\", data: props.timesLooped });\n\t}\n\tif (ended) {\n\t\tprops.state = State.Ended;\n\t\tmessages.push({ type: \"ended\" });\n\t}\n\n\tprops.playedSamples += indexes.length;\n\tprops.playhead = updatedPlayhead;\n\n\tconst numNans = checkNans(output0);\n\tif (numNans > 0) {\n\t\tconsole.log({\n\t\t\tnumNans,\n\t\t\tindexes,\n\t\t\tplayhead: updatedPlayhead,\n\t\t\tended,\n\t\t\tlooped,\n\t\t\tsourceLength,\n\t\t});\n\t\treturn { keepAlive: true, messages };\n\t}\n\n\tfor (let i = 1; i < outputs.length; i++) {\n\t\tcopy(output0, outputs[i]);\n\t}\n\treturn { keepAlive: true, messages };\n}\n",
7
+ "// AudioWorklet processor — runs in AudioWorkletGlobalScope\n// Bundled separately and served at /processor.js\n// This is a thin shell — all DSP logic lives in processor-kernel.ts\n\ndeclare const currentTime: number;\ndeclare const currentFrame: number;\ndeclare const sampleRate: number;\ndeclare class AudioWorkletProcessor {\n\treadonly port: MessagePort;\n\tconstructor(options?: AudioWorkletNodeOptions);\n\tprocess(\n\t\tinputs: Float32Array[][],\n\t\toutputs: Float32Array[][],\n\t\tparameters: Record<string, Float32Array>,\n\t): boolean;\n}\n\ndeclare function registerProcessor(\n\tname: string,\n\tctor: new (options?: AudioWorkletNodeOptions) => AudioWorkletProcessor,\n): void;\n\nimport {\n\tcreateFilterState,\n\tgetProperties,\n\thandleProcessorMessage,\n\tprocessBlock,\n} from \"./processor-kernel\";\nimport type { ClipProcessorOptions, ProcessorWorkletOptions } from \"./types\";\nimport { State } from \"./types\";\n\nclass ClipProcessor extends AudioWorkletProcessor {\n\tstatic get parameterDescriptors() {\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: \"playbackRate\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 1.0,\n\t\t\t},\n\t\t\t{ name: \"detune\", automationRate: \"a-rate\" as const, defaultValue: 0 },\n\t\t\t{\n\t\t\t\tname: \"gain\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 1,\n\t\t\t\tminValue: 0,\n\t\t\t},\n\t\t\t{ name: \"pan\", automationRate: \"a-rate\" as const, defaultValue: 0 },\n\t\t\t{\n\t\t\t\tname: \"highpass\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 20,\n\t\t\t\tminValue: 20,\n\t\t\t\tmaxValue: 20000,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"lowpass\",\n\t\t\t\tautomationRate: \"a-rate\" as const,\n\t\t\t\tdefaultValue: 20000,\n\t\t\t\tminValue: 20,\n\t\t\t\tmaxValue: 20000,\n\t\t\t},\n\t\t];\n\t}\n\n\tproperties: Required<ClipProcessorOptions>;\n\tprivate filterState = {\n\t\tlowpass: createFilterState(),\n\t\thighpass: createFilterState(),\n\t};\n\tprivate lastFrameTime = 0;\n\n\tconstructor(options?: ProcessorWorkletOptions) {\n\t\tsuper(options);\n\t\tthis.properties = getProperties(options?.processorOptions, sampleRate);\n\t\tthis.port.onmessage = (ev: MessageEvent) => {\n\t\t\tif (ev.data.type === \"transferPort\") {\n\t\t\t\tconst port = ev.data.data as MessagePort;\n\t\t\t\tport.onmessage = (portEv: MessageEvent) => {\n\t\t\t\t\tconst messages = handleProcessorMessage(\n\t\t\t\t\t\tthis.properties,\n\t\t\t\t\t\tportEv.data,\n\t\t\t\t\t\tcurrentTime,\n\t\t\t\t\t\tsampleRate,\n\t\t\t\t\t);\n\t\t\t\t\tfor (const msg of messages) this.port.postMessage(msg);\n\t\t\t\t};\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst messages = handleProcessorMessage(\n\t\t\t\tthis.properties,\n\t\t\t\tev.data,\n\t\t\t\tcurrentTime,\n\t\t\t\tsampleRate,\n\t\t\t);\n\t\t\tfor (const msg of messages) this.port.postMessage(msg);\n\t\t\tif (this.properties.state === State.Disposed) this.port.close();\n\t\t};\n\t}\n\n\tprocess(\n\t\t_inputs: Float32Array[][],\n\t\toutputs: Float32Array[][],\n\t\tparameters: Record<string, Float32Array>,\n\t): boolean {\n\t\ttry {\n\t\t\tconst result = processBlock(\n\t\t\t\tthis.properties,\n\t\t\t\toutputs,\n\t\t\t\tparameters,\n\t\t\t\t{ currentTime, currentFrame, sampleRate },\n\t\t\t\tthis.filterState,\n\t\t\t);\n\t\t\tfor (const msg of result.messages) this.port.postMessage(msg);\n\n\t\t\t// Frame reporting\n\t\t\tconst timeTaken = currentTime - this.lastFrameTime;\n\t\t\tthis.lastFrameTime = currentTime;\n\t\t\tthis.port.postMessage({\n\t\t\t\ttype: \"frame\",\n\t\t\t\tdata: [\n\t\t\t\t\tcurrentTime,\n\t\t\t\t\tcurrentFrame,\n\t\t\t\t\tMath.floor(this.properties.playhead),\n\t\t\t\t\ttimeTaken * 1000,\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn result.keepAlive;\n\t\t} catch (e) {\n\t\t\tthis.port.postMessage({\n\t\t\t\ttype: \"processorError\",\n\t\t\t\tdata: {\n\t\t\t\t\terror: String(e),\n\t\t\t\t\tstate: this.properties.state,\n\t\t\t\t\tbufferChannels: this.properties.buffer?.length,\n\t\t\t\t\tbufferLength: this.properties.buffer?.[0]?.length,\n\t\t\t\t\tparamKeys: Object.keys(parameters),\n\t\t\t\t\thasPlaybackRate: !!parameters.playbackRate,\n\t\t\t\t\thasDetune: !!parameters.detune,\n\t\t\t\t\thasGain: !!parameters.gain,\n\t\t\t\t\thasPan: !!parameters.pan,\n\t\t\t\t\toutputChannels: outputs[0]?.length,\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nregisterProcessor(\"ClipProcessor\", ClipProcessor);\n"
8
8
  ],
9
- "mappings": "AAAO,IAAM,EAAQ,CACpB,QAAS,EACT,QAAS,EACT,QAAS,EACT,OAAQ,EACR,UAAW,EACX,MAAO,EACP,SAAU,CACX,ECSO,IAAM,EAAoB,IAEjC,SAAS,CAAuB,CAC/B,EAAyB,CAAC,EACN,CACpB,IAAM,EAAc,EAAO,IAAI,QAAU,EACnC,EAAY,EAAc,EAChC,MAAO,CACN,YAAa,EAAY,EAAc,KACvC,gBAAiB,EAAY,EAAc,EAC3C,YAAa,EACb,UAAW,GACX,aAAc,EAAY,CAAC,CAAE,YAAa,EAAG,UAAW,CAAY,CAAC,EAA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M,iBACN,KAAM,CACL,MAAO,OAAO,CAAC,EACf,MAAO,KAAK,WAAW,MACvB,eAAgB,KAAK,WAAW,QAAQ,OACxC,aAAc,KAAK,WAAW,SAAS,IAAI,OAC3C,UAAW,OAAO,KAAK,CAAU,EACjC,gBAAiB,CAAC,CAAC,EAAW,aAC9B,UAAW,CAAC,CAAC,EAAW,OACxB,QAAS,CAAC,CAAC,EAAW,KACtB,OAAQ,CAAC,CAAC,EAAW,IACrB,eAAgB,EAAQ,IAAI,MAC7B,CACD,CAAC,EACM,IAGV,CAEA,kBAAkB,gBAAiB,EAAa",
10
+ "debugId": "78F68534B0A72CAE64756E2164756E21",
11
11
  "names": []
12
12
  }
@@ -1,10 +1,18 @@
1
1
  # Examples
2
2
 
3
- Each subdirectory demonstrates a different way to use `@jadujoel/web-audio-clip-node`.
3
+ Each subdirectory demonstrates a different integration path for `@jadujoel/web-audio-clip-node`.
4
+
5
+ From the repository root, run every example with:
6
+
7
+ ```sh
8
+ bun run examples
9
+ ```
10
+
11
+ That command builds the local package, links the examples that need it, and serves the demo entry points.
4
12
 
5
13
  | Example | Description | Build step? |
6
14
  |---------|-------------|-------------|
7
- | [cdn-vanilla](./cdn-vanilla/) | Pure HTML + `<script type="module">` via jsDelivr CDN | No |
8
- | [esm-bundler](./esm-bundler/) | Vite + TypeScript with `npm install` | Yes |
9
- | [react](./react/) | Vite + React using the built-in hooks & components | Yes |
15
+ | [cdn-vanilla](./cdn-vanilla/) | Single HTML file using the jsDelivr bundle and a generated demo clip | No |
16
+ | [esm-bundler](./esm-bundler/) | Vite + TypeScript importing the package directly | Yes |
17
+ | [react](./react/) | Vite + React using the provided hooks and UI controls | Yes |
10
18
  | [self-hosted](./self-hosted/) | Vite + self-hosted `processor.js` via `getProcessorModuleUrl()` | Yes |
@@ -1,13 +1,17 @@
1
1
  # CDN Vanilla Example
2
2
 
3
- Zero-install example serve `index.html` with any static file server.
3
+ Single-file demo with no bundler and no local package install.
4
4
 
5
- Everything is loaded from [jsDelivr](https://www.jsdelivr.com/).
5
+ Everything loads from [jsDelivr](https://www.jsdelivr.com/), including the worklet processor. The page synthesizes its own clip so you can see pause/resume, reusable `start()` without recreating the node, live buffer swapping, loop callbacks, loop crossfade, sample-accurate fades, pan, rate, detune, and live playhead seeking without fetching any assets.
6
6
 
7
- > **Note:** Opening the file directly (`file://`) won't work because browsers
8
- > treat `file:` URLs as unique security origins, blocking cross-origin module
9
- > imports.
7
+ > **Note:** Opening the file directly with `file://` will not work because browsers treat local files as isolated origins and block the module/worklet loading path.
8
+
9
+ Serve this directory with any static server, for example:
10
10
 
11
11
  ```sh
12
- bun index.html
12
+ python3 -m http.server 4173
13
13
  ```
14
+
15
+ Then open `http://localhost:4173`.
16
+
17
+ If you are already in the repository root, `bun run examples` also serves this page.