@dawcore/spectrogram 0.0.3 → 0.0.5
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 +50 -6
- package/dist/index.d.mts +128 -1
- package/dist/index.d.ts +128 -1
- package/dist/index.js +261 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -60
- package/dist/index.mjs.map +1 -1
- package/dist/orchestrator/index.d.mts +51 -1
- package/dist/orchestrator/index.mjs +222 -60
- package/dist/orchestrator/index.mjs.map +1 -1
- package/dist/worker/spectrogram.worker.mjs +111 -37
- package/dist/worker/spectrogram.worker.mjs.map +1 -1
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
# @dawcore/spectrogram
|
|
2
2
|
|
|
3
|
-
Framework-agnostic spectrogram computation,
|
|
3
|
+
Framework-agnostic spectrogram computation, Web Worker, and viewport-aware rendering orchestrator for the dawcore family.
|
|
4
4
|
|
|
5
|
-
Used by `@dawcore/components` (the Lit web component layer) and `@waveform-playlist/spectrogram` (the React Provider).
|
|
5
|
+
Used by `@dawcore/components` (the Lit web component layer, behind `<daw-track render-mode="spectrogram">`) and `@waveform-playlist/spectrogram` (the React Provider).
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Installation
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install @dawcore/spectrogram
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
No peer dependencies. If you use `@dawcore/components`, you don't install this directly — it's a regular dependency of that package.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { computeSpectrogram, getColorMap } from '@dawcore/spectrogram';
|
|
19
|
+
|
|
20
|
+
// Pure, synchronous FFT — magnitudes per time/frequency bin
|
|
21
|
+
const data = computeSpectrogram(audioBuffer, { fftSize: 2048 });
|
|
22
|
+
const lut = getColorMap('magma');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For rendering inside an app, use the worker and orchestrator instead of blocking the main thread:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { SpectrogramOrchestrator } from '@dawcore/spectrogram/orchestrator';
|
|
29
|
+
|
|
30
|
+
const orchestrator = new SpectrogramOrchestrator({
|
|
31
|
+
workerFactory: () =>
|
|
32
|
+
new Worker(new URL('@dawcore/spectrogram/worker/spectrogram.worker', import.meta.url), {
|
|
33
|
+
type: 'module',
|
|
34
|
+
}),
|
|
35
|
+
config: { fftSize: 2048 },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
orchestrator.registerClip(/* audio data */);
|
|
39
|
+
orchestrator.registerCanvas(/* OffscreenCanvas + metadata */);
|
|
40
|
+
orchestrator.setViewport(/* visible range */);
|
|
41
|
+
orchestrator.addEventListener('viewport-ready', (e) => console.log(e));
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The orchestrator renders in three tiers (visible viewport first, then a 25% overscan buffer, then the rest during idle time), aborts stale work when the viewport, config, or color map changes, and groups contiguous chunks so non-adjacent regions never trigger one oversized FFT.
|
|
45
|
+
|
|
46
|
+
## Entry Points
|
|
47
|
+
|
|
48
|
+
- `@dawcore/spectrogram` — `computeSpectrogram`, `computeSpectrogramMono`, `getColorMap`, `getFrequencyScale`, worker factories (`createSpectrogramWorker`, `createSpectrogramWorkerPool`, `SpectrogramAbortError`), and the orchestrator re-exports
|
|
49
|
+
- `@dawcore/spectrogram/worker/spectrogram.worker` — the Worker module URL target (resolve with `new URL(..., import.meta.url)`)
|
|
50
|
+
- `@dawcore/spectrogram/orchestrator` — `SpectrogramOrchestrator` and helpers (`classifyViewport`, `groupContiguousChunks`, `ColorLUTCache`) without the computation/worker graph, for consumers with their own FFT pipeline
|
|
51
|
+
|
|
52
|
+
## Examples & Documentation
|
|
53
|
+
|
|
54
|
+
- [`examples/dawcore-native/spectrogram.html`](https://github.com/naomiaro/waveform-playlist/tree/main/examples/dawcore-native) — spectrogram tracks in `<daw-editor>` (`pnpm example:dawcore-native`)
|
|
55
|
+
- Guides: [naomiaro.github.io/waveform-playlist](https://naomiaro.github.io/waveform-playlist/)
|
|
12
56
|
|
|
13
57
|
## License
|
|
14
58
|
|
package/dist/index.d.mts
CHANGED
|
@@ -47,6 +47,83 @@ type FrequencyScaleName = 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb';
|
|
|
47
47
|
*/
|
|
48
48
|
declare function getFrequencyScale(name: FrequencyScaleName): (f: number, minF: number, maxF: number) => number;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Pure geometry for mapping rendered pixel columns to FFT frames.
|
|
52
|
+
*/
|
|
53
|
+
interface PixelColumnToFrameParams {
|
|
54
|
+
/** Clip-relative pixel column (chunk pixel offset + x within the canvas). */
|
|
55
|
+
pixelX: number;
|
|
56
|
+
samplesPerPixel: number;
|
|
57
|
+
/** The clip's start position within its audio file (AudioClip.offsetSamples). */
|
|
58
|
+
clipOffsetSamples: number;
|
|
59
|
+
/** File-absolute sample position where the cached FFT data begins. */
|
|
60
|
+
fftStartSample: number;
|
|
61
|
+
hopSize: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The file sample displayed at clip-relative pixel x is
|
|
65
|
+
* `clipOffsetSamples + x * samplesPerPixel`; the FFT frame holding it starts
|
|
66
|
+
* at `fftStartSample + frame * hopSize`. Omitting `clipOffsetSamples` (the
|
|
67
|
+
* pre-#554 behavior) shifts every trimmed clip's display by its offset.
|
|
68
|
+
*/
|
|
69
|
+
declare function pixelColumnToFrame(params: PixelColumnToFrameParams): number;
|
|
70
|
+
interface PixelRowToBinParams {
|
|
71
|
+
/** Vertical position, bottom-up: `1 - y / canvasHeight` ∈ (0, 1]. */
|
|
72
|
+
normalizedY: number;
|
|
73
|
+
frequencyBinCount: number;
|
|
74
|
+
sampleRate: number;
|
|
75
|
+
minFrequency: number;
|
|
76
|
+
/** Resolved maximum frequency (> 0); callers default 0 → sampleRate / 2. */
|
|
77
|
+
maxFrequency: number;
|
|
78
|
+
/** Frequency scale mapping (Hz, minF, maxF) → [0, 1]. */
|
|
79
|
+
scaleFn: (f: number, minF: number, maxF: number) => number;
|
|
80
|
+
/** Linear scale uses a direct O(1) mapping instead of the binary search. */
|
|
81
|
+
isLinear: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Map a canvas row to the FFT bin displayed there.
|
|
85
|
+
*
|
|
86
|
+
* Linear: direct inversion of the scale — `freq = minF + normalizedY·(maxF −
|
|
87
|
+
* minF)` — so the configured frequency range is honored exactly like the
|
|
88
|
+
* non-linear scales (pre-#557 the linear fast path always spanned 0..Nyquist).
|
|
89
|
+
* Non-linear: binary search for the first bin whose scaled frequency reaches
|
|
90
|
+
* `normalizedY`. Both paths clamp to the last bin so the top row
|
|
91
|
+
* (normalizedY === 1) never falls out of range.
|
|
92
|
+
*/
|
|
93
|
+
declare function pixelRowToBin(params: PixelRowToBinParams): number;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Pure math for the window-padded, clip-clamped sample range covered by a set of
|
|
97
|
+
* render chunks.
|
|
98
|
+
*
|
|
99
|
+
* Shared by `SpectrogramOrchestrator.renderGroupOnce` and the React
|
|
100
|
+
* `computeChunkSampleRange` so both FFT pipelines compute the *same* range for the
|
|
101
|
+
* same chunks — a padding/clamping change to one used to silently diverge the two
|
|
102
|
+
* (the #554 drift class, with no cross-package test to catch it).
|
|
103
|
+
*
|
|
104
|
+
* Computing per-batch ranges on demand avoids allocating one giant FFT array for a
|
|
105
|
+
* full clip (which OOMs on 1hr+ files). The range is padded by one FFT window on
|
|
106
|
+
* each side to avoid edge artifacts, clamped to the clip's sample bounds.
|
|
107
|
+
*/
|
|
108
|
+
interface PaddedFftRangeParams {
|
|
109
|
+
/** Chunks in the render group: clip-relative chunk index + rendered pixel width. */
|
|
110
|
+
chunks: Array<{
|
|
111
|
+
chunkIndex: number;
|
|
112
|
+
widthPx: number;
|
|
113
|
+
}>;
|
|
114
|
+
/** FFT window size (samples) used to pad the range against edge artifacts. */
|
|
115
|
+
fftSize: number;
|
|
116
|
+
/** The clip's start position within its audio file (AudioClip.offsetSamples). */
|
|
117
|
+
offsetSamples: number;
|
|
118
|
+
/** The clip's duration (samples). */
|
|
119
|
+
durationSamples: number;
|
|
120
|
+
samplesPerPixel: number;
|
|
121
|
+
}
|
|
122
|
+
declare function computePaddedFftRange({ chunks, fftSize, offsetSamples, durationSamples, samplesPerPixel, }: PaddedFftRangeParams): {
|
|
123
|
+
paddedStart: number;
|
|
124
|
+
paddedEnd: number;
|
|
125
|
+
};
|
|
126
|
+
|
|
50
127
|
/**
|
|
51
128
|
* Error thrown when a spectrogram computation is aborted due to a generation change.
|
|
52
129
|
* Use `instanceof SpectrogramAbortError` instead of string matching on error messages.
|
|
@@ -90,6 +167,12 @@ interface SpectrogramWorkerApi {
|
|
|
90
167
|
cacheKey: string;
|
|
91
168
|
}>;
|
|
92
169
|
renderChunks(params: SpectrogramWorkerRenderChunksParams, generation?: number): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Cancel in-flight work from generations OLDER than `generation`.
|
|
172
|
+
* Pass the NEW (current) generation after bumping — the worker treats work
|
|
173
|
+
* as stale iff `workGeneration < latestAbortedGeneration`, so passing the
|
|
174
|
+
* previous generation cancels nothing (#555).
|
|
175
|
+
*/
|
|
93
176
|
abortGeneration(generation: number): void;
|
|
94
177
|
registerCanvas(canvasId: string, canvas: OffscreenCanvas): void;
|
|
95
178
|
unregisterCanvas(canvasId: string): void;
|
|
@@ -169,6 +252,13 @@ interface CanvasRegistration {
|
|
|
169
252
|
readonly trackId: string;
|
|
170
253
|
readonly channelIndex: number;
|
|
171
254
|
readonly chunkIndex: number;
|
|
255
|
+
/**
|
|
256
|
+
* TIMELINE-absolute pixel where this chunk starts. Layout contract: every
|
|
257
|
+
* canvas of a clip must satisfy
|
|
258
|
+
* `globalPixelOffset === clipOriginPx + chunkIndex * MAX_CANVAS_WIDTH` —
|
|
259
|
+
* renderGroup's clip-relative sample math depends on it (#554), and
|
|
260
|
+
* registerCanvas warns when a registration violates it.
|
|
261
|
+
*/
|
|
172
262
|
readonly globalPixelOffset: number;
|
|
173
263
|
readonly widthPx: number;
|
|
174
264
|
readonly heightPx: number;
|
|
@@ -202,6 +292,11 @@ declare class SpectrogramOrchestrator extends EventTarget {
|
|
|
202
292
|
protected colorLUT: ColorLUTCache;
|
|
203
293
|
protected disposed: boolean;
|
|
204
294
|
protected renderInFlight: boolean;
|
|
295
|
+
protected renderQueued: boolean;
|
|
296
|
+
protected clipOrigins: Map<string, {
|
|
297
|
+
originPx: number;
|
|
298
|
+
canvasCount: number;
|
|
299
|
+
}>;
|
|
205
300
|
protected readyDispatched: Set<string>;
|
|
206
301
|
constructor(opts: SpectrogramOrchestratorOptions);
|
|
207
302
|
registerClip(reg: ClipRegistration): void;
|
|
@@ -212,11 +307,27 @@ declare class SpectrogramOrchestrator extends EventTarget {
|
|
|
212
307
|
setConfig(config: SpectrogramConfig): void;
|
|
213
308
|
setColorMap(colorMap: ColorMapValue): void;
|
|
214
309
|
setDevicePixelRatio(dpr: number): void;
|
|
310
|
+
/**
|
|
311
|
+
* Start a new render generation and cancel in-flight work from older ones.
|
|
312
|
+
*
|
|
313
|
+
* The worker treats work as stale iff `generation < latestGeneration`, so
|
|
314
|
+
* the abort message must carry the NEW generation — passing the previous
|
|
315
|
+
* one leaves its in-flight FFTs running to completion (#555).
|
|
316
|
+
*/
|
|
317
|
+
protected bumpGenerationAndAbortStale(): void;
|
|
215
318
|
dispose(): void;
|
|
319
|
+
/**
|
|
320
|
+
* Coalesce render requests: `renderInFlight` is held for the WHOLE async
|
|
321
|
+
* render, not just until the microtask fires — a request arriving
|
|
322
|
+
* mid-render (e.g. a late registerCanvas) queues one follow-up run instead
|
|
323
|
+
* of starting a concurrent runRender for the same generation (#558).
|
|
324
|
+
*/
|
|
216
325
|
protected scheduleRender(): void;
|
|
326
|
+
protected runRenderLoop(): Promise<void>;
|
|
217
327
|
protected runRender(generation: number): Promise<void>;
|
|
218
328
|
protected renderTier(canvases: CanvasEntry[], generation: number, viewport: ViewportState): Promise<void>;
|
|
219
329
|
protected renderGroup(group: CanvasEntry[], generation: number, viewport: ViewportState): Promise<void>;
|
|
330
|
+
protected renderGroupOnce(group: CanvasEntry[], generation: number, viewport: ViewportState, clip: ClipEntry): Promise<void>;
|
|
220
331
|
protected renderRemainingViaIdle(canvases: CanvasEntry[], generation: number, viewport: ViewportState): Promise<void>;
|
|
221
332
|
protected yieldUntilIdle(): Promise<void>;
|
|
222
333
|
}
|
|
@@ -236,6 +347,10 @@ interface ViewportReadyDetail {
|
|
|
236
347
|
interface ChunkLike {
|
|
237
348
|
chunkIndex: number;
|
|
238
349
|
}
|
|
350
|
+
interface RenderableChunkLike extends ChunkLike {
|
|
351
|
+
clipId: string;
|
|
352
|
+
channelIndex: number;
|
|
353
|
+
}
|
|
239
354
|
/**
|
|
240
355
|
* Group a list of chunks into runs of contiguous chunk indices.
|
|
241
356
|
*
|
|
@@ -247,5 +362,17 @@ interface ChunkLike {
|
|
|
247
362
|
* two smaller FFTs (10–11, 14–15) totaling ~32K frames.
|
|
248
363
|
*/
|
|
249
364
|
declare function groupContiguousChunks<T extends ChunkLike>(chunks: T[]): T[][];
|
|
365
|
+
/**
|
|
366
|
+
* Group render canvases into runs of contiguous chunk indices, partitioned by
|
|
367
|
+
* `(clipId, channelIndex)` first.
|
|
368
|
+
*
|
|
369
|
+
* A track's canvases span multiple channels (one <daw-spectrogram> per channel,
|
|
370
|
+
* chunk indices shared) and multiple clips (chunk indices restart at 0 per
|
|
371
|
+
* clip). Grouping by chunk index alone interleaves them — e.g. stereo
|
|
372
|
+
* [ch0k0, ch1k0, ch0k1, ch1k1] yields the mixed group [ch1k0, ch0k1], which
|
|
373
|
+
* renderGroup then routes to a single channel's worker with a single clip's
|
|
374
|
+
* FFT data (issue #553).
|
|
375
|
+
*/
|
|
376
|
+
declare function groupRenderableChunks<T extends RenderableChunkLike>(chunks: T[]): T[][];
|
|
250
377
|
|
|
251
|
-
export { type CanvasMeta, type CanvasRegistration, type ChunkLike, type ClassifiedTiers, type ClipRegistration, ColorLUTCache, type FrequencyScaleName, SpectrogramAbortError, SpectrogramOrchestrator, type SpectrogramOrchestratorOptions, type SpectrogramWorkerApi, type SpectrogramWorkerFFTParams, type SpectrogramWorkerRenderChunksParams, type ViewportBounds, type ViewportReadyDetail, type ViewportState, classifyViewport, computeSpectrogram, computeSpectrogramMono, createSpectrogramWorker, createSpectrogramWorkerPool, getColorMap, getFrequencyScale, groupContiguousChunks };
|
|
378
|
+
export { type CanvasMeta, type CanvasRegistration, type ChunkLike, type ClassifiedTiers, type ClipRegistration, ColorLUTCache, type FrequencyScaleName, type PaddedFftRangeParams, type PixelColumnToFrameParams, type PixelRowToBinParams, type RenderableChunkLike, SpectrogramAbortError, SpectrogramOrchestrator, type SpectrogramOrchestratorOptions, type SpectrogramWorkerApi, type SpectrogramWorkerFFTParams, type SpectrogramWorkerRenderChunksParams, type ViewportBounds, type ViewportReadyDetail, type ViewportState, classifyViewport, computePaddedFftRange, computeSpectrogram, computeSpectrogramMono, createSpectrogramWorker, createSpectrogramWorkerPool, getColorMap, getFrequencyScale, groupContiguousChunks, groupRenderableChunks, pixelColumnToFrame, pixelRowToBin };
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,83 @@ type FrequencyScaleName = 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb';
|
|
|
47
47
|
*/
|
|
48
48
|
declare function getFrequencyScale(name: FrequencyScaleName): (f: number, minF: number, maxF: number) => number;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Pure geometry for mapping rendered pixel columns to FFT frames.
|
|
52
|
+
*/
|
|
53
|
+
interface PixelColumnToFrameParams {
|
|
54
|
+
/** Clip-relative pixel column (chunk pixel offset + x within the canvas). */
|
|
55
|
+
pixelX: number;
|
|
56
|
+
samplesPerPixel: number;
|
|
57
|
+
/** The clip's start position within its audio file (AudioClip.offsetSamples). */
|
|
58
|
+
clipOffsetSamples: number;
|
|
59
|
+
/** File-absolute sample position where the cached FFT data begins. */
|
|
60
|
+
fftStartSample: number;
|
|
61
|
+
hopSize: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The file sample displayed at clip-relative pixel x is
|
|
65
|
+
* `clipOffsetSamples + x * samplesPerPixel`; the FFT frame holding it starts
|
|
66
|
+
* at `fftStartSample + frame * hopSize`. Omitting `clipOffsetSamples` (the
|
|
67
|
+
* pre-#554 behavior) shifts every trimmed clip's display by its offset.
|
|
68
|
+
*/
|
|
69
|
+
declare function pixelColumnToFrame(params: PixelColumnToFrameParams): number;
|
|
70
|
+
interface PixelRowToBinParams {
|
|
71
|
+
/** Vertical position, bottom-up: `1 - y / canvasHeight` ∈ (0, 1]. */
|
|
72
|
+
normalizedY: number;
|
|
73
|
+
frequencyBinCount: number;
|
|
74
|
+
sampleRate: number;
|
|
75
|
+
minFrequency: number;
|
|
76
|
+
/** Resolved maximum frequency (> 0); callers default 0 → sampleRate / 2. */
|
|
77
|
+
maxFrequency: number;
|
|
78
|
+
/** Frequency scale mapping (Hz, minF, maxF) → [0, 1]. */
|
|
79
|
+
scaleFn: (f: number, minF: number, maxF: number) => number;
|
|
80
|
+
/** Linear scale uses a direct O(1) mapping instead of the binary search. */
|
|
81
|
+
isLinear: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Map a canvas row to the FFT bin displayed there.
|
|
85
|
+
*
|
|
86
|
+
* Linear: direct inversion of the scale — `freq = minF + normalizedY·(maxF −
|
|
87
|
+
* minF)` — so the configured frequency range is honored exactly like the
|
|
88
|
+
* non-linear scales (pre-#557 the linear fast path always spanned 0..Nyquist).
|
|
89
|
+
* Non-linear: binary search for the first bin whose scaled frequency reaches
|
|
90
|
+
* `normalizedY`. Both paths clamp to the last bin so the top row
|
|
91
|
+
* (normalizedY === 1) never falls out of range.
|
|
92
|
+
*/
|
|
93
|
+
declare function pixelRowToBin(params: PixelRowToBinParams): number;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Pure math for the window-padded, clip-clamped sample range covered by a set of
|
|
97
|
+
* render chunks.
|
|
98
|
+
*
|
|
99
|
+
* Shared by `SpectrogramOrchestrator.renderGroupOnce` and the React
|
|
100
|
+
* `computeChunkSampleRange` so both FFT pipelines compute the *same* range for the
|
|
101
|
+
* same chunks — a padding/clamping change to one used to silently diverge the two
|
|
102
|
+
* (the #554 drift class, with no cross-package test to catch it).
|
|
103
|
+
*
|
|
104
|
+
* Computing per-batch ranges on demand avoids allocating one giant FFT array for a
|
|
105
|
+
* full clip (which OOMs on 1hr+ files). The range is padded by one FFT window on
|
|
106
|
+
* each side to avoid edge artifacts, clamped to the clip's sample bounds.
|
|
107
|
+
*/
|
|
108
|
+
interface PaddedFftRangeParams {
|
|
109
|
+
/** Chunks in the render group: clip-relative chunk index + rendered pixel width. */
|
|
110
|
+
chunks: Array<{
|
|
111
|
+
chunkIndex: number;
|
|
112
|
+
widthPx: number;
|
|
113
|
+
}>;
|
|
114
|
+
/** FFT window size (samples) used to pad the range against edge artifacts. */
|
|
115
|
+
fftSize: number;
|
|
116
|
+
/** The clip's start position within its audio file (AudioClip.offsetSamples). */
|
|
117
|
+
offsetSamples: number;
|
|
118
|
+
/** The clip's duration (samples). */
|
|
119
|
+
durationSamples: number;
|
|
120
|
+
samplesPerPixel: number;
|
|
121
|
+
}
|
|
122
|
+
declare function computePaddedFftRange({ chunks, fftSize, offsetSamples, durationSamples, samplesPerPixel, }: PaddedFftRangeParams): {
|
|
123
|
+
paddedStart: number;
|
|
124
|
+
paddedEnd: number;
|
|
125
|
+
};
|
|
126
|
+
|
|
50
127
|
/**
|
|
51
128
|
* Error thrown when a spectrogram computation is aborted due to a generation change.
|
|
52
129
|
* Use `instanceof SpectrogramAbortError` instead of string matching on error messages.
|
|
@@ -90,6 +167,12 @@ interface SpectrogramWorkerApi {
|
|
|
90
167
|
cacheKey: string;
|
|
91
168
|
}>;
|
|
92
169
|
renderChunks(params: SpectrogramWorkerRenderChunksParams, generation?: number): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Cancel in-flight work from generations OLDER than `generation`.
|
|
172
|
+
* Pass the NEW (current) generation after bumping — the worker treats work
|
|
173
|
+
* as stale iff `workGeneration < latestAbortedGeneration`, so passing the
|
|
174
|
+
* previous generation cancels nothing (#555).
|
|
175
|
+
*/
|
|
93
176
|
abortGeneration(generation: number): void;
|
|
94
177
|
registerCanvas(canvasId: string, canvas: OffscreenCanvas): void;
|
|
95
178
|
unregisterCanvas(canvasId: string): void;
|
|
@@ -169,6 +252,13 @@ interface CanvasRegistration {
|
|
|
169
252
|
readonly trackId: string;
|
|
170
253
|
readonly channelIndex: number;
|
|
171
254
|
readonly chunkIndex: number;
|
|
255
|
+
/**
|
|
256
|
+
* TIMELINE-absolute pixel where this chunk starts. Layout contract: every
|
|
257
|
+
* canvas of a clip must satisfy
|
|
258
|
+
* `globalPixelOffset === clipOriginPx + chunkIndex * MAX_CANVAS_WIDTH` —
|
|
259
|
+
* renderGroup's clip-relative sample math depends on it (#554), and
|
|
260
|
+
* registerCanvas warns when a registration violates it.
|
|
261
|
+
*/
|
|
172
262
|
readonly globalPixelOffset: number;
|
|
173
263
|
readonly widthPx: number;
|
|
174
264
|
readonly heightPx: number;
|
|
@@ -202,6 +292,11 @@ declare class SpectrogramOrchestrator extends EventTarget {
|
|
|
202
292
|
protected colorLUT: ColorLUTCache;
|
|
203
293
|
protected disposed: boolean;
|
|
204
294
|
protected renderInFlight: boolean;
|
|
295
|
+
protected renderQueued: boolean;
|
|
296
|
+
protected clipOrigins: Map<string, {
|
|
297
|
+
originPx: number;
|
|
298
|
+
canvasCount: number;
|
|
299
|
+
}>;
|
|
205
300
|
protected readyDispatched: Set<string>;
|
|
206
301
|
constructor(opts: SpectrogramOrchestratorOptions);
|
|
207
302
|
registerClip(reg: ClipRegistration): void;
|
|
@@ -212,11 +307,27 @@ declare class SpectrogramOrchestrator extends EventTarget {
|
|
|
212
307
|
setConfig(config: SpectrogramConfig): void;
|
|
213
308
|
setColorMap(colorMap: ColorMapValue): void;
|
|
214
309
|
setDevicePixelRatio(dpr: number): void;
|
|
310
|
+
/**
|
|
311
|
+
* Start a new render generation and cancel in-flight work from older ones.
|
|
312
|
+
*
|
|
313
|
+
* The worker treats work as stale iff `generation < latestGeneration`, so
|
|
314
|
+
* the abort message must carry the NEW generation — passing the previous
|
|
315
|
+
* one leaves its in-flight FFTs running to completion (#555).
|
|
316
|
+
*/
|
|
317
|
+
protected bumpGenerationAndAbortStale(): void;
|
|
215
318
|
dispose(): void;
|
|
319
|
+
/**
|
|
320
|
+
* Coalesce render requests: `renderInFlight` is held for the WHOLE async
|
|
321
|
+
* render, not just until the microtask fires — a request arriving
|
|
322
|
+
* mid-render (e.g. a late registerCanvas) queues one follow-up run instead
|
|
323
|
+
* of starting a concurrent runRender for the same generation (#558).
|
|
324
|
+
*/
|
|
216
325
|
protected scheduleRender(): void;
|
|
326
|
+
protected runRenderLoop(): Promise<void>;
|
|
217
327
|
protected runRender(generation: number): Promise<void>;
|
|
218
328
|
protected renderTier(canvases: CanvasEntry[], generation: number, viewport: ViewportState): Promise<void>;
|
|
219
329
|
protected renderGroup(group: CanvasEntry[], generation: number, viewport: ViewportState): Promise<void>;
|
|
330
|
+
protected renderGroupOnce(group: CanvasEntry[], generation: number, viewport: ViewportState, clip: ClipEntry): Promise<void>;
|
|
220
331
|
protected renderRemainingViaIdle(canvases: CanvasEntry[], generation: number, viewport: ViewportState): Promise<void>;
|
|
221
332
|
protected yieldUntilIdle(): Promise<void>;
|
|
222
333
|
}
|
|
@@ -236,6 +347,10 @@ interface ViewportReadyDetail {
|
|
|
236
347
|
interface ChunkLike {
|
|
237
348
|
chunkIndex: number;
|
|
238
349
|
}
|
|
350
|
+
interface RenderableChunkLike extends ChunkLike {
|
|
351
|
+
clipId: string;
|
|
352
|
+
channelIndex: number;
|
|
353
|
+
}
|
|
239
354
|
/**
|
|
240
355
|
* Group a list of chunks into runs of contiguous chunk indices.
|
|
241
356
|
*
|
|
@@ -247,5 +362,17 @@ interface ChunkLike {
|
|
|
247
362
|
* two smaller FFTs (10–11, 14–15) totaling ~32K frames.
|
|
248
363
|
*/
|
|
249
364
|
declare function groupContiguousChunks<T extends ChunkLike>(chunks: T[]): T[][];
|
|
365
|
+
/**
|
|
366
|
+
* Group render canvases into runs of contiguous chunk indices, partitioned by
|
|
367
|
+
* `(clipId, channelIndex)` first.
|
|
368
|
+
*
|
|
369
|
+
* A track's canvases span multiple channels (one <daw-spectrogram> per channel,
|
|
370
|
+
* chunk indices shared) and multiple clips (chunk indices restart at 0 per
|
|
371
|
+
* clip). Grouping by chunk index alone interleaves them — e.g. stereo
|
|
372
|
+
* [ch0k0, ch1k0, ch0k1, ch1k1] yields the mixed group [ch1k0, ch0k1], which
|
|
373
|
+
* renderGroup then routes to a single channel's worker with a single clip's
|
|
374
|
+
* FFT data (issue #553).
|
|
375
|
+
*/
|
|
376
|
+
declare function groupRenderableChunks<T extends RenderableChunkLike>(chunks: T[]): T[][];
|
|
250
377
|
|
|
251
|
-
export { type CanvasMeta, type CanvasRegistration, type ChunkLike, type ClassifiedTiers, type ClipRegistration, ColorLUTCache, type FrequencyScaleName, SpectrogramAbortError, SpectrogramOrchestrator, type SpectrogramOrchestratorOptions, type SpectrogramWorkerApi, type SpectrogramWorkerFFTParams, type SpectrogramWorkerRenderChunksParams, type ViewportBounds, type ViewportReadyDetail, type ViewportState, classifyViewport, computeSpectrogram, computeSpectrogramMono, createSpectrogramWorker, createSpectrogramWorkerPool, getColorMap, getFrequencyScale, groupContiguousChunks };
|
|
378
|
+
export { type CanvasMeta, type CanvasRegistration, type ChunkLike, type ClassifiedTiers, type ClipRegistration, ColorLUTCache, type FrequencyScaleName, type PaddedFftRangeParams, type PixelColumnToFrameParams, type PixelRowToBinParams, type RenderableChunkLike, SpectrogramAbortError, SpectrogramOrchestrator, type SpectrogramOrchestratorOptions, type SpectrogramWorkerApi, type SpectrogramWorkerFFTParams, type SpectrogramWorkerRenderChunksParams, type ViewportBounds, type ViewportReadyDetail, type ViewportState, classifyViewport, computePaddedFftRange, computeSpectrogram, computeSpectrogramMono, createSpectrogramWorker, createSpectrogramWorkerPool, getColorMap, getFrequencyScale, groupContiguousChunks, groupRenderableChunks, pixelColumnToFrame, pixelRowToBin };
|