@dawcore/spectrogram 0.0.4 → 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/dist/index.d.mts +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +44 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -16
- package/dist/index.mjs.map +1 -1
- package/dist/orchestrator/index.mjs +36 -16
- package/dist/orchestrator/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -92,6 +92,38 @@ interface PixelRowToBinParams {
|
|
|
92
92
|
*/
|
|
93
93
|
declare function pixelRowToBin(params: PixelRowToBinParams): number;
|
|
94
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
|
+
|
|
95
127
|
/**
|
|
96
128
|
* Error thrown when a spectrogram computation is aborted due to a generation change.
|
|
97
129
|
* Use `instanceof SpectrogramAbortError` instead of string matching on error messages.
|
|
@@ -343,4 +375,4 @@ declare function groupContiguousChunks<T extends ChunkLike>(chunks: T[]): T[][];
|
|
|
343
375
|
*/
|
|
344
376
|
declare function groupRenderableChunks<T extends RenderableChunkLike>(chunks: T[]): T[][];
|
|
345
377
|
|
|
346
|
-
export { type CanvasMeta, type CanvasRegistration, type ChunkLike, type ClassifiedTiers, type ClipRegistration, ColorLUTCache, type FrequencyScaleName, type PixelColumnToFrameParams, type PixelRowToBinParams, type RenderableChunkLike, SpectrogramAbortError, SpectrogramOrchestrator, type SpectrogramOrchestratorOptions, type SpectrogramWorkerApi, type SpectrogramWorkerFFTParams, type SpectrogramWorkerRenderChunksParams, type ViewportBounds, type ViewportReadyDetail, type ViewportState, classifyViewport, computeSpectrogram, computeSpectrogramMono, createSpectrogramWorker, createSpectrogramWorkerPool, getColorMap, getFrequencyScale, groupContiguousChunks, groupRenderableChunks, pixelColumnToFrame, pixelRowToBin };
|
|
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
|
@@ -92,6 +92,38 @@ interface PixelRowToBinParams {
|
|
|
92
92
|
*/
|
|
93
93
|
declare function pixelRowToBin(params: PixelRowToBinParams): number;
|
|
94
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
|
+
|
|
95
127
|
/**
|
|
96
128
|
* Error thrown when a spectrogram computation is aborted due to a generation change.
|
|
97
129
|
* Use `instanceof SpectrogramAbortError` instead of string matching on error messages.
|
|
@@ -343,4 +375,4 @@ declare function groupContiguousChunks<T extends ChunkLike>(chunks: T[]): T[][];
|
|
|
343
375
|
*/
|
|
344
376
|
declare function groupRenderableChunks<T extends RenderableChunkLike>(chunks: T[]): T[][];
|
|
345
377
|
|
|
346
|
-
export { type CanvasMeta, type CanvasRegistration, type ChunkLike, type ClassifiedTiers, type ClipRegistration, ColorLUTCache, type FrequencyScaleName, type PixelColumnToFrameParams, type PixelRowToBinParams, type RenderableChunkLike, SpectrogramAbortError, SpectrogramOrchestrator, type SpectrogramOrchestratorOptions, type SpectrogramWorkerApi, type SpectrogramWorkerFFTParams, type SpectrogramWorkerRenderChunksParams, type ViewportBounds, type ViewportReadyDetail, type ViewportState, classifyViewport, computeSpectrogram, computeSpectrogramMono, createSpectrogramWorker, createSpectrogramWorkerPool, getColorMap, getFrequencyScale, groupContiguousChunks, groupRenderableChunks, pixelColumnToFrame, pixelRowToBin };
|
|
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.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
SpectrogramAbortError: () => SpectrogramAbortError,
|
|
35
35
|
SpectrogramOrchestrator: () => SpectrogramOrchestrator,
|
|
36
36
|
classifyViewport: () => classifyViewport,
|
|
37
|
+
computePaddedFftRange: () => computePaddedFftRange,
|
|
37
38
|
computeSpectrogram: () => computeSpectrogram,
|
|
38
39
|
computeSpectrogramMono: () => computeSpectrogramMono,
|
|
39
40
|
createSpectrogramWorker: () => createSpectrogramWorker,
|
|
@@ -3468,6 +3469,27 @@ function pixelRowToBin(params) {
|
|
|
3468
3469
|
return Math.min(bin, frequencyBinCount - 1);
|
|
3469
3470
|
}
|
|
3470
3471
|
|
|
3472
|
+
// src/computation/fftSampleRange.ts
|
|
3473
|
+
var import_core = require("@waveform-playlist/core");
|
|
3474
|
+
function computePaddedFftRange({
|
|
3475
|
+
chunks,
|
|
3476
|
+
fftSize,
|
|
3477
|
+
offsetSamples,
|
|
3478
|
+
durationSamples,
|
|
3479
|
+
samplesPerPixel
|
|
3480
|
+
}) {
|
|
3481
|
+
const startPx = Math.min(...chunks.map((c) => c.chunkIndex * import_core.MAX_CANVAS_WIDTH));
|
|
3482
|
+
const endPx = Math.max(...chunks.map((c) => c.chunkIndex * import_core.MAX_CANVAS_WIDTH + c.widthPx));
|
|
3483
|
+
const startSample = offsetSamples + Math.floor(startPx * samplesPerPixel);
|
|
3484
|
+
const endSample = Math.min(
|
|
3485
|
+
offsetSamples + durationSamples,
|
|
3486
|
+
offsetSamples + Math.ceil(endPx * samplesPerPixel)
|
|
3487
|
+
);
|
|
3488
|
+
const paddedStart = Math.max(offsetSamples, startSample - fftSize);
|
|
3489
|
+
const paddedEnd = Math.min(offsetSamples + durationSamples, endSample + fftSize);
|
|
3490
|
+
return { paddedStart, paddedEnd };
|
|
3491
|
+
}
|
|
3492
|
+
|
|
3471
3493
|
// src/worker/createSpectrogramWorker.ts
|
|
3472
3494
|
var SpectrogramAbortError = class extends Error {
|
|
3473
3495
|
constructor() {
|
|
@@ -3609,15 +3631,16 @@ function createSpectrogramWorker(worker) {
|
|
|
3609
3631
|
}
|
|
3610
3632
|
|
|
3611
3633
|
// src/worker/createSpectrogramWorkerPool.ts
|
|
3634
|
+
var import_core2 = require("@waveform-playlist/core");
|
|
3612
3635
|
function parseChannelFromCanvasId(canvasId) {
|
|
3613
|
-
const
|
|
3614
|
-
if (!
|
|
3636
|
+
const parsed = (0, import_core2.parseSpectrogramCanvasId)(canvasId);
|
|
3637
|
+
if (!parsed) {
|
|
3615
3638
|
console.warn(
|
|
3616
3639
|
"[dawcore-spectrogram] canvas ID missing -ch{N}-chunk{M} suffix, routing to worker 0: " + canvasId
|
|
3617
3640
|
);
|
|
3618
3641
|
return 0;
|
|
3619
3642
|
}
|
|
3620
|
-
return
|
|
3643
|
+
return parsed.channelIndex;
|
|
3621
3644
|
}
|
|
3622
3645
|
function defaultPoolSize() {
|
|
3623
3646
|
return 2;
|
|
@@ -3767,7 +3790,7 @@ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize())
|
|
|
3767
3790
|
}
|
|
3768
3791
|
|
|
3769
3792
|
// src/orchestrator/SpectrogramOrchestrator.ts
|
|
3770
|
-
var
|
|
3793
|
+
var import_core3 = require("@waveform-playlist/core");
|
|
3771
3794
|
|
|
3772
3795
|
// src/orchestrator/color-lut-cache.ts
|
|
3773
3796
|
var ColorLUTCache = class {
|
|
@@ -3875,7 +3898,7 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3875
3898
|
const poolSize = opts.workerPoolSize ?? 2;
|
|
3876
3899
|
this.pool = createSpectrogramWorkerPool(opts.workerFactory, poolSize);
|
|
3877
3900
|
this.config = opts.config;
|
|
3878
|
-
this.colorMap = opts.colorMap ??
|
|
3901
|
+
this.colorMap = opts.colorMap ?? import_core3.DEFAULT_SPECTROGRAM_COLOR_MAP;
|
|
3879
3902
|
this.devicePixelRatio = opts.devicePixelRatio ?? (typeof window !== "undefined" ? window.devicePixelRatio : 1);
|
|
3880
3903
|
}
|
|
3881
3904
|
registerClip(reg) {
|
|
@@ -3924,7 +3947,7 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3924
3947
|
channelIndex: reg.channelIndex,
|
|
3925
3948
|
chunkIndex: reg.chunkIndex
|
|
3926
3949
|
});
|
|
3927
|
-
const originPx = reg.globalPixelOffset - reg.chunkIndex *
|
|
3950
|
+
const originPx = reg.globalPixelOffset - reg.chunkIndex * import_core3.MAX_CANVAS_WIDTH;
|
|
3928
3951
|
const origin = this.clipOrigins.get(reg.clipId);
|
|
3929
3952
|
if (!origin) {
|
|
3930
3953
|
this.clipOrigins.set(reg.clipId, { originPx, canvasCount: 1 });
|
|
@@ -3932,7 +3955,7 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3932
3955
|
origin.canvasCount += 1;
|
|
3933
3956
|
if (origin.originPx !== originPx) {
|
|
3934
3957
|
console.warn(
|
|
3935
|
-
"[dawcore-spectrogram] registerCanvas: " + reg.canvasId + " violates the chunk layout contract (chunk " + reg.chunkIndex + " at " + reg.globalPixelOffset + "px implies clip origin " + originPx + "px, but other canvases imply " + origin.originPx + "px) \u2014 sample math assumes chunkIndex * " +
|
|
3958
|
+
"[dawcore-spectrogram] registerCanvas: " + reg.canvasId + " violates the chunk layout contract (chunk " + reg.chunkIndex + " at " + reg.globalPixelOffset + "px implies clip origin " + originPx + "px, but other canvases imply " + origin.originPx + "px) \u2014 sample math assumes chunkIndex * " + import_core3.MAX_CANVAS_WIDTH + "px and this clip will render shifted audio"
|
|
3936
3959
|
);
|
|
3937
3960
|
}
|
|
3938
3961
|
}
|
|
@@ -4123,17 +4146,15 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
4123
4146
|
}
|
|
4124
4147
|
async renderGroupOnce(group, generation, viewport, clip) {
|
|
4125
4148
|
const first = group[0];
|
|
4126
|
-
const fftSize = this.config.fftSize ??
|
|
4127
|
-
const clipRelativeOffsets = group.map((c) => c.chunkIndex *
|
|
4128
|
-
const
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
);
|
|
4135
|
-
const paddedStart = Math.max(clip.offsetSamples, startSample - fftSize);
|
|
4136
|
-
const paddedEnd = Math.min(clip.offsetSamples + clip.durationSamples, endSample + fftSize);
|
|
4149
|
+
const fftSize = this.config.fftSize ?? import_core3.SPECTROGRAM_DEFAULTS.fftSize;
|
|
4150
|
+
const clipRelativeOffsets = group.map((c) => c.chunkIndex * import_core3.MAX_CANVAS_WIDTH);
|
|
4151
|
+
const { paddedStart, paddedEnd } = computePaddedFftRange({
|
|
4152
|
+
chunks: group.map((c) => ({ chunkIndex: c.chunkIndex, widthPx: c.widthPx })),
|
|
4153
|
+
fftSize,
|
|
4154
|
+
offsetSamples: clip.offsetSamples,
|
|
4155
|
+
durationSamples: clip.durationSamples,
|
|
4156
|
+
samplesPerPixel: viewport.samplesPerPixel
|
|
4157
|
+
});
|
|
4137
4158
|
const { cacheKey: cacheKey2 } = await this.pool.computeFFT(
|
|
4138
4159
|
{
|
|
4139
4160
|
clipId: first.clipId,
|
|
@@ -4159,11 +4180,11 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
4159
4180
|
devicePixelRatio: this.devicePixelRatio,
|
|
4160
4181
|
samplesPerPixel: viewport.samplesPerPixel,
|
|
4161
4182
|
colorLUT,
|
|
4162
|
-
frequencyScale: String(this.config.frequencyScale ??
|
|
4163
|
-
minFrequency: this.config.minFrequency ??
|
|
4183
|
+
frequencyScale: String(this.config.frequencyScale ?? import_core3.SPECTROGRAM_DEFAULTS.frequencyScale),
|
|
4184
|
+
minFrequency: this.config.minFrequency ?? import_core3.SPECTROGRAM_DEFAULTS.minFrequency,
|
|
4164
4185
|
maxFrequency: this.config.maxFrequency ?? clip.sampleRate / 2,
|
|
4165
|
-
gainDb: this.config.gainDb ??
|
|
4166
|
-
rangeDb: this.config.rangeDb ??
|
|
4186
|
+
gainDb: this.config.gainDb ?? import_core3.SPECTROGRAM_DEFAULTS.gainDb,
|
|
4187
|
+
rangeDb: this.config.rangeDb ?? import_core3.SPECTROGRAM_DEFAULTS.rangeDb,
|
|
4167
4188
|
channelIndex: first.channelIndex
|
|
4168
4189
|
},
|
|
4169
4190
|
generation
|
|
@@ -4207,6 +4228,7 @@ function viewportsEqual(a, b) {
|
|
|
4207
4228
|
SpectrogramAbortError,
|
|
4208
4229
|
SpectrogramOrchestrator,
|
|
4209
4230
|
classifyViewport,
|
|
4231
|
+
computePaddedFftRange,
|
|
4210
4232
|
computeSpectrogram,
|
|
4211
4233
|
computeSpectrogramMono,
|
|
4212
4234
|
createSpectrogramWorker,
|