PageSourceSearch

https://daw.stem.fm/workers/buffer-player-processor-202609.R360CT0R-ts.js

js stem.fm collected 2026-10-10 00:29:44 UTC 15,888 bytes, 1 lines download raw bytes

1var v=(o,e,t=1.5,r=1.6,n=1.2,i=2)=>{if(!Number.isInteger(o)||o<=0)throw new Error("N must be a positive integer");if(!Number.isInteger(e)||e<=0)throw new Error("step must be a positive integer");if(o%e!==0)throw new Error("step must divide N exactly");if(i<=0)throw new Error("k must be greater than 0");let s=o/e,c=Array.from({length:s},(a,u)=>s===1?0:u/(s-1)),g=c.map(a=>1-Math.pow(a,i)),f=c.map(a=>a*(1-a)),l=g.map(a=>n+(r-n)*a),b=l.reduce((a,u)=>a+u,0),p=f.reduce((a,u)=>a+u,0);if(p===0){if(s===1){if(Math.abs(r-n)>1e-12||Math.abs(r-t)>1e-12)throw new Error("Impossible constraints: with one group, start, last, and avg must all match");return Array.from({length:o},()=>r)}let a=(r+n)/2;if(Math.abs(a-t)>1e-12)throw new Error(`Impossible constraints: with ${s} groups, average is forced to ${a.toFixed(12)}`);return[...Array.from({length:e},()=>r),...Array.from({length:e},()=>n)]}let d=(s*t-b)/p,h=l.map((a,u)=>a+d*f[u]).flatMap(a=>Array.from({length:e},()=>a));if(Math.abs(h[0]-r)>1e-12)throw new Error(`First item mismatch: got ${h[0]}, expected ${r}`);if(Math.abs(h[h.length-1]-n)>1e-12)throw new Error(`Last item mismatch: got ${h[h.length-1]}, expected ${n}`);return h},R=(o,e,t,r)=>{let n=e,i=16;try{switch(o){default:case 0:return Array(i).fill(n);case 2:return Array(i).fill(n);case 4:return v(i,4,e,n,r,2);case 8:return v(i,2,e,n,r,2);case 16:return v(i,1,e,n,r,2)}}catch{return Array(i).fill(n)}};var F=16,L=16,m=16,_=()=>[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],D=!1,P=!1,T=.01,O=.75,B=192,q=1024*6,N=4800,x=[{fraction:1/4,eventType:"from-buffer-processor-event-bufferPlayed_1/4"},{fraction:2/4,eventType:"from-buffer-processor-event-bufferPlayed_2/4"},{fraction:3/4,eventType:"from-buffer-processor-event-bufferPlayed_3/4"}],E=Array.from({length:m},(o,e)=>({fraction:e/m,eventType:`from-buffer-processor-event-for-pitch_${e}/16`})),C=[4,8,12];function U(o,e=B){for(let t of o){if(!t||t.length===0)continue;let r=Math.max(0,t.length-e),n=t.length-r;for(let i=0;i<n;i++)t[r+i]*=1-i/n}}function w(o,e=B){for(let t of o){if(!t||t.length===0)continue;let r=Math.min(e,t.length);for(let n=0;n<r;n++)t[n]*=n/r}}function Q(o,e){switch(e){case"quantised":return{prev:o.speedRatio_SeedMixMatching_prev,current:o.speedRatio_SeedMixMatching,next:o.speedRatio_SeedMixMatching_next};case"seed":return{prev:o.speedRatio_SeedMixMatching_SeedIsPlayingAsUnquantised_prev,current:o.speedRatio_SeedMixMatching_SeedIsPlayingAsUnquantised,next:o.speedRatio_SeedMixMatching_SeedIsPlayingAsUnquantised_next};case"mix":return{prev:o.speedRatio_SeedMixMatching_MixIsPlayingAsUnquantised_prev,current:o.speedRatio_SeedMixMatching_MixIsPlayingAsUnquantised,next:o.speedRatio_SeedMixMatching_MixIsPlayingAsUnquantised_next}}}var y=class o extends AudioWorkletProcessor{bufferQueue=[];currentBuffer=null;currentBufferPos=0;currentBufferPos_eventFired=0;n_of_16=0;playing=!1;startTime=void 0;globalPlaybackRate=1;_speedLerpDivisionsOnManual=F;_speedLerpDivisionsOnSeedMixSpeed=L;playQuantisedSpeedAs="quantised";speedRatio_SeedMixMatching_Resolved=1;speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved=_();speedRatio_ManualScheduling_PerFraction_delta=_();stopTimeTriggeredFromBufferClearing=void 0;fadeOutStartTime=void 0;bufferAlmostEndEventFired=!1;bufferPlayedProgressEventFired=x.map(()=>!1);barSchedularEventFired=E.map(()=>!1);looping=!1;loopCount=0;barPortion=0;static METRONOME_NORMAL={toneFreq:800,attackSeconds:.001,noiseSeconds:0,tailSeconds:.04,tailDecay:6,noiseWeight:0,toneWeight:.45,peakGain:2};static METRONOME_DOWNBEAT={toneFreq:1200,attackSeconds:.002,noiseSeconds:.003,tailSeconds:.08,tailDecay:4.5,noiseWeight:.3,toneWeight:.6,peakGain:2.8};metronomeEnabled=!1;metronomeGain=.3;metronomeTickActive=!1;metronomeTickPhase=0;metronomeIsDownbeat=!1;metronomePrevN16=-1;constructor(){super(),this.port.onmessage=e=>{this.handleMessage(e.data)}}handleMessage(e){switch(e.type){case"to-buffer-processor-event-add-buffer":{let t=e.detail;this.bufferQueue.push(t),this.postMessage_LogOnSafari(`added Buffer to processor: T${t.trackIndex}S${t.sequenceIdx}C${t.chunkIdx} currentTime[${currentTime}]`,"to-buffer-processor-event-add-buffer-cb");break}case"to-buffer-processor-event-set-start-time":{this.postMessage_LogOnSafari(`processor[x] receive setStateTime: currentTime[${currentTime}] at ${this.startTime}`,"to-buffer-processor-event-set-start-time-cb"),this.startTime=e.startTime;break}case"to-buffer-processor-event-setPlaybackRate":this.globalPlaybackRate=e.playbackRate;break;case"to-buffer-processor-event-set-speed-lerp-divisions-manual-porti
1on":this._speedLerpDivisionsOnManual=e.speedLerpDivisions;break;case"to-buffer-processor-event-set-speed-lerp-divisions-seed-mix-portion":this._speedLerpDivisionsOnSeedMixSpeed=e.speedLerpDivisions;break;case"to-buffer-processor-event-next-buffer-is-not-ready-for-exhausted-queue":this.bufferAlmostEndEventFired=!1,D&&(console.log(`audit: received to-buffer-processor-event-next-buffer-is-not-ready-for-exhausted-queue at processor, now reset as ${this.bufferAlmostEndEventFired}`),P=!0);break;case"to-buffer-processor-event-remove-pending-buffer":this.bufferQueue=[],this.bufferAlmostEndEventFired=!1;break;case"to-buffer-processor-event-loop":{let t=e.detail;if(t.loopCount<=0)return;this.looping=!0,this.loopCount=t.loopCount,this.barPortion=t.barPortion;break}case"to-buffer-processor-event-stop-loop":this.looping=!1,this.loopCount=0,this.barPortion=0;break;case"to-buffer-processor-event-cleanAllBuffersAndStop":this.cleanUpBuffers();break;case"to-buffer-processor-event-fade-out-and-clean-all-buffers":{if(this.currentBuffer===null||this.stopTimeTriggeredFromBufferClearing!==void 0)return;this.fadeOutStartTime=currentTime,this.stopTimeTriggeredFromBufferClearing=currentTime+T*O;break}case"to-buffer-processor-event-set-metronome":{let t=e.detail;this.metronomeEnabled=t.enabled===1,t.gain!==void 0&&(this.metronomeGain=t.gain),this.metronomeEnabled||(this.metronomeTickActive=!1,this.metronomeTickPhase=0);break}}}process(e,t){let r=t[0];!this.playing&&this.startTime!==void 0&&currentTime>=this.startTime&&this.bufferQueue.length>0&&(this.playing=!0,this.postMessage_LogOnSafari(`startTime triggered: currentTime:${currentTime}, startTime:${this.startTime}`,"process")),this.stopTimeTriggeredFromBufferClearing&&this.stopTimeTriggeredFromBufferClearing<currentTime&&this.cleanUpBuffers();let n=this.calculateFadeOutGain();if(!this.playing||(!this.currentBuffer&&this.bufferQueue.length>0&&this.loadNextBuffer("currentBuffer is undefined/null",0),!this.currentBuffer?.buffer))return!0;let i=r[0].length,s=r.length;for(let c=0;c<i;c++){let g=this.calculateMetronomeSample(),f=this.currentBuffer;if(!f?.buffer){for(let u=0;u<s;u++)r[u][c]=0;continue}let l=Math.floor(this.currentBufferPos),b=this.currentBufferPos-l,p=l+1;for(let u=0;u<s;u++){let M=f.buffer[u];if(M&&l<M.length){let S=M[l],I=p<M.length?M[p]:S,k=S+b*(I-S);r[u][c]=k*n+g}else r[u][c]=0}let d=f.buffer[s-1];if(!d||l>=d.length)continue;let A=f.speedRatio_ManualScheduling+this.speedRatio_ManualScheduling_PerFraction_delta[this.n_of_16],h=this.speedRatio_SeedMixMatching_Resolved+this.speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved[this.n_of_16],a=this.globalPlaybackRate*A*h;if(this.currentBufferPos+=a,this.updateN_of_16(d),this.updateMetronomeBeatDetection(),this.requestNextBufferIfNeeded(d,a),this.processBufferPlayedEvents(d),this.process1to16FractionPlayedEvents(d),this.currentBufferPos>=d.length)if(this.looping===!1){this.postMessage_BlockProcessEvent("from-buffer-processor-event-bufferEnded",f);let u=this.currentBufferPos-d.length;this.loadNextBuffer("currentBufferPos > buffer length",u)}else this.loopingImpl(d)}return!0}updateN_of_16(e){this.n_of_16=Math.floor(this.currentBufferPos/(e.length/m))}requestNextBufferIfNeeded(e,t){let r=this.currentBuffer;if(!r||this.bufferAlmostEndEventFired||r.chunkIdx===-1)return;let n=q*t;this.currentBufferPos>=e.length-n?(P&&(P=!1,console.log(`audit: fire from-buffer-processor-event-bufferAlmostEnd retry with ${r.chunkIdx}`)),this.bufferAlmostEndEventFired=!0,this.postMessage_BlockProcessEvent("from-buffer-processor-event-bufferAlmostEnd",r)):this.bufferQueue.length===0&&(this.bufferAlmostEndEventFired=!0,this.postMessage_BlockProcessEvent("from-buffer-processor-event-buffer-queue-is-emptied",r))}loadNextBuffer(e,t=0){let r=this.currentBuffer;try{this.currentBuffer=this.bufferQueue.shift()??null;let n=this.currentBuffer;n?.buffer&&(n.rampToZeroBeforeEnd&&U(n.buffer),n.rampFromZeroAtStart&&w(n.buffer));let i=n?.skipSamplesAtStart;this.currentBufferPos=i!==void 0&&i>0?i:t;let s=n?.buffer?.[0];s?this.updateN_of_16(s):this.n_of_16=0,this.currentBufferPos_eventFired=this.currentBufferPos,this.resetPerBufferState(),n||this.postMessage_NextBufferNotReady(r,e),this.resolveSpeedAndGlobalParam(),n&&this.postMessage_BlockProcessEvent("from-buffer-processor-event-bufferStarted",n,e)}catch(n){console.log("signature, ",e),console.error(n)}}cleanUpBuffers(){this.postMessage_LogOnSafari(`processor[x] just cleanAllBuffersAndStop currentTime[${currentTime} ${this.stopTimeTriggeredFromBufferClearing}]`,"CleanupBuffers"),this.resetPauseState(),this.bufferQueue=[],this.playing=!1,this.looping=!1,this.loopCount=0,this.barPortion=0,this.currentBuffer=null,this.currentBufferPos=0,this.n_of_16=0,this.currentBufferPos_eventFired=0,this.speedRatio_SeedMixMatching_Resolved=1,this.startTime=void 0,this.resetPerBufferState(),this.metronomeTickActive=!1,this.metronomeTickPhase=0,this.postMessage_LogOnSafari(`processor[x] just cleanAllBuffersAndStop currentTime[${currentTime}, cleaned & stopTimeTriggeredFromBufferClearing: ${this.stopTimeTriggeredFromBufferClearing}]`,"CleanupBuffers")}resetPerBufferState(){this.speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved=_(),this.speedRatio_ManualScheduling_PerFraction_delta=_(),this.bufferAlmostEndEventFired=!1,this.bufferPlayedProgressEventFired.fill(!1),this.barSchedularEventFired.fill(!1),this.metronomePrevN16=-1}resetPauseState(){this.fadeOutStartTime=void 0,this.stopTimeTriggeredFromBufferClearing=void 0}resolveSpeedAndGlobalParam(){let e=this.currentBuffer;if(!e)return;this.playQuantisedSpeedAs=e.playQuantisedSpeedAs;let t=Q(e,this.playQuantisedSpeedAs);
1if(this.speedRatio_SeedMixMatching_Resolved=t.current,e.speedRatio_ManualScheduling===e.speedRatio_ManualScheduling_next||this._speedLerpDivisionsOnManual===0)this.speedRatio_ManualScheduling_PerFraction_delta=_();else{let r=(e.speedRatio_ManualScheduling_next-e.speedRatio_ManualScheduling)/m,n=_(),i=m/this._speedLerpDivisionsOnManual;for(let s=0;s<m;s++){let c=Math.floor(s/i)*i;n[s]=c*r}this.speedRatio_ManualScheduling_PerFraction_delta=n}this.speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved=this.getSpeedRatioSeedMixMatching_fractions(t.prev,t.current,t.next,this.playQuantisedSpeedAs)}getSpeedRatioSeedMixMatching_fractions(e,t,r,n){let i=t;if(i===r||this._speedLerpDivisionsOnSeedMixSpeed===0||n==="quantised")return _();let s=R(this._speedLerpDivisionsOnSeedMixSpeed,t,i,r);for(let c=0;c<m;c++)s[c]=s[c]-t;return s}processBufferPlayedEvents(e){this.currentBuffer&&this.fireHighestReachedMilestone(e,x,this.bufferPlayedProgressEventFired)}process1to16FractionPlayedEvents(e){this.currentBuffer&&(this.fireHighestReachedMilestone(e,E,this.barSchedularEventFired),this.currentBufferPos>this.currentBufferPos_eventFired+N&&this.currentBuffer.chunkIdx!==-1&&(this.currentBufferPos_eventFired=this.currentBufferPos,this.postMessage_BlockProcessEvent("from-buffer-processor-event-sample-loc-updated",this.currentBuffer)))}fireHighestReachedMilestone(e,t,r){let n=this.currentBuffer;if(!(!n||!e)&&n.chunkIdx!==-1){for(let i=t.length-1;i>=0;i--)if(!r[i]&&this.currentBufferPos>=e.length*t[i].fraction){r.fill(!0,0,i+1),this.postMessage_BlockProcessEvent(t[i].eventType,n);return}}}loopingImpl(e){if(e&&this.loopCount>0){this.loopCount--;let t=1-this.barPortion;this.currentBufferPos=Math.round(t*e.length),this.updateN_of_16(e),this.currentBufferPos_eventFired=this.currentBufferPos,x.forEach((n,i)=>{this.bufferPlayedProgressEventFired[i]=t>n.fraction});let r=Math.ceil(t*m);t>=0&&r<m&&(this.barSchedularEventFired.fill(!0,0,r),this.barSchedularEventFired[r]=!1)}this.loopCount===0&&(this.looping=!1)}calculateFadeOutGain(){if(!this.fadeOutStartTime||!this.stopTimeTriggeredFromBufferClearing)return 1;let e=currentTime-this.fadeOutStartTime;return 1-Math.min(e/T,1)}updateMetronomeBeatDetection(){if(!this.metronomeEnabled||this.currentBuffer?.chunkIdx===-1||this.n_of_16===this.metronomePrevN16)return;let e=this.n_of_16===0;(e||C.includes(this.n_of_16))&&(this.metronomeTickActive=!0,this.metronomeTickPhase=0,this.metronomeIsDownbeat=e,this.postMessage_LogOnSafari(`[T${this.currentBuffer?.trackIndex} C${this.currentBuffer?.chunkIdx} metronome] ${e?"down beat":`up beat ${(this.n_of_16/4).toFixed(0)}`}`,"updateMetronomeBeatDetection")),this.metronomePrevN16=this.n_of_16}calculateMetronomeSample(){if(!this.metronomeEnabled||!this.metronomeTickActive||this.currentBuffer?.chunkIdx===-1)return 0;let e=sampleRate,t=this.metronomeIsDownbeat?o.METRONOME_DOWNBEAT:o.METRONOME_NORMAL,r=Math.max(1,Math.floor(e*t.attackSeconds)),n=Math.max(1,Math.floor(e*t.tailSeconds)),i=this.metronomeTickPhase;if(i>=n)return this.metronomeTickActive=!1,0;let s;if(i<r)s=i/r;else{let p=(i-r)/(n-r);s=Math.exp(-t.tailDecay*p)}let c=0;if(t.noiseWeight>0){let p=Math.max(1,Math.floor(e*t.noiseSeconds)),d=i<p?1-i/p:0;c=(Math.random()*2-1)*t.noiseWeight*d}let g=i/e*t.toneFreq*2*Math.PI,f=Math.sin(g)*t.toneWeight,l=Math.max(0,Math.min(1,this.metronomeGain)),b=Math.sqrt(l)*t.peakGain;return this.metronomeTickPhase++,(c+f)*s*b}postMessage_LogOnSafari(e,t){let r={type:"from-buffer-processor-event-logOnSafari",detail:{message:e},signature:t};this.port.postMessage(r)}postMessage_BlockProcessEvent(e,t,r="BLOCK Process"){let n={type:e,detail:{trackIndex:t.trackIndex,sequenceIdx:t.sequenceIdx,chunkIdx:t.chunkIdx,chunkId:t.chunkId,timeStamp:currentTime,_internalSpeed:{speedRatio_SeedMixMatching_Resolved:this.speedRatio_SeedMixMatching_Resolved,playbackRate:this.globalPlaybackRate,speedRatio_ManualScheduling:t.speedRatio_ManualScheduling,n_of_16:this.n_of_16,speedRatio_ManualScheduling_PerFraction_delta:this.speedRatio_ManualScheduling_PerFraction_delta,speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved:this.speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved,audit:{isPlayingQuantisedAs:this.playQuantisedSpeedAs,speedRatio_ManualScheduling_prev:t.speedRatio_ManualScheduling_prev,speedRatio_ManualScheduling_next:t.speedRatio_ManualScheduling_next}},trackId:t.trackId,stemId:t.stemId,signature:r,barSequenceUUID:t.barSequenceUUID,bufferPosPlayedInThisChunk:this.currentBufferPos}};this.port.postMessage(n)}postMessage_NextBufferNotReady(e,t){let r={type:"from-buffer-processor-event-nextBufferNotReady",detail
1:{trackIndex:e?.trackIndex??-1,sequenceIdx:e?.sequenceIdx??-1,chunkIdx:e?.chunkIdx??-1,chunkId:e?.chunkId??"empty",timeStamp:currentTime,_internalSpeed:{speedRatio_SeedMixMatching_Resolved:-1,playbackRate:this.globalPlaybackRate,speedRatio_ManualScheduling:-1,n_of_16:this.n_of_16,speedRatio_ManualScheduling_PerFraction_delta:this.speedRatio_ManualScheduling_PerFraction_delta,speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved:this.speedRatio_SeedMixMatching_LerpingFineTune_PerFraction_delta_Resolved,audit:{isPlayingQuantisedAs:e?.playQuantisedSpeedAs??this.playQuantisedSpeedAs,speedRatio_ManualScheduling_prev:e?.speedRatio_ManualScheduling_prev??-1,speedRatio_ManualScheduling_next:e?.speedRatio_ManualScheduling_next??-1}},trackId:e?.trackId??"empty",stemId:e?.stemId??"empty",signature:t,barSequenceUUID:e?.barSequenceUUID??"empty",bufferPosPlayedInThisChunk:this.currentBufferPos}};this.port.postMessage(r)}};registerProcessor("buffer-player-processor",y);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.