@waveform-playlist/spectrogram 12.0.0 → 13.0.0
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 +2 -115
- package/dist/index.d.ts +2 -115
- package/dist/index.js +93 -3645
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -3630
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -10
- package/dist/worker/spectrogram.worker.mjs +0 -606
- package/dist/worker/spectrogram.worker.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,53 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RenderMode, SpectrogramConfig, ColorMapValue } from '@waveform-playlist/core';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Compute spectrogram data from an AudioBuffer.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Compute spectrogram for a single channel of audio.
|
|
10
|
-
*
|
|
11
|
-
* @param audioBuffer - Source audio buffer
|
|
12
|
-
* @param config - Spectrogram configuration
|
|
13
|
-
* @param offsetSamples - Start offset into the audio buffer
|
|
14
|
-
* @param durationSamples - Number of samples to process
|
|
15
|
-
* @param channel - Channel index (0 = left, 1 = right). Default: 0
|
|
16
|
-
*/
|
|
17
|
-
declare function computeSpectrogram(audioBuffer: AudioBuffer, config?: SpectrogramConfig, offsetSamples?: number, durationSamples?: number, channel?: number): SpectrogramData;
|
|
18
|
-
/**
|
|
19
|
-
* Compute a mono (mixed-down) spectrogram from all channels.
|
|
20
|
-
*/
|
|
21
|
-
declare function computeSpectrogramMono(audioBuffer: AudioBuffer, config?: SpectrogramConfig, offsetSamples?: number, durationSamples?: number): SpectrogramData;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Color maps for spectrogram rendering.
|
|
25
|
-
* Each map is a 256-entry RGB lookup table (768 bytes).
|
|
26
|
-
*
|
|
27
|
-
* Viridis, Magma, Inferno: Perceptually uniform colormaps from matplotlib.
|
|
28
|
-
* By Stéfan van der Walt, Nathaniel Smith, and Eric Firing. Released under CC0.
|
|
29
|
-
* Data from https://github.com/BIDS/colormap
|
|
30
|
-
*
|
|
31
|
-
* Roseus: Perceptually uniform colormap from https://github.com/dofuuz/roseus
|
|
32
|
-
* By dofuuz, licensed under CC0 1.0 Universal.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
type ColorLUT = Uint8Array;
|
|
36
|
-
/**
|
|
37
|
-
* Get a 256-entry RGB LUT for the given color map.
|
|
38
|
-
*/
|
|
39
|
-
declare function getColorMap(value: ColorMapValue): ColorLUT;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Frequency scale mapping functions.
|
|
43
|
-
* Each maps a frequency (Hz) to a normalized position [0, 1].
|
|
44
|
-
*/
|
|
45
|
-
type FrequencyScaleName = 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb';
|
|
46
|
-
/**
|
|
47
|
-
* Returns a mapping function: (frequencyHz, minFrequency, maxFrequency) → [0, 1]
|
|
48
|
-
*/
|
|
49
|
-
declare function getFrequencyScale(name: FrequencyScaleName): (f: number, minF: number, maxF: number) => number;
|
|
50
|
-
|
|
51
4
|
interface TrackMenuItem {
|
|
52
5
|
id: string;
|
|
53
6
|
label?: string;
|
|
@@ -74,72 +27,6 @@ interface SpectrogramSettingsModalProps {
|
|
|
74
27
|
}
|
|
75
28
|
declare const SpectrogramSettingsModal: React.FC<SpectrogramSettingsModalProps>;
|
|
76
29
|
|
|
77
|
-
/**
|
|
78
|
-
* Error thrown when a spectrogram computation is aborted due to a generation change.
|
|
79
|
-
* Use `instanceof SpectrogramAbortError` instead of string matching on error messages.
|
|
80
|
-
*/
|
|
81
|
-
declare class SpectrogramAbortError extends Error {
|
|
82
|
-
constructor();
|
|
83
|
-
}
|
|
84
|
-
interface SpectrogramWorkerFFTParams {
|
|
85
|
-
clipId: string;
|
|
86
|
-
channelDataArrays: Float32Array[];
|
|
87
|
-
config: SpectrogramConfig;
|
|
88
|
-
sampleRate: number;
|
|
89
|
-
offsetSamples: number;
|
|
90
|
-
durationSamples: number;
|
|
91
|
-
mono: boolean;
|
|
92
|
-
sampleRange?: {
|
|
93
|
-
start: number;
|
|
94
|
-
end: number;
|
|
95
|
-
};
|
|
96
|
-
/** If set, compute only this channel index (used by worker pool). */
|
|
97
|
-
channelFilter?: number;
|
|
98
|
-
}
|
|
99
|
-
interface SpectrogramWorkerRenderChunksParams {
|
|
100
|
-
cacheKey: string;
|
|
101
|
-
canvasIds: string[];
|
|
102
|
-
canvasWidths: number[];
|
|
103
|
-
globalPixelOffsets: number[];
|
|
104
|
-
canvasHeight: number;
|
|
105
|
-
devicePixelRatio: number;
|
|
106
|
-
samplesPerPixel: number;
|
|
107
|
-
colorLUT: Uint8Array;
|
|
108
|
-
frequencyScale: string;
|
|
109
|
-
minFrequency: number;
|
|
110
|
-
maxFrequency: number;
|
|
111
|
-
gainDb: number;
|
|
112
|
-
rangeDb: number;
|
|
113
|
-
channelIndex: number;
|
|
114
|
-
}
|
|
115
|
-
interface SpectrogramWorkerApi {
|
|
116
|
-
computeFFT(params: SpectrogramWorkerFFTParams, generation?: number): Promise<{
|
|
117
|
-
cacheKey: string;
|
|
118
|
-
}>;
|
|
119
|
-
renderChunks(params: SpectrogramWorkerRenderChunksParams, generation?: number): Promise<void>;
|
|
120
|
-
abortGeneration(generation: number): void;
|
|
121
|
-
registerCanvas(canvasId: string, canvas: OffscreenCanvas): void;
|
|
122
|
-
unregisterCanvas(canvasId: string): void;
|
|
123
|
-
registerAudioData(clipId: string, channelDataArrays: Float32Array[], sampleRate: number): void;
|
|
124
|
-
unregisterAudioData(clipId: string): void;
|
|
125
|
-
terminate(): void;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Wraps a Web Worker running `spectrogram.worker.ts` with a promise-based API.
|
|
129
|
-
*
|
|
130
|
-
* The caller is responsible for creating the Worker, e.g.:
|
|
131
|
-
* ```ts
|
|
132
|
-
* const worker = new Worker(
|
|
133
|
-
* new URL('@waveform-playlist/spectrogram/worker/spectrogram.worker', import.meta.url),
|
|
134
|
-
* { type: 'module' }
|
|
135
|
-
* );
|
|
136
|
-
* const api = createSpectrogramWorker(worker);
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
declare function createSpectrogramWorker(worker: Worker): SpectrogramWorkerApi;
|
|
140
|
-
|
|
141
|
-
declare function createSpectrogramWorkerPool(createWorker: () => Worker, poolSize?: number): SpectrogramWorkerApi;
|
|
142
|
-
|
|
143
30
|
interface SpectrogramProviderProps {
|
|
144
31
|
config?: SpectrogramConfig;
|
|
145
32
|
colorMap?: ColorMapValue;
|
|
@@ -149,4 +36,4 @@ interface SpectrogramProviderProps {
|
|
|
149
36
|
}
|
|
150
37
|
declare const SpectrogramProvider: React.FC<SpectrogramProviderProps>;
|
|
151
38
|
|
|
152
|
-
export {
|
|
39
|
+
export { SpectrogramMenuItems, type SpectrogramMenuItemsProps, SpectrogramProvider, type SpectrogramProviderProps, SpectrogramSettingsModal, type SpectrogramSettingsModalProps, type TrackMenuItem };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RenderMode, SpectrogramConfig, ColorMapValue } from '@waveform-playlist/core';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Compute spectrogram data from an AudioBuffer.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Compute spectrogram for a single channel of audio.
|
|
10
|
-
*
|
|
11
|
-
* @param audioBuffer - Source audio buffer
|
|
12
|
-
* @param config - Spectrogram configuration
|
|
13
|
-
* @param offsetSamples - Start offset into the audio buffer
|
|
14
|
-
* @param durationSamples - Number of samples to process
|
|
15
|
-
* @param channel - Channel index (0 = left, 1 = right). Default: 0
|
|
16
|
-
*/
|
|
17
|
-
declare function computeSpectrogram(audioBuffer: AudioBuffer, config?: SpectrogramConfig, offsetSamples?: number, durationSamples?: number, channel?: number): SpectrogramData;
|
|
18
|
-
/**
|
|
19
|
-
* Compute a mono (mixed-down) spectrogram from all channels.
|
|
20
|
-
*/
|
|
21
|
-
declare function computeSpectrogramMono(audioBuffer: AudioBuffer, config?: SpectrogramConfig, offsetSamples?: number, durationSamples?: number): SpectrogramData;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Color maps for spectrogram rendering.
|
|
25
|
-
* Each map is a 256-entry RGB lookup table (768 bytes).
|
|
26
|
-
*
|
|
27
|
-
* Viridis, Magma, Inferno: Perceptually uniform colormaps from matplotlib.
|
|
28
|
-
* By Stéfan van der Walt, Nathaniel Smith, and Eric Firing. Released under CC0.
|
|
29
|
-
* Data from https://github.com/BIDS/colormap
|
|
30
|
-
*
|
|
31
|
-
* Roseus: Perceptually uniform colormap from https://github.com/dofuuz/roseus
|
|
32
|
-
* By dofuuz, licensed under CC0 1.0 Universal.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
type ColorLUT = Uint8Array;
|
|
36
|
-
/**
|
|
37
|
-
* Get a 256-entry RGB LUT for the given color map.
|
|
38
|
-
*/
|
|
39
|
-
declare function getColorMap(value: ColorMapValue): ColorLUT;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Frequency scale mapping functions.
|
|
43
|
-
* Each maps a frequency (Hz) to a normalized position [0, 1].
|
|
44
|
-
*/
|
|
45
|
-
type FrequencyScaleName = 'linear' | 'logarithmic' | 'mel' | 'bark' | 'erb';
|
|
46
|
-
/**
|
|
47
|
-
* Returns a mapping function: (frequencyHz, minFrequency, maxFrequency) → [0, 1]
|
|
48
|
-
*/
|
|
49
|
-
declare function getFrequencyScale(name: FrequencyScaleName): (f: number, minF: number, maxF: number) => number;
|
|
50
|
-
|
|
51
4
|
interface TrackMenuItem {
|
|
52
5
|
id: string;
|
|
53
6
|
label?: string;
|
|
@@ -74,72 +27,6 @@ interface SpectrogramSettingsModalProps {
|
|
|
74
27
|
}
|
|
75
28
|
declare const SpectrogramSettingsModal: React.FC<SpectrogramSettingsModalProps>;
|
|
76
29
|
|
|
77
|
-
/**
|
|
78
|
-
* Error thrown when a spectrogram computation is aborted due to a generation change.
|
|
79
|
-
* Use `instanceof SpectrogramAbortError` instead of string matching on error messages.
|
|
80
|
-
*/
|
|
81
|
-
declare class SpectrogramAbortError extends Error {
|
|
82
|
-
constructor();
|
|
83
|
-
}
|
|
84
|
-
interface SpectrogramWorkerFFTParams {
|
|
85
|
-
clipId: string;
|
|
86
|
-
channelDataArrays: Float32Array[];
|
|
87
|
-
config: SpectrogramConfig;
|
|
88
|
-
sampleRate: number;
|
|
89
|
-
offsetSamples: number;
|
|
90
|
-
durationSamples: number;
|
|
91
|
-
mono: boolean;
|
|
92
|
-
sampleRange?: {
|
|
93
|
-
start: number;
|
|
94
|
-
end: number;
|
|
95
|
-
};
|
|
96
|
-
/** If set, compute only this channel index (used by worker pool). */
|
|
97
|
-
channelFilter?: number;
|
|
98
|
-
}
|
|
99
|
-
interface SpectrogramWorkerRenderChunksParams {
|
|
100
|
-
cacheKey: string;
|
|
101
|
-
canvasIds: string[];
|
|
102
|
-
canvasWidths: number[];
|
|
103
|
-
globalPixelOffsets: number[];
|
|
104
|
-
canvasHeight: number;
|
|
105
|
-
devicePixelRatio: number;
|
|
106
|
-
samplesPerPixel: number;
|
|
107
|
-
colorLUT: Uint8Array;
|
|
108
|
-
frequencyScale: string;
|
|
109
|
-
minFrequency: number;
|
|
110
|
-
maxFrequency: number;
|
|
111
|
-
gainDb: number;
|
|
112
|
-
rangeDb: number;
|
|
113
|
-
channelIndex: number;
|
|
114
|
-
}
|
|
115
|
-
interface SpectrogramWorkerApi {
|
|
116
|
-
computeFFT(params: SpectrogramWorkerFFTParams, generation?: number): Promise<{
|
|
117
|
-
cacheKey: string;
|
|
118
|
-
}>;
|
|
119
|
-
renderChunks(params: SpectrogramWorkerRenderChunksParams, generation?: number): Promise<void>;
|
|
120
|
-
abortGeneration(generation: number): void;
|
|
121
|
-
registerCanvas(canvasId: string, canvas: OffscreenCanvas): void;
|
|
122
|
-
unregisterCanvas(canvasId: string): void;
|
|
123
|
-
registerAudioData(clipId: string, channelDataArrays: Float32Array[], sampleRate: number): void;
|
|
124
|
-
unregisterAudioData(clipId: string): void;
|
|
125
|
-
terminate(): void;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Wraps a Web Worker running `spectrogram.worker.ts` with a promise-based API.
|
|
129
|
-
*
|
|
130
|
-
* The caller is responsible for creating the Worker, e.g.:
|
|
131
|
-
* ```ts
|
|
132
|
-
* const worker = new Worker(
|
|
133
|
-
* new URL('@waveform-playlist/spectrogram/worker/spectrogram.worker', import.meta.url),
|
|
134
|
-
* { type: 'module' }
|
|
135
|
-
* );
|
|
136
|
-
* const api = createSpectrogramWorker(worker);
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
declare function createSpectrogramWorker(worker: Worker): SpectrogramWorkerApi;
|
|
140
|
-
|
|
141
|
-
declare function createSpectrogramWorkerPool(createWorker: () => Worker, poolSize?: number): SpectrogramWorkerApi;
|
|
142
|
-
|
|
143
30
|
interface SpectrogramProviderProps {
|
|
144
31
|
config?: SpectrogramConfig;
|
|
145
32
|
colorMap?: ColorMapValue;
|
|
@@ -149,4 +36,4 @@ interface SpectrogramProviderProps {
|
|
|
149
36
|
}
|
|
150
37
|
declare const SpectrogramProvider: React.FC<SpectrogramProviderProps>;
|
|
151
38
|
|
|
152
|
-
export {
|
|
39
|
+
export { SpectrogramMenuItems, type SpectrogramMenuItemsProps, SpectrogramProvider, type SpectrogramProviderProps, SpectrogramSettingsModal, type SpectrogramSettingsModalProps, type TrackMenuItem };
|