@jadujoel/web-audio-clip-node 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -32
- package/dist/audio/ClipNode.d.ts +2 -0
- package/dist/audio/ClipNode.js +6 -1
- package/dist/audio/processor-code.d.ts +1 -1
- package/dist/audio/processor-code.js +1 -1
- package/dist/audio/processor-kernel.js +3 -0
- package/dist/audio/processor.js +9 -0
- package/dist/audio/version.d.ts +1 -1
- package/dist/audio/version.js +1 -1
- package/dist/lib.bundle.js +3 -3
- package/dist/lib.bundle.js.map +3 -3
- package/dist/processor.js +2 -2
- package/dist/processor.js.map +4 -4
- package/examples/README.md +12 -4
- package/examples/cdn-vanilla/README.md +10 -6
- package/examples/cdn-vanilla/index.html +1065 -33
- package/examples/index.html +1 -0
- package/examples/self-hosted/public/processor.js +2 -2
- package/examples/streaming/README.md +25 -0
- package/examples/streaming/build-worker.ts +21 -0
- package/examples/streaming/decode-worker.ts +308 -0
- package/examples/streaming/index.html +211 -0
- package/examples/streaming/main.ts +276 -0
- package/examples/streaming/package.json +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,29 +1,50 @@
|
|
|
1
1
|
# @jadujoel/web-audio-clip-node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AudioWorklet clip playback for the Web Audio API with pause/resume, reusable start, buffer hot-swap, loop callbacks, loop crossfade, real-time sample playhead control, and sample-accurate fades — without extra nodes.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Live demo: https://jadujoel.github.io/web-audio-clip-node/
|
|
6
|
+
|
|
7
|
+
## Why this library
|
|
8
|
+
|
|
9
|
+
`AudioBufferSourceNode` is good at one-shot playback, but it does not give you some things clip-based apps usually need:
|
|
10
|
+
|
|
11
|
+
- **Pause and resume** — `AudioBufferSourceNode` has no pause; you must stop and recreate
|
|
12
|
+
- **Reusable start** — call `start()` again after `stop()` without creating a new node
|
|
13
|
+
- **Buffer hot-swap** — assign a new `AudioBuffer` to a playing node and it switches seamlessly
|
|
14
|
+
- **Loop callback** when the playhead wraps (`onlooped`)
|
|
15
|
+
- **Loop crossfade** built into the source itself
|
|
16
|
+
- **Real-time playhead** get/set access in samples
|
|
17
|
+
- **Sample-accurate fade in / fade out** without wiring extra gain nodes around every source
|
|
18
|
+
|
|
19
|
+
`ClipNode` is aimed at those missing pieces while staying small enough to drop into a plain browser app.
|
|
20
|
+
|
|
21
|
+
## Try It Fast
|
|
22
|
+
|
|
23
|
+
- Open the live playground: https://jadujoel.github.io/web-audio-clip-node/
|
|
24
|
+
- Run all local examples from the repo root with `bun run examples`
|
|
25
|
+
- Try the zero-install example in [examples/cdn-vanilla](examples/cdn-vanilla/)
|
|
6
26
|
|
|
7
27
|
## Features
|
|
8
28
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
29
|
+
- AudioWorklet-based clip playback with explicit transport control
|
|
30
|
+
- **Pause / resume** and **reusable start** — no need to recreate the node after stopping
|
|
31
|
+
- **Buffer hot-swap** — assign `clip.buffer` on a live node and it switches immediately
|
|
32
|
+
- `onlooped` callback support so you can react when the clip wraps
|
|
33
|
+
- Loop start, loop end, and loop crossfade on the node itself
|
|
34
|
+
- Real-time playhead readback and sample-accurate seeking via `clip.playhead`
|
|
35
|
+
- Sample-accurate fade in and fade out without external helper nodes
|
|
36
|
+
- Playback rate from `-2` to `2`, including reverse playback
|
|
37
|
+
- Detune, gain, stereo pan, highpass, and lowpass controls
|
|
38
|
+
- Streaming buffer support for incremental writes
|
|
39
|
+
- Optional React hooks and ready-made controls
|
|
19
40
|
|
|
20
41
|
## Install
|
|
21
42
|
|
|
22
43
|
```sh
|
|
23
|
-
|
|
44
|
+
npm install @jadujoel/web-audio-clip-node
|
|
24
45
|
```
|
|
25
46
|
|
|
26
|
-
## Quick Start
|
|
47
|
+
## Quick Start
|
|
27
48
|
|
|
28
49
|
```ts
|
|
29
50
|
import { ClipNode, getProcessorBlobUrl } from "@jadujoel/web-audio-clip-node";
|
|
@@ -34,13 +55,28 @@ await ctx.audioWorklet.addModule(getProcessorBlobUrl());
|
|
|
34
55
|
const clip = new ClipNode(ctx);
|
|
35
56
|
clip.connect(ctx.destination);
|
|
36
57
|
|
|
37
|
-
const response = await fetch("audio.opus");
|
|
58
|
+
const response = await fetch("/audio/clip.opus");
|
|
38
59
|
const buffer = await ctx.decodeAudioData(await response.arrayBuffer());
|
|
60
|
+
|
|
39
61
|
clip.buffer = buffer;
|
|
62
|
+
clip.loop = true;
|
|
63
|
+
clip.loopStart = 0.5;
|
|
64
|
+
clip.loopEnd = 1.75;
|
|
65
|
+
clip.loopCrossfade = 0.04;
|
|
66
|
+
clip.fadeIn = 0.01;
|
|
67
|
+
clip.fadeOut = 0.08;
|
|
68
|
+
clip.onlooped = () => {
|
|
69
|
+
console.log("looped at sample", clip.playhead);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
clip.playbackRate.value = 1;
|
|
73
|
+
clip.playhead = 24_000;
|
|
40
74
|
clip.start();
|
|
41
75
|
```
|
|
42
76
|
|
|
43
|
-
|
|
77
|
+
`clip.playhead` is read and written in samples, so you can scrub to an exact frame position while playback is active.
|
|
78
|
+
|
|
79
|
+
## React Quick Start
|
|
44
80
|
|
|
45
81
|
```tsx
|
|
46
82
|
import {
|
|
@@ -104,48 +140,57 @@ function Player() {
|
|
|
104
140
|
}
|
|
105
141
|
```
|
|
106
142
|
|
|
107
|
-
## CDN Usage
|
|
143
|
+
## CDN Usage
|
|
144
|
+
|
|
145
|
+
Use the bundled entry point when you want a single browser import and load the processor from jsDelivr with `getProcessorCdnUrl()`.
|
|
108
146
|
|
|
109
147
|
```html
|
|
110
148
|
<script type="module">
|
|
111
|
-
import {
|
|
149
|
+
import {
|
|
150
|
+
ClipNode,
|
|
151
|
+
getProcessorCdnUrl,
|
|
152
|
+
} from "https://cdn.jsdelivr.net/npm/@jadujoel/web-audio-clip-node@0.1.6/dist/lib.bundle.js";
|
|
112
153
|
|
|
113
154
|
const ctx = new AudioContext();
|
|
114
|
-
await ctx.audioWorklet.addModule(getProcessorCdnUrl());
|
|
155
|
+
await ctx.audioWorklet.addModule(getProcessorCdnUrl("0.1.6"));
|
|
115
156
|
|
|
116
157
|
const clip = new ClipNode(ctx);
|
|
117
158
|
clip.connect(ctx.destination);
|
|
118
159
|
</script>
|
|
119
160
|
```
|
|
120
161
|
|
|
162
|
+
The full no-bundler demo lives in [examples/cdn-vanilla](examples/cdn-vanilla/).
|
|
163
|
+
|
|
164
|
+
That demo foregrounds the non-standard capabilities: pause/resume, restarting without recreating the node, buffer hot-swap, loop count callbacks, loop crossfade, and direct playhead seeking in samples.
|
|
165
|
+
|
|
121
166
|
## Processor Loading Options
|
|
122
167
|
|
|
123
168
|
| Method | Function | Use case |
|
|
124
169
|
|--------|----------|----------|
|
|
125
|
-
| Blob URL
|
|
126
|
-
| CDN | `getProcessorCdnUrl("0.1.
|
|
127
|
-
| Self-hosted | `getProcessorModuleUrl(baseUrl)` | You serve `processor.js`
|
|
170
|
+
| Blob URL | `getProcessorBlobUrl()` | Default for package consumers who want zero setup |
|
|
171
|
+
| CDN | `getProcessorCdnUrl("0.1.6")` | Plain browser usage via jsDelivr |
|
|
172
|
+
| Self-hosted | `getProcessorModuleUrl(baseUrl)` | You serve `processor.js` from your own app |
|
|
128
173
|
|
|
129
|
-
##
|
|
174
|
+
## Entry Points
|
|
130
175
|
|
|
131
176
|
| Entry point | Import path | Contents |
|
|
132
177
|
|-------------|-------------|----------|
|
|
133
|
-
| Core | `@jadujoel/web-audio-clip-node` | `ClipNode`, types,
|
|
134
|
-
| Bundle | `@jadujoel/web-audio-clip-node/bundle` | Single-file ESM bundle for CDN
|
|
135
|
-
| React | `@jadujoel/web-audio-clip-node/react` | Store, hooks, UI components |
|
|
178
|
+
| Core | `@jadujoel/web-audio-clip-node` | `ClipNode`, types, utilities, controls, processor kernel |
|
|
179
|
+
| Bundle | `@jadujoel/web-audio-clip-node/bundle` | Single-file ESM bundle for CDN or browser module usage |
|
|
180
|
+
| React | `@jadujoel/web-audio-clip-node/react` | Store, hooks, and UI components |
|
|
136
181
|
| Processor | `@jadujoel/web-audio-clip-node/processor` | Standalone worklet script |
|
|
137
|
-
| Styles | `@jadujoel/web-audio-clip-node/styles.css` | CSS for React components |
|
|
182
|
+
| Styles | `@jadujoel/web-audio-clip-node/styles.css` | CSS for the React components |
|
|
138
183
|
|
|
139
184
|
## Examples
|
|
140
185
|
|
|
141
|
-
The [
|
|
186
|
+
The [examples](examples/) directory covers the main integration styles.
|
|
142
187
|
|
|
143
188
|
| Example | Description | Build step? |
|
|
144
189
|
|---------|-------------|-------------|
|
|
145
|
-
| [cdn-vanilla](examples/cdn-vanilla/) |
|
|
146
|
-
| [esm-bundler](examples/esm-bundler/) | Vite + TypeScript
|
|
147
|
-
| [react](examples/react/) | Vite + React
|
|
148
|
-
| [self-hosted](examples/self-hosted/) | Vite
|
|
190
|
+
| [cdn-vanilla](examples/cdn-vanilla/) | Single HTML file using the CDN bundle and processor URL | No |
|
|
191
|
+
| [esm-bundler](examples/esm-bundler/) | Vite + TypeScript app importing the package directly | Yes |
|
|
192
|
+
| [react](examples/react/) | Vite + React with the included hooks and controls | Yes |
|
|
193
|
+
| [self-hosted](examples/self-hosted/) | Vite app serving `processor.js` locally via `getProcessorModuleUrl()` | Yes |
|
|
149
194
|
|
|
150
195
|
## License
|
|
151
196
|
|
package/dist/audio/ClipNode.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class ClipNode extends AudioWorkletNode {
|
|
|
22
22
|
private _duration;
|
|
23
23
|
private _previousState;
|
|
24
24
|
private _bufferWriteCursor;
|
|
25
|
+
private _hasStreamingPort;
|
|
25
26
|
timesLooped: number;
|
|
26
27
|
state: ClipNodeState;
|
|
27
28
|
cpu: number;
|
|
@@ -42,6 +43,7 @@ export declare class ClipNode extends AudioWorkletNode {
|
|
|
42
43
|
logState(): void;
|
|
43
44
|
get buffer(): AudioBuffer | undefined;
|
|
44
45
|
set buffer(ab: AudioBuffer);
|
|
46
|
+
transferPort(port: MessagePort): void;
|
|
45
47
|
initializeBuffer(totalLength: number, channels: number, options?: {
|
|
46
48
|
streaming?: boolean;
|
|
47
49
|
}): void;
|
package/dist/audio/ClipNode.js
CHANGED
|
@@ -22,6 +22,7 @@ export class ClipNode extends AudioWorkletNode {
|
|
|
22
22
|
_duration = -1;
|
|
23
23
|
_previousState = "initial";
|
|
24
24
|
_bufferWriteCursor = 0;
|
|
25
|
+
_hasStreamingPort = false;
|
|
25
26
|
timesLooped = 0;
|
|
26
27
|
state = "initial";
|
|
27
28
|
cpu = 0;
|
|
@@ -144,6 +145,10 @@ export class ClipNode extends AudioWorkletNode {
|
|
|
144
145
|
this.port.postMessage({ type: "loopStart", data: this._loopStart });
|
|
145
146
|
this.port.postMessage({ type: "loopEnd", data: this._loopEnd });
|
|
146
147
|
}
|
|
148
|
+
transferPort(port) {
|
|
149
|
+
this._hasStreamingPort = true;
|
|
150
|
+
this.port.postMessage({ type: "transferPort", data: port }, [port]);
|
|
151
|
+
}
|
|
147
152
|
initializeBuffer(totalLength, channels, options = {}) {
|
|
148
153
|
this._buffer = this.context.createBuffer(channels, totalLength, this.context.sampleRate);
|
|
149
154
|
this._bufferWriteCursor = 0;
|
|
@@ -184,7 +189,7 @@ export class ClipNode extends AudioWorkletNode {
|
|
|
184
189
|
this.port.postMessage({ type: "bufferEnd", data: { totalLength } });
|
|
185
190
|
}
|
|
186
191
|
start(when, offset, duration) {
|
|
187
|
-
if (!this._buffer) {
|
|
192
|
+
if (!this._buffer && !this._hasStreamingPort) {
|
|
188
193
|
console.error("Buffer not set.");
|
|
189
194
|
return;
|
|
190
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const processorCode = "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";
|
|
1
|
+
export declare const processorCode = "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";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// AUTO-GENERATED — do not edit. Run 'bun run build:lib' to regenerate.
|
|
2
|
-
export const processorCode = "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";
|
|
2
|
+
export const processorCode = "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";
|
|
@@ -570,15 +570,18 @@ export function handleProcessorMessage(properties, message, currentTime, sampleR
|
|
|
570
570
|
return [];
|
|
571
571
|
case "loopCrossfade":
|
|
572
572
|
properties.loopCrossfade = data;
|
|
573
|
+
properties.enableLoopCrossfade = properties.loopCrossfade > 0;
|
|
573
574
|
return [];
|
|
574
575
|
case "playhead":
|
|
575
576
|
properties.playhead = Math.floor(data);
|
|
576
577
|
return [];
|
|
577
578
|
case "fadeIn":
|
|
578
579
|
properties.fadeInDuration = data;
|
|
580
|
+
properties.enableFadeIn = properties.fadeInDuration > 0;
|
|
579
581
|
return [];
|
|
580
582
|
case "fadeOut":
|
|
581
583
|
properties.fadeOutDuration = data;
|
|
584
|
+
properties.enableFadeOut = properties.fadeOutDuration > 0;
|
|
582
585
|
return [];
|
|
583
586
|
case "toggleGain":
|
|
584
587
|
properties.enableGain =
|
package/dist/audio/processor.js
CHANGED
|
@@ -45,6 +45,15 @@ class ClipProcessor extends AudioWorkletProcessor {
|
|
|
45
45
|
super(options);
|
|
46
46
|
this.properties = getProperties(options?.processorOptions, sampleRate);
|
|
47
47
|
this.port.onmessage = (ev) => {
|
|
48
|
+
if (ev.data.type === "transferPort") {
|
|
49
|
+
const port = ev.data.data;
|
|
50
|
+
port.onmessage = (portEv) => {
|
|
51
|
+
const messages = handleProcessorMessage(this.properties, portEv.data, currentTime, sampleRate);
|
|
52
|
+
for (const msg of messages)
|
|
53
|
+
this.port.postMessage(msg);
|
|
54
|
+
};
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
48
57
|
const messages = handleProcessorMessage(this.properties, ev.data, currentTime, sampleRate);
|
|
49
58
|
for (const msg of messages)
|
|
50
59
|
this.port.postMessage(msg);
|
package/dist/audio/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.7";
|
package/dist/audio/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// AUTO-GENERATED — do not edit. Run 'bun run build:lib' to regenerate.
|
|
2
|
-
export const VERSION = "0.1.
|
|
2
|
+
export const VERSION = "0.1.7";
|