@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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/audio/utils.ts", "../src/audio/ClipNode.ts", "../src/audio/processor-code.ts", "../src/audio/types.ts", "../src/audio/processor-kernel.ts", "../src/audio/version.ts", "../src/audio/workletUrl.ts", "../src/controls/controlDefs.ts", "../src/controls/formatValueText.ts", "../src/controls/linkedControlPairs.ts", "../src/data/cache.ts", "../src/data/fileStore.ts"],
4
- "sourcesContent": ["export function dbFromLin(lin: number): number {\n\treturn Math.max(20 * Math.log10(lin), -1000);\n}\n\nexport function linFromDb(db: number): number {\n\treturn 10 ** (db / 20);\n}\n\nconst TEMPO_RELATIVE_SNAPS = [\"beat\", \"bar\", \"8th\", \"16th\"] as const;\n\nexport type TempoRelativeSnap = (typeof TEMPO_RELATIVE_SNAPS)[number];\n\nfunction clamp(value: number, min: number, max: number): number {\n\treturn Math.min(Math.max(value, min), max);\n}\n\nexport function isTempoRelativeSnap(snap: string): snap is TempoRelativeSnap {\n\treturn TEMPO_RELATIVE_SNAPS.includes(snap as TempoRelativeSnap);\n}\n\nexport function getTempoSnapInterval(\n\tsnap: string,\n\ttempo: number,\n): number | null {\n\tif (!Number.isFinite(tempo) || tempo <= 0) return null;\n\n\tconst secondsPerBeat = 60 / tempo;\n\tswitch (snap) {\n\t\tcase \"beat\":\n\t\t\treturn secondsPerBeat;\n\t\tcase \"bar\":\n\t\t\treturn secondsPerBeat * 4;\n\t\tcase \"8th\":\n\t\t\treturn secondsPerBeat / 2;\n\t\tcase \"16th\":\n\t\t\treturn secondsPerBeat / 4;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nexport function remapTempoRelativeValue(\n\tvalue: number,\n\tsnap: string,\n\toldTempo: number,\n\tnewTempo: number,\n\tmin: number,\n\tmax: number,\n): number {\n\tif (!isTempoRelativeSnap(snap)) {\n\t\treturn clamp(value, min, max);\n\t}\n\tif (value < 0) {\n\t\treturn clamp(value, min, max);\n\t}\n\n\tconst oldInterval = getTempoSnapInterval(snap, oldTempo);\n\tconst newInterval = getTempoSnapInterval(snap, newTempo);\n\tif (oldInterval == null || newInterval == null) {\n\t\treturn clamp(value, min, max);\n\t}\n\n\tconst count = Math.round(value / oldInterval);\n\treturn clamp(count * newInterval, min, max);\n}\n\nexport function getSnappedValue(\n\tvalue: number,\n\tsnap: string,\n\ttempo: number,\n): number {\n\tconst interval = getTempoSnapInterval(snap, tempo);\n\tif (interval != null) {\n\t\treturn Math.round(value / interval) * interval;\n\t}\n\n\tswitch (snap) {\n\t\tcase \"int\":\n\t\t\treturn Math.round(value);\n\t\tdefault:\n\t\t\treturn value;\n\t}\n}\n\nexport interface SliderPreset {\n\tsnaps?: number[];\n\tticks?: number[];\n\tmin?: number;\n\tmax?: number;\n\tskew?: number;\n\tstep?: number;\n\tlogarithmic?: boolean;\n}\n\nexport const presets: Record<string, SliderPreset> = {\n\thertz: {\n\t\tsnaps: [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],\n\t\tticks: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],\n\t\tmin: 32,\n\t\tmax: 16384,\n\t\tlogarithmic: true,\n\t},\n\tdecibel: {\n\t\tticks: [-48, -24, -12, -6, -3, 0],\n\t\tmin: -60,\n\t\tmax: 0,\n\t\tskew: 1,\n\t},\n\tcents: {\n\t\tsnaps: Array.from({ length: 49 }, (_, i) => (i - 24) * 100), // semitones: -2400..2400 by 100\n\t\tticks: [-2400, -1200, 0, 1200, 2400],\n\t\tmin: -2400,\n\t\tmax: 2400,\n\t\tskew: 1,\n\t\tstep: 1,\n\t},\n\tplaybackRate: {\n\t\tsnaps: [-2, -1, -0.5, 0, 0.5, 1, 1.5, 2],\n\t\tticks: [-2, -1, 0, 1, 2],\n\t\tmin: -2,\n\t\tmax: 2,\n\t\tskew: 1,\n\t},\n\tgain: {\n\t\tsnaps: [-60, -48, -36, -24, -18, -12, -9, -6, -3, -1, 0],\n\t\tticks: [-48, -24, -12, -6, -3, 0],\n\t\tmin: -100,\n\t\tmax: 0,\n\t\tskew: 6,\n\t},\n\tpan: {\n\t\tsnaps: [-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],\n\t\tticks: [-1, -0.5, 0, 0.5, 1],\n\t\tmin: -1,\n\t\tmax: 1,\n\t\tskew: 1,\n\t},\n};\n\nexport function float32ArrayFromAudioBuffer(\n\tbuffer: AudioBuffer,\n): Float32Array[] {\n\treturn buffer.numberOfChannels === 1\n\t\t? [buffer.getChannelData(0)]\n\t\t: [buffer.getChannelData(0), buffer.getChannelData(1)];\n}\n\nexport function audioBufferFromFloat32Array(\n\tcontext: BaseAudioContext,\n\tdata?: Float32Array[],\n): AudioBuffer | undefined {\n\tif (!data || data.length === 0) return undefined;\n\tconst buffer = context.createBuffer(\n\t\tdata.length,\n\t\tdata[0].length,\n\t\tcontext.sampleRate,\n\t);\n\tfor (let i = 0; i < data.length; i++) {\n\t\tbuffer.copyToChannel(new Float32Array(data[i]), i);\n\t}\n\treturn buffer;\n}\n\nexport function generateSnapPoints(\n\tsnap: string,\n\ttempo: number,\n\tmin: number,\n\tmax: number,\n): number[] {\n\tconst interval =\n\t\tgetTempoSnapInterval(snap, tempo) ?? (snap === \"int\" ? 1 : null);\n\tif (interval == null) return [];\n\tif (interval <= 0) return [];\n\tconst points: number[] = [];\n\tconst start = Math.ceil(min / interval) * interval;\n\tfor (let v = start; v <= max; v += interval) {\n\t\tpoints.push(Math.round(v * 1e10) / 1e10);\n\t}\n\treturn points;\n}\n", "import type { ClipNodeState, ClipWorkletOptions, FrameData } from \"./types\";\nimport { audioBufferFromFloat32Array } from \"./utils\";\n\nexport class ClipNode extends AudioWorkletNode {\n\tonscheduled?: () => void;\n\tonstarted?: () => void;\n\tonpaused?: () => void;\n\tonresumed?: () => void;\n\tonended?: () => void;\n\tonlooped?: () => void;\n\tonstopped?: () => void;\n\tonframe?: (data: FrameData) => void;\n\tondisposed?: () => void;\n\tonstatechange?: (state: ClipNodeState) => void;\n\n\tprivate _buffer?: AudioBuffer;\n\tprivate _loopStart = 0;\n\tprivate _loopEnd = 0;\n\tprivate _loop = false;\n\tprivate _offset = 0;\n\tprivate _playhead = 0;\n\tprivate _fadeIn = 0;\n\tprivate _fadeOut = 0;\n\tprivate _loopCrossfade = 0;\n\tprivate _duration = -1;\n\tprivate _previousState: ClipNodeState = \"initial\";\n\tprivate _bufferWriteCursor = 0;\n\n\ttimesLooped = 0;\n\tstate: ClipNodeState = \"initial\";\n\tcpu = 0;\n\n\tconstructor(context: BaseAudioContext, options: ClipWorkletOptions = {}) {\n\t\tsuper(context, \"ClipProcessor\", {\n\t\t\tnumberOfInputs: options.numberOfInputs ?? 0,\n\t\t\toutputChannelCount: options.outputChannelCount ?? [2],\n\t\t\tprocessorOptions: options.processorOptions,\n\t\t\tchannelCount: options.channelCount,\n\t\t\tchannelCountMode: options.channelCountMode,\n\t\t\tchannelInterpretation: options.channelInterpretation,\n\t\t\tnumberOfOutputs: options.numberOfOutputs,\n\t\t\tparameterData: options.parameterData,\n\t\t});\n\n\t\tthis._buffer = audioBufferFromFloat32Array(\n\t\t\tthis.context,\n\t\t\toptions.processorOptions?.buffer,\n\t\t);\n\t\tthis.port.onmessage = this.handleMessage;\n\t}\n\n\tprivate handleMessage = (message: MessageEvent) => {\n\t\tconst { type, data } = message.data;\n\t\tswitch (type) {\n\t\t\tcase \"frame\": {\n\t\t\t\tconst [_ct, _cf, ph, tt] = data as [number, number, number, number];\n\t\t\t\tthis._playhead = ph;\n\t\t\t\tthis.cpu = tt;\n\t\t\t\tthis.onframe?.(data);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"scheduled\":\n\t\t\t\tthis.setState(\"scheduled\");\n\t\t\t\tthis.onscheduled?.();\n\t\t\t\tbreak;\n\t\t\tcase \"started\":\n\t\t\t\tthis.setState(\"started\");\n\t\t\t\tthis.onstarted?.();\n\t\t\t\tbreak;\n\t\t\tcase \"stopped\":\n\t\t\t\tthis.setState(\"stopped\");\n\t\t\t\tthis.onstopped?.();\n\t\t\t\tbreak;\n\t\t\tcase \"paused\":\n\t\t\t\tthis.setState(\"paused\");\n\t\t\t\tthis.onpaused?.();\n\t\t\t\tbreak;\n\t\t\tcase \"resume\":\n\t\t\t\tthis.setState(\"resumed\");\n\t\t\t\tthis.onresumed?.();\n\t\t\t\tbreak;\n\t\t\tcase \"ended\":\n\t\t\t\tthis.setState(\"ended\");\n\t\t\t\tthis.onended?.();\n\t\t\t\tbreak;\n\t\t\tcase \"looped\":\n\t\t\t\tthis.timesLooped++;\n\t\t\t\tthis.onlooped?.();\n\t\t\t\tbreak;\n\t\t\tcase \"disposed\":\n\t\t\t\tthis.setState(\"disposed\");\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tprivate setState(newState: ClipNodeState) {\n\t\tthis._previousState = this.state;\n\t\tthis.state = newState;\n\t\tif (this.state !== this._previousState) {\n\t\t\tthis.onstatechange?.(this.state);\n\t\t}\n\t}\n\n\ttoggleGain(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleGain\", data: value });\n\t}\n\ttogglePlaybackRate(value = true) {\n\t\tthis.port.postMessage({ type: \"togglePlaybackRate\", data: value });\n\t}\n\ttoggleDetune(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleDetune\", data: value });\n\t}\n\ttogglePan(value = true) {\n\t\tthis.port.postMessage({ type: \"togglePan\", data: value });\n\t}\n\ttoggleHighpass(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleHighpass\", data: value });\n\t}\n\ttoggleLowpass(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLowpass\", data: value });\n\t}\n\ttoggleFadeIn(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleFadeIn\", data: value });\n\t}\n\ttoggleFadeOut(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleFadeOut\", data: value });\n\t}\n\ttoggleLoopCrossfade(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLoopCrossfade\", data: value });\n\t}\n\ttoggleLoopStart(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLoopStart\", data: value });\n\t}\n\ttoggleLoopEnd(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLoopEnd\", data: value });\n\t}\n\tlogState() {\n\t\tthis.port.postMessage({ type: \"logState\" });\n\t}\n\n\tget buffer(): AudioBuffer | undefined {\n\t\treturn this._buffer;\n\t}\n\tset buffer(ab: AudioBuffer) {\n\t\tthis._buffer = ab;\n\t\tthis._bufferWriteCursor = ab.length;\n\t\tif (this._loopStart >= ab.duration) {\n\t\t\tthis._loopStart = 0;\n\t\t}\n\t\tif (this._loopEnd <= this._loopStart || this._loopEnd > ab.duration) {\n\t\t\tthis._loopEnd = ab.duration;\n\t\t}\n\t\tconst data =\n\t\t\tab.numberOfChannels === 1\n\t\t\t\t? [ab.getChannelData(0)]\n\t\t\t\t: [ab.getChannelData(0), ab.getChannelData(1)];\n\t\tthis.port.postMessage({ type: \"buffer\", data });\n\t\tthis.port.postMessage({ type: \"loopStart\", data: this._loopStart });\n\t\tthis.port.postMessage({ type: \"loopEnd\", data: this._loopEnd });\n\t}\n\n\tinitializeBuffer(\n\t\ttotalLength: number,\n\t\tchannels: number,\n\t\toptions: { streaming?: boolean } = {},\n\t) {\n\t\tthis._buffer = this.context.createBuffer(\n\t\t\tchannels,\n\t\t\ttotalLength,\n\t\t\tthis.context.sampleRate,\n\t\t);\n\t\tthis._bufferWriteCursor = 0;\n\t\tconst duration = totalLength / this.context.sampleRate;\n\t\tif (this._loopStart >= duration) {\n\t\t\tthis._loopStart = 0;\n\t\t}\n\t\tif (this._loopEnd <= this._loopStart || this._loopEnd > duration) {\n\t\t\tthis._loopEnd = duration;\n\t\t}\n\t\tthis.port.postMessage({\n\t\t\ttype: \"bufferInit\",\n\t\t\tdata: {\n\t\t\t\tchannels,\n\t\t\t\ttotalLength,\n\t\t\t\tstreaming: options.streaming ?? true,\n\t\t\t},\n\t\t});\n\t\tthis.port.postMessage({ type: \"loopStart\", data: this._loopStart });\n\t\tthis.port.postMessage({ type: \"loopEnd\", data: this._loopEnd });\n\t}\n\n\treplaceBufferRange(\n\t\tstartSample: number,\n\t\tchannelData: Float32Array[],\n\t\toptions: { totalLength?: number | null; streamEnded?: boolean } = {},\n\t) {\n\t\tthis.port.postMessage({\n\t\t\ttype: \"bufferRange\",\n\t\t\tdata: {\n\t\t\t\tstartSample,\n\t\t\t\tchannelData,\n\t\t\t\ttotalLength: options.totalLength,\n\t\t\t\tstreamEnded: options.streamEnded,\n\t\t\t},\n\t\t});\n\t\tthis._bufferWriteCursor = Math.max(\n\t\t\tthis._bufferWriteCursor,\n\t\t\tstartSample + (channelData[0]?.length ?? 0),\n\t\t);\n\t}\n\n\tappendBufferRange(\n\t\tchannelData: Float32Array[],\n\t\toptions: { totalLength?: number | null; streamEnded?: boolean } = {},\n\t) {\n\t\tthis.replaceBufferRange(this._bufferWriteCursor, channelData, options);\n\t}\n\n\tfinalizeBuffer(totalLength?: number) {\n\t\tthis.port.postMessage({ type: \"bufferEnd\", data: { totalLength } });\n\t}\n\n\tstart(when?: number, offset?: number, duration?: number) {\n\t\tif (!this._buffer) {\n\t\t\tconsole.error(\"Buffer not set.\");\n\t\t\treturn;\n\t\t}\n\t\tthis.port.postMessage({ type: \"start\", data: { when, offset, duration } });\n\t}\n\n\tstop(when: number = this.context.currentTime, initialDelay = 0) {\n\t\tthis.port.postMessage({\n\t\t\ttype: \"stop\",\n\t\t\tdata: when + initialDelay + this._fadeOut + 0.2,\n\t\t});\n\t}\n\n\tpause(when: number = this.context.currentTime) {\n\t\tthis.port.postMessage({ type: \"pause\", data: when });\n\t}\n\n\tresume(when: number = this.context.currentTime) {\n\t\tthis.port.postMessage({ type: \"resume\", data: when });\n\t}\n\n\tget loop() {\n\t\treturn this._loop;\n\t}\n\tset loop(value: boolean) {\n\t\tif (this._loop !== value) {\n\t\t\tthis._loop = value;\n\t\t\tthis.port.postMessage({ type: \"loop\", data: value });\n\t\t}\n\t}\n\n\tget loopStart() {\n\t\treturn this._loopStart;\n\t}\n\tset loopStart(value: number) {\n\t\tif (value !== this._loopStart) {\n\t\t\tthis._loopStart = value;\n\t\t\tthis.port.postMessage({ type: \"loopStart\", data: value });\n\t\t}\n\t}\n\n\tget loopEnd() {\n\t\treturn this._loopEnd;\n\t}\n\tset loopEnd(value: number) {\n\t\tif (value !== this._loopEnd) {\n\t\t\tthis._loopEnd = value;\n\t\t\tthis.port.postMessage({ type: \"loopEnd\", data: value });\n\t\t}\n\t}\n\n\tget duration() {\n\t\treturn this._duration ?? this._buffer?.duration ?? -1;\n\t}\n\tset duration(value: number) {\n\t\tthis._duration = value;\n\t}\n\n\tget offset() {\n\t\treturn this._offset;\n\t}\n\tset offset(value: number) {\n\t\tthis._offset = value;\n\t}\n\n\tget playhead() {\n\t\treturn this._playhead;\n\t}\n\tset playhead(value: number) {\n\t\tthis.port.postMessage({ type: \"playhead\", data: value });\n\t}\n\n\tget playbackRate(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"playbackRate\")!;\n\t}\n\tget detune(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"detune\")!;\n\t}\n\tget highpass(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"highpass\")!;\n\t}\n\tget lowpass(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"lowpass\")!;\n\t}\n\tget gain(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"gain\")!;\n\t}\n\tget pan(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"pan\")!;\n\t}\n\n\tget fadeIn() {\n\t\treturn this._fadeIn;\n\t}\n\tset fadeIn(value: number) {\n\t\tthis._fadeIn = value;\n\t\tthis.port.postMessage({ type: \"fadeIn\", data: value });\n\t}\n\n\tget fadeOut() {\n\t\treturn this._fadeOut;\n\t}\n\n\tset fadeOut(value: number) {\n\t\tthis._fadeOut = value;\n\t\tthis.port.postMessage({ type: \"fadeOut\", data: value });\n\t}\n\n\tget loopCrossfade() {\n\t\treturn this._loopCrossfade;\n\t}\n\tset loopCrossfade(value: number) {\n\t\tthis._loopCrossfade = value;\n\t\tthis.port.postMessage({ type: \"loopCrossfade\", data: value });\n\t}\n\n\tdispose() {\n\t\tthis.port.postMessage({ type: \"dispose\" });\n\t\tthis.port.close();\n\t\tthis.ondisposed?.();\n\t\tthis._buffer = undefined;\n\t\tthis.onended = undefined;\n\t\tthis.onframe = undefined;\n\t\tthis.onlooped = undefined;\n\t\tthis.onpaused = undefined;\n\t\tthis.onresumed = undefined;\n\t\tthis.onstarted = undefined;\n\t\tthis.onstopped = undefined;\n\t\tthis.onscheduled = undefined;\n\t\tthis.onstatechange = undefined;\n\t\tthis.ondisposed = undefined;\n\t\tthis.state = \"disposed\";\n\t}\n}\n", "// AUTO-GENERATED \u2014 do not edit. Run 'bun run build:lib' to regenerate.\nexport const processorCode =\n\t\"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);\\n\\n//# debugId=12FC7555EABD465B64756E2164756E21\\n//# sourceMappingURL=processor.js.map\\n\";\n", "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", "// processor-kernel.ts \u2014 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 \u2014 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", "// AUTO-GENERATED \u2014 do not edit. Run 'bun run build:lib' to regenerate.\nexport const VERSION = \"0.1.6\";\n", "import { processorCode } from \"./processor-code\";\nimport { VERSION } from \"./version\";\n\nconst PACKAGE_NAME = \"@jadujoel/web-audio-clip-node\";\nconst PACKAGE_VERSION: string = VERSION;\n\n/** Blob URL from embedded processor code. Zero-config, default for npm users. */\nexport function getProcessorBlobUrl(): string {\n\tconst blob = new Blob([processorCode], { type: \"text/javascript\" });\n\treturn URL.createObjectURL(blob);\n}\n\n/** jsDelivr CDN URL. For script-tag / no-bundler usage. */\nexport function getProcessorCdnUrl(version = PACKAGE_VERSION): string {\n\treturn `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${version}/dist/processor.js`;\n}\n\n/** Custom URL relative to a base. For self-hosted processor.js. */\nexport function getProcessorModuleUrl(baseUrl = document.baseURI): string {\n\treturn new URL(\"./processor.js\", baseUrl).toString();\n}\n", "// ---------------------------------------------------------------------------\n// Control definitions \u2014 shared configuration for all audio controls\n// ---------------------------------------------------------------------------\n\nexport type ControlKey =\n\t| \"playhead\"\n\t| \"offset\"\n\t| \"duration\"\n\t| \"startDelay\"\n\t| \"stopDelay\"\n\t| \"fadeIn\"\n\t| \"fadeOut\"\n\t| \"loopStart\"\n\t| \"loopEnd\"\n\t| \"loopCrossfade\"\n\t| \"playbackRate\"\n\t| \"detune\"\n\t| \"gain\"\n\t| \"pan\"\n\t| \"lowpass\"\n\t| \"highpass\";\n\nexport interface ControlDef {\n\tkey: ControlKey;\n\tlabel: string;\n\tmin: number;\n\tmax: number;\n\tdefaultValue: number;\n\tprecision?: number;\n\tsnap?: string;\n\tpreset?: string;\n\ttitle?: string;\n\thasToggle?: boolean;\n\thasSnap?: boolean;\n\thasMaxLock?: boolean;\n\t/** When true, max defaults to audio file duration. */\n\tmaxLockedByDefault?: boolean;\n}\n\nexport const DEFAULT_TEMPO = 120;\nexport const SAMPLE_RATE = 48000;\n\nexport const controlDefs: ControlDef[] = [\n\t{\n\t\tkey: \"offset\",\n\t\tlabel: \"Offset\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"bar\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t\ttitle: \"Start position in the buffer (seconds).\",\n\t},\n\t{\n\t\tkey: \"duration\",\n\t\tlabel: \"Duration\",\n\t\tmin: -1,\n\t\tmax: 60,\n\t\tdefaultValue: -1,\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t\ttitle:\n\t\t\t\"How long to play before auto-stopping (seconds). -1 for full length.\",\n\t},\n\t{\n\t\tkey: \"startDelay\",\n\t\tlabel: \"StartDelay\",\n\t\tmin: 0,\n\t\tmax: 4,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\ttitle: \"Delay before starting (seconds).\",\n\t},\n\t{\n\t\tkey: \"stopDelay\",\n\t\tlabel: \"StopDelay\",\n\t\tmin: 0,\n\t\tmax: 4,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\ttitle: \"Delay before stopping (seconds).\",\n\t},\n\t{\n\t\tkey: \"fadeIn\",\n\t\tlabel: \"FadeIn\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\ttitle: \"Fade-in duration (seconds).\",\n\t},\n\t{\n\t\tkey: \"fadeOut\",\n\t\tlabel: \"FadeOut\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\ttitle: \"Fade-out duration (seconds).\",\n\t},\n];\n\nexport const loopControlDefs: ControlDef[] = [\n\t{\n\t\tkey: \"loopStart\",\n\t\tlabel: \"Start\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"bar\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t},\n\t{\n\t\tkey: \"loopEnd\",\n\t\tlabel: \"End\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"bar\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t},\n\t{\n\t\tkey: \"loopCrossfade\",\n\t\tlabel: \"Crossfade\",\n\t\tmin: 0,\n\t\tmax: 1,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t},\n];\n\nexport const paramDefs: ControlDef[] = [\n\t{\n\t\tkey: \"playbackRate\",\n\t\tlabel: \"PlaybackRate\",\n\t\tmin: -2,\n\t\tmax: 2,\n\t\tdefaultValue: 1,\n\t\tprecision: 2,\n\t\tpreset: \"playbackRate\",\n\t\thasToggle: true,\n\t\ttitle: \"Playback speed. Negative for reverse.\",\n\t},\n\t{\n\t\tkey: \"detune\",\n\t\tlabel: \"Detune\",\n\t\tmin: -2400,\n\t\tmax: 2400,\n\t\tdefaultValue: 0,\n\t\tprecision: 4,\n\t\tpreset: \"cents\",\n\t\thasToggle: true,\n\t\ttitle: \"Pitch shift in cents.\",\n\t},\n\t{\n\t\tkey: \"gain\",\n\t\tlabel: \"Gain\",\n\t\tmin: -100,\n\t\tmax: 0,\n\t\tdefaultValue: 0,\n\t\tprecision: 3,\n\t\tpreset: \"gain\",\n\t\thasToggle: true,\n\t\ttitle: \"Amplitude in dB.\",\n\t},\n\t{\n\t\tkey: \"pan\",\n\t\tlabel: \"Pan\",\n\t\tmin: -1,\n\t\tmax: 1,\n\t\tdefaultValue: 0,\n\t\tpreset: \"pan\",\n\t\thasToggle: true,\n\t\ttitle: \"-1 full left, 1 full right.\",\n\t},\n\t{\n\t\tkey: \"lowpass\",\n\t\tlabel: \"Lowpass\",\n\t\tmin: 32,\n\t\tmax: 16384,\n\t\tdefaultValue: 16384,\n\t\tpreset: \"hertz\",\n\t\thasToggle: true,\n\t\ttitle: \"Lowpass cutoff frequency.\",\n\t},\n\t{\n\t\tkey: \"highpass\",\n\t\tlabel: \"Highpass\",\n\t\tmin: 32,\n\t\tmax: 16384,\n\t\tdefaultValue: 32,\n\t\tpreset: \"hertz\",\n\t\thasToggle: true,\n\t\ttitle: \"Highpass cutoff frequency.\",\n\t},\n];\n\n/** Internal-only definition for playhead (not shown in UI). */\nconst playheadDef: ControlDef = {\n\tkey: \"playhead\",\n\tlabel: \"Playhead\",\n\tmin: 0,\n\tmax: 480000,\n\tdefaultValue: 0,\n\tprecision: 1,\n\tsnap: \"int\",\n\ttitle: \"Current sample position of buffer playback.\",\n};\n\nexport const allDefs = [\n\tplayheadDef,\n\t...controlDefs,\n\t...loopControlDefs,\n\t...paramDefs,\n];\n\nexport function buildDefaults(): {\n\tvalues: Record<ControlKey, number>;\n\tsnaps: Record<ControlKey, string>;\n\tenabled: Record<ControlKey, boolean>;\n\tmins: Record<ControlKey, number>;\n\tmaxs: Record<ControlKey, number>;\n\tmaxLocked: Record<ControlKey, boolean>;\n} {\n\tconst values = {} as Record<ControlKey, number>;\n\tconst snaps = {} as Record<ControlKey, string>;\n\tconst enabled = {} as Record<ControlKey, boolean>;\n\tconst mins = {} as Record<ControlKey, number>;\n\tconst maxs = {} as Record<ControlKey, number>;\n\tconst maxLocked = {} as Record<ControlKey, boolean>;\n\tfor (const d of allDefs) {\n\t\tvalues[d.key] = d.defaultValue;\n\t\tsnaps[d.key] = d.snap ?? \"none\";\n\t\tenabled[d.key] = true;\n\t\tmins[d.key] = d.min;\n\t\tmaxs[d.key] = d.max;\n\t\tmaxLocked[d.key] = d.maxLockedByDefault ?? false;\n\t}\n\treturn { values, snaps, enabled, mins, maxs, maxLocked };\n}\n", "export function formatValueText(\n\tvalue: number,\n\tkey: string | undefined,\n\tsnap: string,\n\ttempo: number,\n): string {\n\tswitch (key) {\n\t\tcase \"gain\":\n\t\t\treturn `${value.toFixed(1)} dB`;\n\t\tcase \"lowpass\":\n\t\tcase \"highpass\":\n\t\t\treturn `${Math.round(value)} Hz`;\n\t\tcase \"detune\":\n\t\t\treturn `${Math.round(value)} cents`;\n\t\tcase \"pan\":\n\t\t\tif (value === 0) return \"center\";\n\t\t\treturn value < 0\n\t\t\t\t? `${Math.abs(value).toFixed(2)} left`\n\t\t\t\t: `${value.toFixed(2)} right`;\n\t\tcase \"playbackRate\":\n\t\t\treturn `${value.toFixed(2)}x`;\n\t\tcase \"playhead\":\n\t\t\treturn `sample ${Math.round(value)}`;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n\tif (snap === \"beat\" || snap === \"bar\" || snap === \"8th\" || snap === \"16th\") {\n\t\tconst spb = 60 / tempo;\n\t\tif (snap === \"bar\") {\n\t\t\tconst bars = value / (spb * 4);\n\t\t\treturn `${Math.round(bars)} bars`;\n\t\t}\n\t\tif (snap === \"8th\") {\n\t\t\tconst eighths = value / (spb / 2);\n\t\t\treturn `${Math.round(eighths)} 8ths`;\n\t\t}\n\t\tif (snap === \"16th\") {\n\t\t\tconst sixteenths = value / (spb / 4);\n\t\t\treturn `${Math.round(sixteenths)} 16ths`;\n\t\t}\n\t\tconst beats = value / spb;\n\t\treturn `${Math.round(beats)} beats`;\n\t}\n\n\tif (snap === \"integer\") {\n\t\treturn `${Math.round(value)} s`;\n\t}\n\n\treturn `${value.toPrecision(4)} s`;\n}\n\nexport function formatTickLabel(\n\tvalue: number,\n\tkey: string | undefined,\n\tsnap: string,\n\ttempo: number,\n): string {\n\tswitch (key) {\n\t\tcase \"gain\":\n\t\t\treturn value.toFixed(1);\n\t\tcase \"lowpass\":\n\t\tcase \"highpass\":\n\t\t\treturn `${Math.round(value)}`;\n\t\tcase \"detune\":\n\t\t\treturn `${Math.round(value)}`;\n\t\tcase \"pan\":\n\t\t\tif (value === 0) return \"C\";\n\t\t\treturn value < 0\n\t\t\t\t? `${Math.abs(value).toFixed(2)}L`\n\t\t\t\t: `${value.toFixed(2)}R`;\n\t\tcase \"playbackRate\":\n\t\t\treturn `${value.toFixed(2)}x`;\n\t\tcase \"playhead\":\n\t\t\treturn `${Math.round(value)}`;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n\tif (snap === \"beat\" || snap === \"bar\" || snap === \"8th\" || snap === \"16th\") {\n\t\tconst spb = 60 / tempo;\n\t\tif (snap === \"bar\") return `${Math.round(value / (spb * 4))}`;\n\t\tif (snap === \"8th\") return `${Math.round(value / (spb / 2))}`;\n\t\tif (snap === \"16th\") return `${Math.round(value / (spb / 4))}`;\n\t\treturn `${Math.round(value / spb)}`;\n\t}\n\n\tif (snap === \"integer\") return `${Math.round(value)}`;\n\n\treturn value.toPrecision(4);\n}\n", "import type { ControlKey } from \"./controlDefs\";\n\nexport type LinkedControlPairKey = \"fadeOutStopDelay\" | \"loopStartEnd\";\n\nexport interface LinkedControlPairDef {\n\tkey: LinkedControlPairKey;\n\tlabel: string;\n\tcontrols: readonly [ControlKey, ControlKey];\n}\n\nexport const transportLinkedControlPairs: readonly LinkedControlPairDef[] = [\n\t{\n\t\tkey: \"fadeOutStopDelay\",\n\t\tlabel: \"Link StopDelay and FadeOut\",\n\t\tcontrols: [\"stopDelay\", \"fadeOut\"],\n\t},\n];\n\nexport const loopLinkedControlPairs: readonly LinkedControlPairDef[] = [\n\t{\n\t\tkey: \"loopStartEnd\",\n\t\tlabel: \"Link Start and End\",\n\t\tcontrols: [\"loopStart\", \"loopEnd\"],\n\t},\n];\n\nconst allLinkedControlPairs = [\n\t...transportLinkedControlPairs,\n\t...loopLinkedControlPairs,\n];\n\nexport function buildLinkedControlPairDefaults(): Record<\n\tLinkedControlPairKey,\n\tboolean\n> {\n\treturn {\n\t\tfadeOutStopDelay: false,\n\t\tloopStartEnd: false,\n\t};\n}\n\nexport function getLinkedControlPairForControl(\n\tcontrolKey: ControlKey,\n): LinkedControlPairDef | undefined {\n\treturn allLinkedControlPairs.find(\n\t\t(pair) =>\n\t\t\tpair.controls[0] === controlKey || pair.controls[1] === controlKey,\n\t);\n}\n\nexport function getActiveLinkedControls(\n\tcontrolKey: ControlKey,\n\tlinkedPairs: Record<LinkedControlPairKey, boolean>,\n): readonly ControlKey[] {\n\tconst pair = getLinkedControlPairForControl(controlKey);\n\tif (pair && linkedPairs[pair.key]) {\n\t\treturn pair.controls;\n\t}\n\n\treturn [controlKey];\n}\n\nexport function getLinkedControlUpdates({\n\tpair,\n\tchangedKey,\n\tnextValue,\n\tvalues,\n\tmins,\n\tmaxs,\n}: {\n\tpair: LinkedControlPairDef;\n\tchangedKey: ControlKey;\n\tnextValue: number;\n\tvalues: Record<ControlKey, number>;\n\tmins: Record<ControlKey, number>;\n\tmaxs: Record<ControlKey, number>;\n}): Partial<Record<ControlKey, number>> {\n\tconst [firstKey, secondKey] = pair.controls;\n\tif (changedKey !== firstKey && changedKey !== secondKey) {\n\t\treturn { [changedKey]: nextValue };\n\t}\n\n\tconst otherKey = changedKey === firstKey ? secondKey : firstKey;\n\tconst currentChanged = values[changedKey];\n\tconst currentOther = values[otherKey];\n\tconst requestedShift = nextValue - currentChanged;\n\tconst minShift = Math.max(\n\t\tmins[changedKey] - currentChanged,\n\t\tmins[otherKey] - currentOther,\n\t);\n\tconst maxShift = Math.min(\n\t\tmaxs[changedKey] - currentChanged,\n\t\tmaxs[otherKey] - currentOther,\n\t);\n\tconst appliedShift = Math.min(Math.max(requestedShift, minShift), maxShift);\n\n\treturn {\n\t\t[changedKey]: currentChanged + appliedShift,\n\t\t[otherKey]: currentOther + appliedShift,\n\t};\n}\n", "const cachePromise = caches.open(\"sound-files\");\n\nexport async function loadFromCache(\n\turl: string,\n): Promise<ArrayBuffer | undefined> {\n\tconst startTime = performance.now();\n\tconst cache = await cachePromise;\n\tconst response = await cache.match(url);\n\tif (response) {\n\t\tconsole.log(\n\t\t\t`[cache] Loaded ${url} from CacheStorage in ${(performance.now() - startTime).toFixed(0)}ms`,\n\t\t);\n\t\treturn response.arrayBuffer();\n\t}\n\tconst fetched = await fetch(url);\n\tif (fetched.ok) {\n\t\tcache.put(url, fetched.clone()).catch(() => {});\n\t\tconsole.log(\n\t\t\t`[cache] Loaded ${url} from network in ${(performance.now() - startTime).toFixed(0)}ms`,\n\t\t);\n\t\treturn fetched.arrayBuffer();\n\t}\n\treturn undefined;\n}\n", "const DB_NAME = \"clip-audio-store\";\nconst DB_VERSION = 1;\nconst STORE_NAME = \"files\";\nconst LAST_FILE_KEY = \"last-uploaded\";\n\nfunction openDB(): Promise<IDBDatabase> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst request = indexedDB.open(DB_NAME, DB_VERSION);\n\t\trequest.onupgradeneeded = () => {\n\t\t\tconst db = request.result;\n\t\t\tif (!db.objectStoreNames.contains(STORE_NAME)) {\n\t\t\t\tdb.createObjectStore(STORE_NAME);\n\t\t\t}\n\t\t};\n\t\trequest.onsuccess = () => resolve(request.result);\n\t\trequest.onerror = () => reject(request.error);\n\t});\n}\n\nfunction tx(db: IDBDatabase, mode: IDBTransactionMode): IDBObjectStore {\n\treturn db.transaction(STORE_NAME, mode).objectStore(STORE_NAME);\n}\n\nexport interface StoredFile {\n\tname: string;\n\tarrayBuffer: ArrayBuffer;\n}\n\nexport async function saveUploadedFile(\n\tname: string,\n\tarrayBuffer: ArrayBuffer,\n): Promise<void> {\n\tconst db = await openDB();\n\tconst store = tx(db, \"readwrite\");\n\tconst data: StoredFile = { name, arrayBuffer };\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst req = store.put(data, LAST_FILE_KEY);\n\t\treq.onsuccess = () => resolve();\n\t\treq.onerror = () => reject(req.error);\n\t});\n}\n\nexport async function loadUploadedFile(): Promise<StoredFile | null> {\n\tconst db = await openDB();\n\tconst store = tx(db, \"readonly\");\n\treturn new Promise((resolve, reject) => {\n\t\tconst req = store.get(LAST_FILE_KEY);\n\t\treq.onsuccess = () => resolve(req.result ?? null);\n\t\treq.onerror = () => reject(req.error);\n\t});\n}\n"],
5
- "mappings": "AAAO,SAASA,GAAUC,EAAqB,CAC9C,OAAO,KAAK,IAAI,GAAK,KAAK,MAAMA,CAAG,EAAG,IAAK,CAC5C,CAEO,SAASC,GAAUC,EAAoB,CAC7C,MAAO,MAAOA,EAAK,GACpB,CAEA,IAAMC,GAAuB,CAAC,OAAQ,MAAO,MAAO,MAAM,EAI1D,SAASC,EAAMC,EAAeC,EAAaC,EAAqB,CAC/D,OAAO,KAAK,IAAI,KAAK,IAAIF,EAAOC,CAAG,EAAGC,CAAG,CAC1C,CAEO,SAASC,GAAoBC,EAAyC,CAC5E,OAAON,GAAqB,SAASM,CAAyB,CAC/D,CAEO,SAASC,EACfD,EACAE,EACgB,CAChB,GAAI,CAAC,OAAO,SAASA,CAAK,GAAKA,GAAS,EAAG,OAAO,KAElD,IAAMC,EAAiB,GAAKD,EAC5B,OAAQF,EAAM,CACb,IAAK,OACJ,OAAOG,EACR,IAAK,MACJ,OAAOA,EAAiB,EACzB,IAAK,MACJ,OAAOA,EAAiB,EACzB,IAAK,OACJ,OAAOA,EAAiB,EACzB,QACC,OAAO,IACT,CACD,CAEO,SAASC,GACfR,EACAI,EACAK,EACAC,EACAT,EACAC,EACS,CAIT,GAHI,CAACC,GAAoBC,CAAI,GAGzBJ,EAAQ,EACX,OAAOD,EAAMC,EAAOC,EAAKC,CAAG,EAG7B,IAAMS,EAAcN,EAAqBD,EAAMK,CAAQ,EACjDG,EAAcP,EAAqB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AW,CAC5C,IAAMW,EAAMF,EAAM,IAAIC,EAAMb,EAAa,EACzCc,EAAI,UAAY,IAAMZ,EAAQ,EAC9BY,EAAI,QAAU,IAAMX,EAAOW,EAAI,KAAK,CACrC,CAAC,CACF,CAEA,eAAsBC,IAA+C,CACpE,IAAMT,EAAK,MAAML,GAAO,EAClBW,EAAQL,GAAGD,EAAI,UAAU,EAC/B,OAAO,IAAI,QAAQ,CAACJ,EAASC,IAAW,CACvC,IAAMW,EAAMF,EAAM,IAAIZ,EAAa,EACnCc,EAAI,UAAY,IAAMZ,EAAQY,EAAI,QAAU,IAAI,EAChDA,EAAI,QAAU,IAAMX,EAAOW,EAAI,KAAK,CACrC,CAAC,CACF",
6
- "names": ["dbFromLin", "lin", "linFromDb", "db", "TEMPO_RELATIVE_SNAPS", "clamp", "value", "min", "max", "isTempoRelativeSnap", "snap", "getTempoSnapInterval", "tempo", "secondsPerBeat", "remapTempoRelativeValue", "oldTempo", "newTempo", "oldInterval", "newInterval", "count", "getSnappedValue", "interval", "presets", "_", "i", "float32ArrayFromAudioBuffer", "buffer", "audioBufferFromFloat32Array", "context", "data", "generateSnapPoints", "points", "start", "v", "ClipNode", "context", "options", "audioBufferFromFloat32Array", "message", "type", "data", "_ct", "_cf", "ph", "tt", "newState", "value", "ab", "totalLength", "channels", "duration", "startSample", "channelData", "when", "offset", "initialDelay", "processorCode", "State", "SAMPLE_BLOCK_SIZE", "createStreamBufferState", "buffer", "totalLength", "hasBuffer", "getBufferLength", "getLogicalBufferLength", "properties", "createSilentBuffer", "channels", "length", "mergeWrittenSpan", "spans", "nextSpan", "merged", "a", "b", "result", "span", "previous", "getCommittedLength", "committedLength", "resetLowWaterState", "streamBuffer", "playhead", "ensureBufferCapacity", "requiredChannels", "requiredLength", "currentLength", "currentChannels", "nextLength", "nextChannels", "nextBuffer", "ch", "applyBufferRangeWrite", "write", "startSample", "writeLength", "requestedTotalLength", "applyPendingBufferWrites", "setWholeBuffer", "getProperties", "opts", "sampleRate", "duration", "loop", "loopStart", "loopEnd", "loopCrossfade", "offset", "startWhen", "stopWhen", "pauseWhen", "resumeWhen", "playedSamples", "state", "State", "timesLooped", "fadeInDuration", "fadeOutDuration", "enableFadeIn", "enableFadeOut", "enableLoopStart", "enableLoopEnd", "enableLoopCrossfade", "enableHighpass", "enableLowpass", "enableGain", "enablePan", "enableDetune", "enablePlaybackRate", "getBufferDurationSeconds", "normalizeLoopBounds", "bufferDuration", "setOffset", "offs", "findIndexesNormal", "p", "bufferLength", "loopStartSamples", "loopEndSamples", "indexes", "i", "head", "nextPlayhead", "looped", "findIndexesWithPlaybackRates", "playbackRates", "rate", "fill", "target", "source", "nc", "fillWithSilence", "j", "monoToStereo", "signal", "r", "copy", "checkNans", "output", "numNans", "createFilterState", "gainFilter", "arr", "gains", "g", "panFilter", "pans", "pan", "leftGain", "rightGain", "lowpassFilter", "cutoffs", "states", "channel", "x_1", "x_2", "y_1", "y_2", "cutoff", "w0", "alpha", "b0", "b1", "b2", "a0", "a1", "a2", "h0", "h1", "h2", "h3", "h4", "x", "y", "prevCutoff", "highpassFilter", "handleProcessorMessage", "message", "currentTime", "type", "data", "init", "endData", "d", "st", "processBlock", "props", "outputs", "parameters", "ctx", "filterState", "messages", "output0", "sourceLength", "detunes", "lowpass", "highpass", "hasIncompleteStream", "durationSamples", "loopCrossfadeSamples", "maxLoopStartSample", "loopLengthSamples", "needsDetune", "effectiveRates", "len", "cents", "useRateIndexing", "isZeroRateBlock", "blockParams", "ended", "updatedPlayhead", "underrunSample", "index", "xfadeNumSamples", "isWithinLoopRange", "needsCrossfade", "endIndex", "elapsed", "n", "position", "srcIdx", "startIndex", "fadeInSamples", "remaining", "t", "fadeOutSamples", "remainingSamples", "sampleRemaining", "VERSION", "PACKAGE_NAME", "PACKAGE_VERSION", "VERSION", "getProcessorBlobUrl", "blob", "processorCode", "getProcessorCdnUrl", "version", "getProcessorModuleUrl", "baseUrl", "DEFAULT_TEMPO", "SAMPLE_RATE", "controlDefs", "loopControlDefs", "paramDefs", "playheadDef", "allDefs", "buildDefaults", "values", "snaps", "enabled", "mins", "maxs", "maxLocked", "d", "formatValueText", "value", "key", "snap", "tempo", "spb", "bars", "eighths", "sixteenths", "beats", "formatTickLabel", "transportLinkedControlPairs", "loopLinkedControlPairs", "allLinkedControlPairs", "buildLinkedControlPairDefaults", "getLinkedControlPairForControl", "controlKey", "pair", "getActiveLinkedControls", "linkedPairs", "getLinkedControlUpdates", "changedKey", "nextValue", "values", "mins", "maxs", "firstKey", "secondKey", "otherKey", "currentChanged", "currentOther", "requestedShift", "minShift", "maxShift", "appliedShift", "cachePromise", "loadFromCache", "url", "startTime", "cache", "response", "fetched", "DB_NAME", "STORE_NAME", "LAST_FILE_KEY", "openDB", "resolve", "reject", "request", "DB_NAME", "db", "tx", "mode", "saveUploadedFile", "name", "arrayBuffer", "store", "data", "req", "loadUploadedFile"]
4
+ "sourcesContent": ["export function dbFromLin(lin: number): number {\n\treturn Math.max(20 * Math.log10(lin), -1000);\n}\n\nexport function linFromDb(db: number): number {\n\treturn 10 ** (db / 20);\n}\n\nconst TEMPO_RELATIVE_SNAPS = [\"beat\", \"bar\", \"8th\", \"16th\"] as const;\n\nexport type TempoRelativeSnap = (typeof TEMPO_RELATIVE_SNAPS)[number];\n\nfunction clamp(value: number, min: number, max: number): number {\n\treturn Math.min(Math.max(value, min), max);\n}\n\nexport function isTempoRelativeSnap(snap: string): snap is TempoRelativeSnap {\n\treturn TEMPO_RELATIVE_SNAPS.includes(snap as TempoRelativeSnap);\n}\n\nexport function getTempoSnapInterval(\n\tsnap: string,\n\ttempo: number,\n): number | null {\n\tif (!Number.isFinite(tempo) || tempo <= 0) return null;\n\n\tconst secondsPerBeat = 60 / tempo;\n\tswitch (snap) {\n\t\tcase \"beat\":\n\t\t\treturn secondsPerBeat;\n\t\tcase \"bar\":\n\t\t\treturn secondsPerBeat * 4;\n\t\tcase \"8th\":\n\t\t\treturn secondsPerBeat / 2;\n\t\tcase \"16th\":\n\t\t\treturn secondsPerBeat / 4;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nexport function remapTempoRelativeValue(\n\tvalue: number,\n\tsnap: string,\n\toldTempo: number,\n\tnewTempo: number,\n\tmin: number,\n\tmax: number,\n): number {\n\tif (!isTempoRelativeSnap(snap)) {\n\t\treturn clamp(value, min, max);\n\t}\n\tif (value < 0) {\n\t\treturn clamp(value, min, max);\n\t}\n\n\tconst oldInterval = getTempoSnapInterval(snap, oldTempo);\n\tconst newInterval = getTempoSnapInterval(snap, newTempo);\n\tif (oldInterval == null || newInterval == null) {\n\t\treturn clamp(value, min, max);\n\t}\n\n\tconst count = Math.round(value / oldInterval);\n\treturn clamp(count * newInterval, min, max);\n}\n\nexport function getSnappedValue(\n\tvalue: number,\n\tsnap: string,\n\ttempo: number,\n): number {\n\tconst interval = getTempoSnapInterval(snap, tempo);\n\tif (interval != null) {\n\t\treturn Math.round(value / interval) * interval;\n\t}\n\n\tswitch (snap) {\n\t\tcase \"int\":\n\t\t\treturn Math.round(value);\n\t\tdefault:\n\t\t\treturn value;\n\t}\n}\n\nexport interface SliderPreset {\n\tsnaps?: number[];\n\tticks?: number[];\n\tmin?: number;\n\tmax?: number;\n\tskew?: number;\n\tstep?: number;\n\tlogarithmic?: boolean;\n}\n\nexport const presets: Record<string, SliderPreset> = {\n\thertz: {\n\t\tsnaps: [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],\n\t\tticks: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],\n\t\tmin: 32,\n\t\tmax: 16384,\n\t\tlogarithmic: true,\n\t},\n\tdecibel: {\n\t\tticks: [-48, -24, -12, -6, -3, 0],\n\t\tmin: -60,\n\t\tmax: 0,\n\t\tskew: 1,\n\t},\n\tcents: {\n\t\tsnaps: Array.from({ length: 49 }, (_, i) => (i - 24) * 100), // semitones: -2400..2400 by 100\n\t\tticks: [-2400, -1200, 0, 1200, 2400],\n\t\tmin: -2400,\n\t\tmax: 2400,\n\t\tskew: 1,\n\t\tstep: 1,\n\t},\n\tplaybackRate: {\n\t\tsnaps: [-2, -1, -0.5, 0, 0.5, 1, 1.5, 2],\n\t\tticks: [-2, -1, 0, 1, 2],\n\t\tmin: -2,\n\t\tmax: 2,\n\t\tskew: 1,\n\t},\n\tgain: {\n\t\tsnaps: [-60, -48, -36, -24, -18, -12, -9, -6, -3, -1, 0],\n\t\tticks: [-48, -24, -12, -6, -3, 0],\n\t\tmin: -100,\n\t\tmax: 0,\n\t\tskew: 6,\n\t},\n\tpan: {\n\t\tsnaps: [-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],\n\t\tticks: [-1, -0.5, 0, 0.5, 1],\n\t\tmin: -1,\n\t\tmax: 1,\n\t\tskew: 1,\n\t},\n};\n\nexport function float32ArrayFromAudioBuffer(\n\tbuffer: AudioBuffer,\n): Float32Array[] {\n\treturn buffer.numberOfChannels === 1\n\t\t? [buffer.getChannelData(0)]\n\t\t: [buffer.getChannelData(0), buffer.getChannelData(1)];\n}\n\nexport function audioBufferFromFloat32Array(\n\tcontext: BaseAudioContext,\n\tdata?: Float32Array[],\n): AudioBuffer | undefined {\n\tif (!data || data.length === 0) return undefined;\n\tconst buffer = context.createBuffer(\n\t\tdata.length,\n\t\tdata[0].length,\n\t\tcontext.sampleRate,\n\t);\n\tfor (let i = 0; i < data.length; i++) {\n\t\tbuffer.copyToChannel(new Float32Array(data[i]), i);\n\t}\n\treturn buffer;\n}\n\nexport function generateSnapPoints(\n\tsnap: string,\n\ttempo: number,\n\tmin: number,\n\tmax: number,\n): number[] {\n\tconst interval =\n\t\tgetTempoSnapInterval(snap, tempo) ?? (snap === \"int\" ? 1 : null);\n\tif (interval == null) return [];\n\tif (interval <= 0) return [];\n\tconst points: number[] = [];\n\tconst start = Math.ceil(min / interval) * interval;\n\tfor (let v = start; v <= max; v += interval) {\n\t\tpoints.push(Math.round(v * 1e10) / 1e10);\n\t}\n\treturn points;\n}\n", "import type { ClipNodeState, ClipWorkletOptions, FrameData } from \"./types\";\nimport { audioBufferFromFloat32Array } from \"./utils\";\n\nexport class ClipNode extends AudioWorkletNode {\n\tonscheduled?: () => void;\n\tonstarted?: () => void;\n\tonpaused?: () => void;\n\tonresumed?: () => void;\n\tonended?: () => void;\n\tonlooped?: () => void;\n\tonstopped?: () => void;\n\tonframe?: (data: FrameData) => void;\n\tondisposed?: () => void;\n\tonstatechange?: (state: ClipNodeState) => void;\n\n\tprivate _buffer?: AudioBuffer;\n\tprivate _loopStart = 0;\n\tprivate _loopEnd = 0;\n\tprivate _loop = false;\n\tprivate _offset = 0;\n\tprivate _playhead = 0;\n\tprivate _fadeIn = 0;\n\tprivate _fadeOut = 0;\n\tprivate _loopCrossfade = 0;\n\tprivate _duration = -1;\n\tprivate _previousState: ClipNodeState = \"initial\";\n\tprivate _bufferWriteCursor = 0;\n\tprivate _hasStreamingPort = false;\n\n\ttimesLooped = 0;\n\tstate: ClipNodeState = \"initial\";\n\tcpu = 0;\n\n\tconstructor(context: BaseAudioContext, options: ClipWorkletOptions = {}) {\n\t\tsuper(context, \"ClipProcessor\", {\n\t\t\tnumberOfInputs: options.numberOfInputs ?? 0,\n\t\t\toutputChannelCount: options.outputChannelCount ?? [2],\n\t\t\tprocessorOptions: options.processorOptions,\n\t\t\tchannelCount: options.channelCount,\n\t\t\tchannelCountMode: options.channelCountMode,\n\t\t\tchannelInterpretation: options.channelInterpretation,\n\t\t\tnumberOfOutputs: options.numberOfOutputs,\n\t\t\tparameterData: options.parameterData,\n\t\t});\n\n\t\tthis._buffer = audioBufferFromFloat32Array(\n\t\t\tthis.context,\n\t\t\toptions.processorOptions?.buffer,\n\t\t);\n\t\tthis.port.onmessage = this.handleMessage;\n\t}\n\n\tprivate handleMessage = (message: MessageEvent) => {\n\t\tconst { type, data } = message.data;\n\t\tswitch (type) {\n\t\t\tcase \"frame\": {\n\t\t\t\tconst [_ct, _cf, ph, tt] = data as [number, number, number, number];\n\t\t\t\tthis._playhead = ph;\n\t\t\t\tthis.cpu = tt;\n\t\t\t\tthis.onframe?.(data);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"scheduled\":\n\t\t\t\tthis.setState(\"scheduled\");\n\t\t\t\tthis.onscheduled?.();\n\t\t\t\tbreak;\n\t\t\tcase \"started\":\n\t\t\t\tthis.setState(\"started\");\n\t\t\t\tthis.onstarted?.();\n\t\t\t\tbreak;\n\t\t\tcase \"stopped\":\n\t\t\t\tthis.setState(\"stopped\");\n\t\t\t\tthis.onstopped?.();\n\t\t\t\tbreak;\n\t\t\tcase \"paused\":\n\t\t\t\tthis.setState(\"paused\");\n\t\t\t\tthis.onpaused?.();\n\t\t\t\tbreak;\n\t\t\tcase \"resume\":\n\t\t\t\tthis.setState(\"resumed\");\n\t\t\t\tthis.onresumed?.();\n\t\t\t\tbreak;\n\t\t\tcase \"ended\":\n\t\t\t\tthis.setState(\"ended\");\n\t\t\t\tthis.onended?.();\n\t\t\t\tbreak;\n\t\t\tcase \"looped\":\n\t\t\t\tthis.timesLooped++;\n\t\t\t\tthis.onlooped?.();\n\t\t\t\tbreak;\n\t\t\tcase \"disposed\":\n\t\t\t\tthis.setState(\"disposed\");\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tprivate setState(newState: ClipNodeState) {\n\t\tthis._previousState = this.state;\n\t\tthis.state = newState;\n\t\tif (this.state !== this._previousState) {\n\t\t\tthis.onstatechange?.(this.state);\n\t\t}\n\t}\n\n\ttoggleGain(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleGain\", data: value });\n\t}\n\ttogglePlaybackRate(value = true) {\n\t\tthis.port.postMessage({ type: \"togglePlaybackRate\", data: value });\n\t}\n\ttoggleDetune(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleDetune\", data: value });\n\t}\n\ttogglePan(value = true) {\n\t\tthis.port.postMessage({ type: \"togglePan\", data: value });\n\t}\n\ttoggleHighpass(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleHighpass\", data: value });\n\t}\n\ttoggleLowpass(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLowpass\", data: value });\n\t}\n\ttoggleFadeIn(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleFadeIn\", data: value });\n\t}\n\ttoggleFadeOut(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleFadeOut\", data: value });\n\t}\n\ttoggleLoopCrossfade(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLoopCrossfade\", data: value });\n\t}\n\ttoggleLoopStart(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLoopStart\", data: value });\n\t}\n\ttoggleLoopEnd(value = true) {\n\t\tthis.port.postMessage({ type: \"toggleLoopEnd\", data: value });\n\t}\n\tlogState() {\n\t\tthis.port.postMessage({ type: \"logState\" });\n\t}\n\n\tget buffer(): AudioBuffer | undefined {\n\t\treturn this._buffer;\n\t}\n\tset buffer(ab: AudioBuffer) {\n\t\tthis._buffer = ab;\n\t\tthis._bufferWriteCursor = ab.length;\n\t\tif (this._loopStart >= ab.duration) {\n\t\t\tthis._loopStart = 0;\n\t\t}\n\t\tif (this._loopEnd <= this._loopStart || this._loopEnd > ab.duration) {\n\t\t\tthis._loopEnd = ab.duration;\n\t\t}\n\t\tconst data =\n\t\t\tab.numberOfChannels === 1\n\t\t\t\t? [ab.getChannelData(0)]\n\t\t\t\t: [ab.getChannelData(0), ab.getChannelData(1)];\n\t\tthis.port.postMessage({ type: \"buffer\", data });\n\t\tthis.port.postMessage({ type: \"loopStart\", data: this._loopStart });\n\t\tthis.port.postMessage({ type: \"loopEnd\", data: this._loopEnd });\n\t}\n\n\ttransferPort(port: MessagePort) {\n\t\tthis._hasStreamingPort = true;\n\t\tthis.port.postMessage({ type: \"transferPort\", data: port }, [port]);\n\t}\n\n\tinitializeBuffer(\n\t\ttotalLength: number,\n\t\tchannels: number,\n\t\toptions: { streaming?: boolean } = {},\n\t) {\n\t\tthis._buffer = this.context.createBuffer(\n\t\t\tchannels,\n\t\t\ttotalLength,\n\t\t\tthis.context.sampleRate,\n\t\t);\n\t\tthis._bufferWriteCursor = 0;\n\t\tconst duration = totalLength / this.context.sampleRate;\n\t\tif (this._loopStart >= duration) {\n\t\t\tthis._loopStart = 0;\n\t\t}\n\t\tif (this._loopEnd <= this._loopStart || this._loopEnd > duration) {\n\t\t\tthis._loopEnd = duration;\n\t\t}\n\t\tthis.port.postMessage({\n\t\t\ttype: \"bufferInit\",\n\t\t\tdata: {\n\t\t\t\tchannels,\n\t\t\t\ttotalLength,\n\t\t\t\tstreaming: options.streaming ?? true,\n\t\t\t},\n\t\t});\n\t\tthis.port.postMessage({ type: \"loopStart\", data: this._loopStart });\n\t\tthis.port.postMessage({ type: \"loopEnd\", data: this._loopEnd });\n\t}\n\n\treplaceBufferRange(\n\t\tstartSample: number,\n\t\tchannelData: Float32Array[],\n\t\toptions: { totalLength?: number | null; streamEnded?: boolean } = {},\n\t) {\n\t\tthis.port.postMessage({\n\t\t\ttype: \"bufferRange\",\n\t\t\tdata: {\n\t\t\t\tstartSample,\n\t\t\t\tchannelData,\n\t\t\t\ttotalLength: options.totalLength,\n\t\t\t\tstreamEnded: options.streamEnded,\n\t\t\t},\n\t\t});\n\t\tthis._bufferWriteCursor = Math.max(\n\t\t\tthis._bufferWriteCursor,\n\t\t\tstartSample + (channelData[0]?.length ?? 0),\n\t\t);\n\t}\n\n\tappendBufferRange(\n\t\tchannelData: Float32Array[],\n\t\toptions: { totalLength?: number | null; streamEnded?: boolean } = {},\n\t) {\n\t\tthis.replaceBufferRange(this._bufferWriteCursor, channelData, options);\n\t}\n\n\tfinalizeBuffer(totalLength?: number) {\n\t\tthis.port.postMessage({ type: \"bufferEnd\", data: { totalLength } });\n\t}\n\n\tstart(when?: number, offset?: number, duration?: number) {\n\t\tif (!this._buffer && !this._hasStreamingPort) {\n\t\t\tconsole.error(\"Buffer not set.\");\n\t\t\treturn;\n\t\t}\n\t\tthis.port.postMessage({ type: \"start\", data: { when, offset, duration } });\n\t}\n\n\tstop(when: number = this.context.currentTime, initialDelay = 0) {\n\t\tthis.port.postMessage({\n\t\t\ttype: \"stop\",\n\t\t\tdata: when + initialDelay + this._fadeOut + 0.2,\n\t\t});\n\t}\n\n\tpause(when: number = this.context.currentTime) {\n\t\tthis.port.postMessage({ type: \"pause\", data: when });\n\t}\n\n\tresume(when: number = this.context.currentTime) {\n\t\tthis.port.postMessage({ type: \"resume\", data: when });\n\t}\n\n\tget loop() {\n\t\treturn this._loop;\n\t}\n\tset loop(value: boolean) {\n\t\tif (this._loop !== value) {\n\t\t\tthis._loop = value;\n\t\t\tthis.port.postMessage({ type: \"loop\", data: value });\n\t\t}\n\t}\n\n\tget loopStart() {\n\t\treturn this._loopStart;\n\t}\n\tset loopStart(value: number) {\n\t\tif (value !== this._loopStart) {\n\t\t\tthis._loopStart = value;\n\t\t\tthis.port.postMessage({ type: \"loopStart\", data: value });\n\t\t}\n\t}\n\n\tget loopEnd() {\n\t\treturn this._loopEnd;\n\t}\n\tset loopEnd(value: number) {\n\t\tif (value !== this._loopEnd) {\n\t\t\tthis._loopEnd = value;\n\t\t\tthis.port.postMessage({ type: \"loopEnd\", data: value });\n\t\t}\n\t}\n\n\tget duration() {\n\t\treturn this._duration ?? this._buffer?.duration ?? -1;\n\t}\n\tset duration(value: number) {\n\t\tthis._duration = value;\n\t}\n\n\tget offset() {\n\t\treturn this._offset;\n\t}\n\tset offset(value: number) {\n\t\tthis._offset = value;\n\t}\n\n\tget playhead() {\n\t\treturn this._playhead;\n\t}\n\tset playhead(value: number) {\n\t\tthis.port.postMessage({ type: \"playhead\", data: value });\n\t}\n\n\tget playbackRate(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"playbackRate\")!;\n\t}\n\tget detune(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"detune\")!;\n\t}\n\tget highpass(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"highpass\")!;\n\t}\n\tget lowpass(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"lowpass\")!;\n\t}\n\tget gain(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"gain\")!;\n\t}\n\tget pan(): AudioParam {\n\t\t// biome-ignore lint/style/noNonNullAssertion: it is definitely set in the processor\n\t\treturn this.parameters.get(\"pan\")!;\n\t}\n\n\tget fadeIn() {\n\t\treturn this._fadeIn;\n\t}\n\tset fadeIn(value: number) {\n\t\tthis._fadeIn = value;\n\t\tthis.port.postMessage({ type: \"fadeIn\", data: value });\n\t}\n\n\tget fadeOut() {\n\t\treturn this._fadeOut;\n\t}\n\n\tset fadeOut(value: number) {\n\t\tthis._fadeOut = value;\n\t\tthis.port.postMessage({ type: \"fadeOut\", data: value });\n\t}\n\n\tget loopCrossfade() {\n\t\treturn this._loopCrossfade;\n\t}\n\tset loopCrossfade(value: number) {\n\t\tthis._loopCrossfade = value;\n\t\tthis.port.postMessage({ type: \"loopCrossfade\", data: value });\n\t}\n\n\tdispose() {\n\t\tthis.port.postMessage({ type: \"dispose\" });\n\t\tthis.port.close();\n\t\tthis.ondisposed?.();\n\t\tthis._buffer = undefined;\n\t\tthis.onended = undefined;\n\t\tthis.onframe = undefined;\n\t\tthis.onlooped = undefined;\n\t\tthis.onpaused = undefined;\n\t\tthis.onresumed = undefined;\n\t\tthis.onstarted = undefined;\n\t\tthis.onstopped = undefined;\n\t\tthis.onscheduled = undefined;\n\t\tthis.onstatechange = undefined;\n\t\tthis.ondisposed = undefined;\n\t\tthis.state = \"disposed\";\n\t}\n}\n", "// AUTO-GENERATED \u2014 do not edit. Run 'bun run build:lib' to regenerate.\nexport const processorCode =\n\t\"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);\\n\\n//# debugId=78F68534B0A72CAE64756E2164756E21\\n//# sourceMappingURL=processor.js.map\\n\";\n", "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", "// processor-kernel.ts \u2014 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 \u2014 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", "// AUTO-GENERATED \u2014 do not edit. Run 'bun run build:lib' to regenerate.\nexport const VERSION = \"0.1.7\";\n", "import { processorCode } from \"./processor-code\";\nimport { VERSION } from \"./version\";\n\nconst PACKAGE_NAME = \"@jadujoel/web-audio-clip-node\";\nconst PACKAGE_VERSION: string = VERSION;\n\n/** Blob URL from embedded processor code. Zero-config, default for npm users. */\nexport function getProcessorBlobUrl(): string {\n\tconst blob = new Blob([processorCode], { type: \"text/javascript\" });\n\treturn URL.createObjectURL(blob);\n}\n\n/** jsDelivr CDN URL. For script-tag / no-bundler usage. */\nexport function getProcessorCdnUrl(version = PACKAGE_VERSION): string {\n\treturn `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${version}/dist/processor.js`;\n}\n\n/** Custom URL relative to a base. For self-hosted processor.js. */\nexport function getProcessorModuleUrl(baseUrl = document.baseURI): string {\n\treturn new URL(\"./processor.js\", baseUrl).toString();\n}\n", "// ---------------------------------------------------------------------------\n// Control definitions \u2014 shared configuration for all audio controls\n// ---------------------------------------------------------------------------\n\nexport type ControlKey =\n\t| \"playhead\"\n\t| \"offset\"\n\t| \"duration\"\n\t| \"startDelay\"\n\t| \"stopDelay\"\n\t| \"fadeIn\"\n\t| \"fadeOut\"\n\t| \"loopStart\"\n\t| \"loopEnd\"\n\t| \"loopCrossfade\"\n\t| \"playbackRate\"\n\t| \"detune\"\n\t| \"gain\"\n\t| \"pan\"\n\t| \"lowpass\"\n\t| \"highpass\";\n\nexport interface ControlDef {\n\tkey: ControlKey;\n\tlabel: string;\n\tmin: number;\n\tmax: number;\n\tdefaultValue: number;\n\tprecision?: number;\n\tsnap?: string;\n\tpreset?: string;\n\ttitle?: string;\n\thasToggle?: boolean;\n\thasSnap?: boolean;\n\thasMaxLock?: boolean;\n\t/** When true, max defaults to audio file duration. */\n\tmaxLockedByDefault?: boolean;\n}\n\nexport const DEFAULT_TEMPO = 120;\nexport const SAMPLE_RATE = 48000;\n\nexport const controlDefs: ControlDef[] = [\n\t{\n\t\tkey: \"offset\",\n\t\tlabel: \"Offset\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"bar\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t\ttitle: \"Start position in the buffer (seconds).\",\n\t},\n\t{\n\t\tkey: \"duration\",\n\t\tlabel: \"Duration\",\n\t\tmin: -1,\n\t\tmax: 60,\n\t\tdefaultValue: -1,\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t\ttitle:\n\t\t\t\"How long to play before auto-stopping (seconds). -1 for full length.\",\n\t},\n\t{\n\t\tkey: \"startDelay\",\n\t\tlabel: \"StartDelay\",\n\t\tmin: 0,\n\t\tmax: 4,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\ttitle: \"Delay before starting (seconds).\",\n\t},\n\t{\n\t\tkey: \"stopDelay\",\n\t\tlabel: \"StopDelay\",\n\t\tmin: 0,\n\t\tmax: 4,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\ttitle: \"Delay before stopping (seconds).\",\n\t},\n\t{\n\t\tkey: \"fadeIn\",\n\t\tlabel: \"FadeIn\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\ttitle: \"Fade-in duration (seconds).\",\n\t},\n\t{\n\t\tkey: \"fadeOut\",\n\t\tlabel: \"FadeOut\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\ttitle: \"Fade-out duration (seconds).\",\n\t},\n];\n\nexport const loopControlDefs: ControlDef[] = [\n\t{\n\t\tkey: \"loopStart\",\n\t\tlabel: \"Start\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"bar\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t},\n\t{\n\t\tkey: \"loopEnd\",\n\t\tlabel: \"End\",\n\t\tmin: 0,\n\t\tmax: 60,\n\t\tdefaultValue: 0,\n\t\tsnap: \"bar\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t\thasMaxLock: true,\n\t\tmaxLockedByDefault: true,\n\t},\n\t{\n\t\tkey: \"loopCrossfade\",\n\t\tlabel: \"Crossfade\",\n\t\tmin: 0,\n\t\tmax: 1,\n\t\tdefaultValue: 0,\n\t\tsnap: \"beat\",\n\t\thasSnap: true,\n\t\thasToggle: true,\n\t},\n];\n\nexport const paramDefs: ControlDef[] = [\n\t{\n\t\tkey: \"playbackRate\",\n\t\tlabel: \"PlaybackRate\",\n\t\tmin: -2,\n\t\tmax: 2,\n\t\tdefaultValue: 1,\n\t\tprecision: 2,\n\t\tpreset: \"playbackRate\",\n\t\thasToggle: true,\n\t\ttitle: \"Playback speed. Negative for reverse.\",\n\t},\n\t{\n\t\tkey: \"detune\",\n\t\tlabel: \"Detune\",\n\t\tmin: -2400,\n\t\tmax: 2400,\n\t\tdefaultValue: 0,\n\t\tprecision: 4,\n\t\tpreset: \"cents\",\n\t\thasToggle: true,\n\t\ttitle: \"Pitch shift in cents.\",\n\t},\n\t{\n\t\tkey: \"gain\",\n\t\tlabel: \"Gain\",\n\t\tmin: -100,\n\t\tmax: 0,\n\t\tdefaultValue: 0,\n\t\tprecision: 3,\n\t\tpreset: \"gain\",\n\t\thasToggle: true,\n\t\ttitle: \"Amplitude in dB.\",\n\t},\n\t{\n\t\tkey: \"pan\",\n\t\tlabel: \"Pan\",\n\t\tmin: -1,\n\t\tmax: 1,\n\t\tdefaultValue: 0,\n\t\tpreset: \"pan\",\n\t\thasToggle: true,\n\t\ttitle: \"-1 full left, 1 full right.\",\n\t},\n\t{\n\t\tkey: \"lowpass\",\n\t\tlabel: \"Lowpass\",\n\t\tmin: 32,\n\t\tmax: 16384,\n\t\tdefaultValue: 16384,\n\t\tpreset: \"hertz\",\n\t\thasToggle: true,\n\t\ttitle: \"Lowpass cutoff frequency.\",\n\t},\n\t{\n\t\tkey: \"highpass\",\n\t\tlabel: \"Highpass\",\n\t\tmin: 32,\n\t\tmax: 16384,\n\t\tdefaultValue: 32,\n\t\tpreset: \"hertz\",\n\t\thasToggle: true,\n\t\ttitle: \"Highpass cutoff frequency.\",\n\t},\n];\n\n/** Internal-only definition for playhead (not shown in UI). */\nconst playheadDef: ControlDef = {\n\tkey: \"playhead\",\n\tlabel: \"Playhead\",\n\tmin: 0,\n\tmax: 480000,\n\tdefaultValue: 0,\n\tprecision: 1,\n\tsnap: \"int\",\n\ttitle: \"Current sample position of buffer playback.\",\n};\n\nexport const allDefs = [\n\tplayheadDef,\n\t...controlDefs,\n\t...loopControlDefs,\n\t...paramDefs,\n];\n\nexport function buildDefaults(): {\n\tvalues: Record<ControlKey, number>;\n\tsnaps: Record<ControlKey, string>;\n\tenabled: Record<ControlKey, boolean>;\n\tmins: Record<ControlKey, number>;\n\tmaxs: Record<ControlKey, number>;\n\tmaxLocked: Record<ControlKey, boolean>;\n} {\n\tconst values = {} as Record<ControlKey, number>;\n\tconst snaps = {} as Record<ControlKey, string>;\n\tconst enabled = {} as Record<ControlKey, boolean>;\n\tconst mins = {} as Record<ControlKey, number>;\n\tconst maxs = {} as Record<ControlKey, number>;\n\tconst maxLocked = {} as Record<ControlKey, boolean>;\n\tfor (const d of allDefs) {\n\t\tvalues[d.key] = d.defaultValue;\n\t\tsnaps[d.key] = d.snap ?? \"none\";\n\t\tenabled[d.key] = true;\n\t\tmins[d.key] = d.min;\n\t\tmaxs[d.key] = d.max;\n\t\tmaxLocked[d.key] = d.maxLockedByDefault ?? false;\n\t}\n\treturn { values, snaps, enabled, mins, maxs, maxLocked };\n}\n", "export function formatValueText(\n\tvalue: number,\n\tkey: string | undefined,\n\tsnap: string,\n\ttempo: number,\n): string {\n\tswitch (key) {\n\t\tcase \"gain\":\n\t\t\treturn `${value.toFixed(1)} dB`;\n\t\tcase \"lowpass\":\n\t\tcase \"highpass\":\n\t\t\treturn `${Math.round(value)} Hz`;\n\t\tcase \"detune\":\n\t\t\treturn `${Math.round(value)} cents`;\n\t\tcase \"pan\":\n\t\t\tif (value === 0) return \"center\";\n\t\t\treturn value < 0\n\t\t\t\t? `${Math.abs(value).toFixed(2)} left`\n\t\t\t\t: `${value.toFixed(2)} right`;\n\t\tcase \"playbackRate\":\n\t\t\treturn `${value.toFixed(2)}x`;\n\t\tcase \"playhead\":\n\t\t\treturn `sample ${Math.round(value)}`;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n\tif (snap === \"beat\" || snap === \"bar\" || snap === \"8th\" || snap === \"16th\") {\n\t\tconst spb = 60 / tempo;\n\t\tif (snap === \"bar\") {\n\t\t\tconst bars = value / (spb * 4);\n\t\t\treturn `${Math.round(bars)} bars`;\n\t\t}\n\t\tif (snap === \"8th\") {\n\t\t\tconst eighths = value / (spb / 2);\n\t\t\treturn `${Math.round(eighths)} 8ths`;\n\t\t}\n\t\tif (snap === \"16th\") {\n\t\t\tconst sixteenths = value / (spb / 4);\n\t\t\treturn `${Math.round(sixteenths)} 16ths`;\n\t\t}\n\t\tconst beats = value / spb;\n\t\treturn `${Math.round(beats)} beats`;\n\t}\n\n\tif (snap === \"integer\") {\n\t\treturn `${Math.round(value)} s`;\n\t}\n\n\treturn `${value.toPrecision(4)} s`;\n}\n\nexport function formatTickLabel(\n\tvalue: number,\n\tkey: string | undefined,\n\tsnap: string,\n\ttempo: number,\n): string {\n\tswitch (key) {\n\t\tcase \"gain\":\n\t\t\treturn value.toFixed(1);\n\t\tcase \"lowpass\":\n\t\tcase \"highpass\":\n\t\t\treturn `${Math.round(value)}`;\n\t\tcase \"detune\":\n\t\t\treturn `${Math.round(value)}`;\n\t\tcase \"pan\":\n\t\t\tif (value === 0) return \"C\";\n\t\t\treturn value < 0\n\t\t\t\t? `${Math.abs(value).toFixed(2)}L`\n\t\t\t\t: `${value.toFixed(2)}R`;\n\t\tcase \"playbackRate\":\n\t\t\treturn `${value.toFixed(2)}x`;\n\t\tcase \"playhead\":\n\t\t\treturn `${Math.round(value)}`;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n\tif (snap === \"beat\" || snap === \"bar\" || snap === \"8th\" || snap === \"16th\") {\n\t\tconst spb = 60 / tempo;\n\t\tif (snap === \"bar\") return `${Math.round(value / (spb * 4))}`;\n\t\tif (snap === \"8th\") return `${Math.round(value / (spb / 2))}`;\n\t\tif (snap === \"16th\") return `${Math.round(value / (spb / 4))}`;\n\t\treturn `${Math.round(value / spb)}`;\n\t}\n\n\tif (snap === \"integer\") return `${Math.round(value)}`;\n\n\treturn value.toPrecision(4);\n}\n", "import type { ControlKey } from \"./controlDefs\";\n\nexport type LinkedControlPairKey = \"fadeOutStopDelay\" | \"loopStartEnd\";\n\nexport interface LinkedControlPairDef {\n\tkey: LinkedControlPairKey;\n\tlabel: string;\n\tcontrols: readonly [ControlKey, ControlKey];\n}\n\nexport const transportLinkedControlPairs: readonly LinkedControlPairDef[] = [\n\t{\n\t\tkey: \"fadeOutStopDelay\",\n\t\tlabel: \"Link StopDelay and FadeOut\",\n\t\tcontrols: [\"stopDelay\", \"fadeOut\"],\n\t},\n];\n\nexport const loopLinkedControlPairs: readonly LinkedControlPairDef[] = [\n\t{\n\t\tkey: \"loopStartEnd\",\n\t\tlabel: \"Link Start and End\",\n\t\tcontrols: [\"loopStart\", \"loopEnd\"],\n\t},\n];\n\nconst allLinkedControlPairs = [\n\t...transportLinkedControlPairs,\n\t...loopLinkedControlPairs,\n];\n\nexport function buildLinkedControlPairDefaults(): Record<\n\tLinkedControlPairKey,\n\tboolean\n> {\n\treturn {\n\t\tfadeOutStopDelay: false,\n\t\tloopStartEnd: false,\n\t};\n}\n\nexport function getLinkedControlPairForControl(\n\tcontrolKey: ControlKey,\n): LinkedControlPairDef | undefined {\n\treturn allLinkedControlPairs.find(\n\t\t(pair) =>\n\t\t\tpair.controls[0] === controlKey || pair.controls[1] === controlKey,\n\t);\n}\n\nexport function getActiveLinkedControls(\n\tcontrolKey: ControlKey,\n\tlinkedPairs: Record<LinkedControlPairKey, boolean>,\n): readonly ControlKey[] {\n\tconst pair = getLinkedControlPairForControl(controlKey);\n\tif (pair && linkedPairs[pair.key]) {\n\t\treturn pair.controls;\n\t}\n\n\treturn [controlKey];\n}\n\nexport function getLinkedControlUpdates({\n\tpair,\n\tchangedKey,\n\tnextValue,\n\tvalues,\n\tmins,\n\tmaxs,\n}: {\n\tpair: LinkedControlPairDef;\n\tchangedKey: ControlKey;\n\tnextValue: number;\n\tvalues: Record<ControlKey, number>;\n\tmins: Record<ControlKey, number>;\n\tmaxs: Record<ControlKey, number>;\n}): Partial<Record<ControlKey, number>> {\n\tconst [firstKey, secondKey] = pair.controls;\n\tif (changedKey !== firstKey && changedKey !== secondKey) {\n\t\treturn { [changedKey]: nextValue };\n\t}\n\n\tconst otherKey = changedKey === firstKey ? secondKey : firstKey;\n\tconst currentChanged = values[changedKey];\n\tconst currentOther = values[otherKey];\n\tconst requestedShift = nextValue - currentChanged;\n\tconst minShift = Math.max(\n\t\tmins[changedKey] - currentChanged,\n\t\tmins[otherKey] - currentOther,\n\t);\n\tconst maxShift = Math.min(\n\t\tmaxs[changedKey] - currentChanged,\n\t\tmaxs[otherKey] - currentOther,\n\t);\n\tconst appliedShift = Math.min(Math.max(requestedShift, minShift), maxShift);\n\n\treturn {\n\t\t[changedKey]: currentChanged + appliedShift,\n\t\t[otherKey]: currentOther + appliedShift,\n\t};\n}\n", "const cachePromise = caches.open(\"sound-files\");\n\nexport async function loadFromCache(\n\turl: string,\n): Promise<ArrayBuffer | undefined> {\n\tconst startTime = performance.now();\n\tconst cache = await cachePromise;\n\tconst response = await cache.match(url);\n\tif (response) {\n\t\tconsole.log(\n\t\t\t`[cache] Loaded ${url} from CacheStorage in ${(performance.now() - startTime).toFixed(0)}ms`,\n\t\t);\n\t\treturn response.arrayBuffer();\n\t}\n\tconst fetched = await fetch(url);\n\tif (fetched.ok) {\n\t\tcache.put(url, fetched.clone()).catch(() => {});\n\t\tconsole.log(\n\t\t\t`[cache] Loaded ${url} from network in ${(performance.now() - startTime).toFixed(0)}ms`,\n\t\t);\n\t\treturn fetched.arrayBuffer();\n\t}\n\treturn undefined;\n}\n", "const DB_NAME = \"clip-audio-store\";\nconst DB_VERSION = 1;\nconst STORE_NAME = \"files\";\nconst LAST_FILE_KEY = \"last-uploaded\";\n\nfunction openDB(): Promise<IDBDatabase> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst request = indexedDB.open(DB_NAME, DB_VERSION);\n\t\trequest.onupgradeneeded = () => {\n\t\t\tconst db = request.result;\n\t\t\tif (!db.objectStoreNames.contains(STORE_NAME)) {\n\t\t\t\tdb.createObjectStore(STORE_NAME);\n\t\t\t}\n\t\t};\n\t\trequest.onsuccess = () => resolve(request.result);\n\t\trequest.onerror = () => reject(request.error);\n\t});\n}\n\nfunction tx(db: IDBDatabase, mode: IDBTransactionMode): IDBObjectStore {\n\treturn db.transaction(STORE_NAME, mode).objectStore(STORE_NAME);\n}\n\nexport interface StoredFile {\n\tname: string;\n\tarrayBuffer: ArrayBuffer;\n}\n\nexport async function saveUploadedFile(\n\tname: string,\n\tarrayBuffer: ArrayBuffer,\n): Promise<void> {\n\tconst db = await openDB();\n\tconst store = tx(db, \"readwrite\");\n\tconst data: StoredFile = { name, arrayBuffer };\n\tawait new Promise<void>((resolve, reject) => {\n\t\tconst req = store.put(data, LAST_FILE_KEY);\n\t\treq.onsuccess = () => resolve();\n\t\treq.onerror = () => reject(req.error);\n\t});\n}\n\nexport async function loadUploadedFile(): Promise<StoredFile | null> {\n\tconst db = await openDB();\n\tconst store = tx(db, \"readonly\");\n\treturn new Promise((resolve, reject) => {\n\t\tconst req = store.get(LAST_FILE_KEY);\n\t\treq.onsuccess = () => resolve(req.result ?? null);\n\t\treq.onerror = () => reject(req.error);\n\t});\n}\n"],
5
+ "mappings": "AAAO,SAASA,GAAUC,EAAqB,CAC9C,OAAO,KAAK,IAAI,GAAK,KAAK,MAAMA,CAAG,EAAG,IAAK,CAC5C,CAEO,SAASC,GAAUC,EAAoB,CAC7C,MAAO,MAAOA,EAAK,GACpB,CAEA,IAAMC,GAAuB,CAAC,OAAQ,MAAO,MAAO,MAAM,EAI1D,SAASC,EAAMC,EAAeC,EAAaC,EAAqB,CAC/D,OAAO,KAAK,IAAI,KAA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AO,IAAI,IAAI,iBAAkBA,CAAO,EAAE,SAAS,CACpD,CCmBO,IAAMC,GAAgB,IAChBC,GAAc,KAEdC,GAA4B,CACxC,CACC,IAAK,SACL,MAAO,SACP,IAAK,EACL,IAAK,GACL,aAAc,EACd,KAAM,MACN,QAAS,GACT,UAAW,GACX,WAAY,GACZ,mBAAoB,GACpB,MAAO,yCACR,EACA,CACC,IAAK,WACL,MAAO,WACP,IAAK,GACL,IAAK,GACL,aAAc,GACd,QAAS,GACT,UAAW,GACX,WAAY,GACZ,mBAAoB,GACpB,MACC,sEACF,EACA,CACC,IAAK,aACL,MAAO,aACP,IAAK,EACL,IAAK,EACL,aAAc,EACd,KAAM,OACN,QAAS,GACT,UAAW,GACX,MAAO,kCACR,EACA,CACC,IAAK,YACL,MAAO,YACP,IAAK,EACL,IAAK,EACL,aAAc,EACd,KAAM,OACN,QAAS,GACT,UAAW,GACX,WAAY,GACZ,MAAO,kCACR,EACA,CACC,IAAK,SACL,MAAO,SACP,IAAK,EACL,IAAK,GACL,aAAc,EACd,KAAM,OACN,QAAS,GACT,UAAW,GACX,WAAY,GACZ,MAAO,6BACR,EACA,CACC,IAAK,UACL,MAAO,UACP,IAAK,EACL,IAAK,GACL,aAAc,EACd,KAAM,OACN,QAAS,GACT,UAAW,GACX,WAAY,GACZ,MAAO,8BACR,CACD,EAEaC,GAAgC,CAC5C,CACC,IAAK,YACL,MAAO,QACP,IAAK,EACL,IAAK,GACL,aAAc,EACd,KAAM,MACN,QAAS,GACT,UAAW,GACX,WAAY,GACZ,mBAAoB,EACrB,EACA,CACC,IAAK,UACL,MAAO,MACP,IAAK,EACL,IAAK,GACL,aAAc,EACd,KAAM,MACN,QAAS,GACT,UAAW,GACX,WAAY,GACZ,mBAAoB,EACrB,EACA,CACC,IAAK,gBACL,MAAO,YACP,IAAK,EACL,IAAK,EACL,aAAc,EACd,KAAM,OACN,QAAS,GACT,UAAW,EACZ,CACD,EAEaC,GAA0B,CACtC,CACC,IAAK,eACL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EAAQY,EAAI,QAAU,IAAI,EAChDA,EAAI,QAAU,IAAMX,EAAOW,EAAI,KAAK,CACrC,CAAC,CACF",
6
+ "names": ["dbFromLin", "lin", "linFromDb", "db", "TEMPO_RELATIVE_SNAPS", "clamp", "value", "min", "max", "isTempoRelativeSnap", "snap", "getTempoSnapInterval", "tempo", "secondsPerBeat", "remapTempoRelativeValue", "oldTempo", "newTempo", "oldInterval", "newInterval", "count", "getSnappedValue", "interval", "presets", "_", "i", "float32ArrayFromAudioBuffer", "buffer", "audioBufferFromFloat32Array", "context", "data", "generateSnapPoints", "points", "start", "v", "ClipNode", "context", "options", "audioBufferFromFloat32Array", "message", "type", "data", "_ct", "_cf", "ph", "tt", "newState", "value", "ab", "port", "totalLength", "channels", "duration", "startSample", "channelData", "when", "offset", "initialDelay", "processorCode", "State", "SAMPLE_BLOCK_SIZE", "createStreamBufferState", "buffer", "totalLength", "hasBuffer", "getBufferLength", "getLogicalBufferLength", "properties", "createSilentBuffer", "channels", "length", "mergeWrittenSpan", "spans", "nextSpan", "merged", "a", "b", "result", "span", "previous", "getCommittedLength", "committedLength", "resetLowWaterState", "streamBuffer", "playhead", "ensureBufferCapacity", "requiredChannels", "requiredLength", "currentLength", "currentChannels", "nextLength", "nextChannels", "nextBuffer", "ch", "applyBufferRangeWrite", "write", "startSample", "writeLength", "requestedTotalLength", "applyPendingBufferWrites", "setWholeBuffer", "getProperties", "opts", "sampleRate", "duration", "loop", "loopStart", "loopEnd", "loopCrossfade", "offset", "startWhen", "stopWhen", "pauseWhen", "resumeWhen", "playedSamples", "state", "State", "timesLooped", "fadeInDuration", "fadeOutDuration", "enableFadeIn", "enableFadeOut", "enableLoopStart", "enableLoopEnd", "enableLoopCrossfade", "enableHighpass", "enableLowpass", "enableGain", "enablePan", "enableDetune", "enablePlaybackRate", "getBufferDurationSeconds", "normalizeLoopBounds", "bufferDuration", "setOffset", "offs", "findIndexesNormal", "p", "bufferLength", "loopStartSamples", "loopEndSamples", "indexes", "i", "head", "nextPlayhead", "looped", "findIndexesWithPlaybackRates", "playbackRates", "rate", "fill", "target", "source", "nc", "fillWithSilence", "j", "monoToStereo", "signal", "r", "copy", "checkNans", "output", "numNans", "createFilterState", "gainFilter", "arr", "gains", "g", "panFilter", "pans", "pan", "leftGain", "rightGain", "lowpassFilter", "cutoffs", "states", "channel", "x_1", "x_2", "y_1", "y_2", "cutoff", "w0", "alpha", "b0", "b1", "b2", "a0", "a1", "a2", "h0", "h1", "h2", "h3", "h4", "x", "y", "prevCutoff", "highpassFilter", "handleProcessorMessage", "message", "currentTime", "type", "data", "init", "endData", "d", "st", "processBlock", "props", "outputs", "parameters", "ctx", "filterState", "messages", "output0", "sourceLength", "detunes", "lowpass", "highpass", "hasIncompleteStream", "durationSamples", "loopCrossfadeSamples", "maxLoopStartSample", "loopLengthSamples", "needsDetune", "effectiveRates", "len", "cents", "useRateIndexing", "isZeroRateBlock", "blockParams", "ended", "updatedPlayhead", "underrunSample", "index", "xfadeNumSamples", "isWithinLoopRange", "needsCrossfade", "endIndex", "elapsed", "n", "position", "srcIdx", "startIndex", "fadeInSamples", "remaining", "t", "fadeOutSamples", "remainingSamples", "sampleRemaining", "VERSION", "PACKAGE_NAME", "PACKAGE_VERSION", "VERSION", "getProcessorBlobUrl", "blob", "processorCode", "getProcessorCdnUrl", "version", "getProcessorModuleUrl", "baseUrl", "DEFAULT_TEMPO", "SAMPLE_RATE", "controlDefs", "loopControlDefs", "paramDefs", "playheadDef", "allDefs", "buildDefaults", "values", "snaps", "enabled", "mins", "maxs", "maxLocked", "d", "formatValueText", "value", "key", "snap", "tempo", "spb", "bars", "eighths", "sixteenths", "beats", "formatTickLabel", "transportLinkedControlPairs", "loopLinkedControlPairs", "allLinkedControlPairs", "buildLinkedControlPairDefaults", "getLinkedControlPairForControl", "controlKey", "pair", "getActiveLinkedControls", "linkedPairs", "getLinkedControlUpdates", "changedKey", "nextValue", "values", "mins", "maxs", "firstKey", "secondKey", "otherKey", "currentChanged", "currentOther", "requestedShift", "minShift", "maxShift", "appliedShift", "cachePromise", "loadFromCache", "url", "startTime", "cache", "response", "fetched", "DB_NAME", "STORE_NAME", "LAST_FILE_KEY", "openDB", "resolve", "reject", "request", "DB_NAME", "db", "tx", "mode", "saveUploadedFile", "name", "arrayBuffer", "store", "data", "req", "loadUploadedFile"]
7
7
  }