@siteed/audio-studio 3.0.0 → 3.0.2-beta.1
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/CHANGELOG.md +356 -415
- package/README.md +1 -1
- package/android/src/main/CMakeLists.txt +3 -0
- package/build/cjs/AudioAnalysis/audioFeaturesWasm.js +7 -155
- package/build/cjs/AudioAnalysis/audioFeaturesWasm.js.map +1 -1
- package/build/cjs/AudioAnalysis/audioFeaturesWasm.web.js +165 -0
- package/build/cjs/AudioAnalysis/audioFeaturesWasm.web.js.map +1 -0
- package/build/cjs/AudioAnalysis/melSpectrogramWasm.js +8 -140
- package/build/cjs/AudioAnalysis/melSpectrogramWasm.js.map +1 -1
- package/build/cjs/AudioAnalysis/melSpectrogramWasm.web.js +153 -0
- package/build/cjs/AudioAnalysis/melSpectrogramWasm.web.js.map +1 -0
- package/build/cjs/AudioAnalysis/wasmConfig.js +26 -0
- package/build/cjs/AudioAnalysis/wasmConfig.js.map +1 -0
- package/build/cjs/index.js +3 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/prebuilt/wasm/mel-spectrogram.js +18 -0
- package/build/esm/AudioAnalysis/audioFeaturesWasm.js +7 -122
- package/build/esm/AudioAnalysis/audioFeaturesWasm.js.map +1 -1
- package/build/esm/AudioAnalysis/audioFeaturesWasm.web.js +127 -0
- package/build/esm/AudioAnalysis/audioFeaturesWasm.web.js.map +1 -0
- package/build/esm/AudioAnalysis/melSpectrogramWasm.js +8 -107
- package/build/esm/AudioAnalysis/melSpectrogramWasm.js.map +1 -1
- package/build/esm/AudioAnalysis/melSpectrogramWasm.web.js +115 -0
- package/build/esm/AudioAnalysis/melSpectrogramWasm.web.js.map +1 -0
- package/build/esm/AudioAnalysis/wasmConfig.js +21 -0
- package/build/esm/AudioAnalysis/wasmConfig.js.map +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/prebuilt/wasm/mel-spectrogram.js +18 -0
- package/build/types/AudioAnalysis/audioFeaturesWasm.d.ts +3 -15
- package/build/types/AudioAnalysis/audioFeaturesWasm.d.ts.map +1 -1
- package/build/types/AudioAnalysis/audioFeaturesWasm.web.d.ts +24 -0
- package/build/types/AudioAnalysis/audioFeaturesWasm.web.d.ts.map +1 -0
- package/build/types/AudioAnalysis/melSpectrogramWasm.d.ts +3 -15
- package/build/types/AudioAnalysis/melSpectrogramWasm.d.ts.map +1 -1
- package/build/types/AudioAnalysis/melSpectrogramWasm.web.d.ts +16 -0
- package/build/types/AudioAnalysis/melSpectrogramWasm.web.d.ts.map +1 -0
- package/build/types/AudioAnalysis/wasmConfig.d.ts +4 -0
- package/build/types/AudioAnalysis/wasmConfig.d.ts.map +1 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/AudioAnalysis/audioFeaturesWasm.ts +18 -179
- package/src/AudioAnalysis/audioFeaturesWasm.web.ts +201 -0
- package/src/AudioAnalysis/melSpectrogramWasm.ts +23 -169
- package/src/AudioAnalysis/melSpectrogramWasm.web.ts +184 -0
- package/src/AudioAnalysis/wasmConfig.ts +24 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { getMelSpectrogramWasmUrl } from './wasmConfig';
|
|
2
|
+
let modulePromise = null;
|
|
3
|
+
function getModule() {
|
|
4
|
+
if (!modulePromise) {
|
|
5
|
+
modulePromise = (async () => {
|
|
6
|
+
const url = getMelSpectrogramWasmUrl();
|
|
7
|
+
// webpackIgnore + @vite-ignore prevent bundlers from trying to resolve the URL
|
|
8
|
+
const mod = await import(/* webpackIgnore: true */ /* @vite-ignore */ url);
|
|
9
|
+
const factory = mod.default ?? mod;
|
|
10
|
+
return factory();
|
|
11
|
+
})().catch((err) => {
|
|
12
|
+
modulePromise = null;
|
|
13
|
+
throw err;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return modulePromise;
|
|
17
|
+
}
|
|
18
|
+
// --- Struct layout for CAudioFeaturesResult (wasm32) ---
|
|
19
|
+
// Offset 0: float spectralCentroid (4 bytes)
|
|
20
|
+
// Offset 4: float spectralFlatness (4 bytes)
|
|
21
|
+
// Offset 8: float spectralRolloff (4 bytes)
|
|
22
|
+
// Offset 12: float spectralBandwidth (4 bytes)
|
|
23
|
+
// Offset 16: float* mfcc (4 bytes pointer)
|
|
24
|
+
// Offset 20: int mfccCount (4 bytes)
|
|
25
|
+
// Offset 24: float* chromagram (4 bytes pointer)
|
|
26
|
+
// Offset 28: int chromagramCount (4 bytes)
|
|
27
|
+
const STRUCT_SIZE = 32;
|
|
28
|
+
function readResult(Module, ptr) {
|
|
29
|
+
const spectralCentroid = Module.getValue(ptr, 'float');
|
|
30
|
+
const spectralFlatness = Module.getValue(ptr + 4, 'float');
|
|
31
|
+
const spectralRolloff = Module.getValue(ptr + 8, 'float');
|
|
32
|
+
const spectralBandwidth = Module.getValue(ptr + 12, 'float');
|
|
33
|
+
const mfccPtr = Module.getValue(ptr + 16, 'i32');
|
|
34
|
+
const mfccCount = Module.getValue(ptr + 20, 'i32');
|
|
35
|
+
const chromaPtr = Module.getValue(ptr + 24, 'i32');
|
|
36
|
+
const chromaCount = Module.getValue(ptr + 28, 'i32');
|
|
37
|
+
const mfcc = [];
|
|
38
|
+
if (mfccPtr && mfccCount > 0) {
|
|
39
|
+
const offset = mfccPtr >> 2;
|
|
40
|
+
for (let i = 0; i < mfccCount; i++) {
|
|
41
|
+
mfcc.push(Module.HEAPF32[offset + i]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const chromagram = [];
|
|
45
|
+
if (chromaPtr && chromaCount > 0) {
|
|
46
|
+
const offset = chromaPtr >> 2;
|
|
47
|
+
for (let i = 0; i < chromaCount; i++) {
|
|
48
|
+
chromagram.push(Module.HEAPF32[offset + i]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
spectralCentroid,
|
|
53
|
+
spectralFlatness,
|
|
54
|
+
spectralRolloff,
|
|
55
|
+
spectralBandwidth,
|
|
56
|
+
mfcc,
|
|
57
|
+
chromagram,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// --- Streaming (per-frame) API ---
|
|
61
|
+
let streamingModule = null;
|
|
62
|
+
let streamingFramePtr = 0;
|
|
63
|
+
let streamingFrameCapacity = 0;
|
|
64
|
+
let streamingResultPtr = 0;
|
|
65
|
+
/**
|
|
66
|
+
* Initialise the WASM streaming audio features processor.
|
|
67
|
+
* Call once before computeAudioFeaturesFrameWasm().
|
|
68
|
+
*/
|
|
69
|
+
export async function initAudioFeaturesWasm(sampleRate, fftLength = 1024, nMfcc = 13, nMelFilters = 26, computeMfcc = true, computeChroma = true) {
|
|
70
|
+
const Module = await getModule();
|
|
71
|
+
streamingModule = Module;
|
|
72
|
+
Module._audio_features_init(sampleRate, fftLength, nMfcc, nMelFilters, computeMfcc ? 1 : 0, computeChroma ? 1 : 0);
|
|
73
|
+
// Pre-allocate result struct on WASM heap
|
|
74
|
+
if (streamingResultPtr)
|
|
75
|
+
Module._free(streamingResultPtr);
|
|
76
|
+
streamingResultPtr = Module._malloc(STRUCT_SIZE);
|
|
77
|
+
// Zero-initialize to prevent freeing garbage pointers on first use
|
|
78
|
+
Module.HEAPU8.fill(0, streamingResultPtr, streamingResultPtr + STRUCT_SIZE);
|
|
79
|
+
// Frame input buffer allocated on demand
|
|
80
|
+
streamingFrameCapacity = 0;
|
|
81
|
+
streamingFramePtr = 0;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Compute audio features for a single frame via WASM C++.
|
|
85
|
+
* Returns null if not initialised or on error.
|
|
86
|
+
*/
|
|
87
|
+
export function computeAudioFeaturesFrameWasm(samples) {
|
|
88
|
+
if (!streamingModule || !streamingResultPtr)
|
|
89
|
+
return null;
|
|
90
|
+
const Module = streamingModule;
|
|
91
|
+
// (Re-)allocate frame input buffer if needed
|
|
92
|
+
if (samples.length > streamingFrameCapacity) {
|
|
93
|
+
if (streamingFramePtr)
|
|
94
|
+
Module._free(streamingFramePtr);
|
|
95
|
+
streamingFramePtr = Module._malloc(samples.length * 4);
|
|
96
|
+
streamingFrameCapacity = samples.length;
|
|
97
|
+
}
|
|
98
|
+
// Copy samples to WASM heap
|
|
99
|
+
Module.HEAPF32.set(samples, streamingFramePtr >> 2);
|
|
100
|
+
const ok = Module._audio_features_compute_frame(streamingFramePtr, samples.length, streamingResultPtr);
|
|
101
|
+
if (!ok)
|
|
102
|
+
return null;
|
|
103
|
+
const result = readResult(Module, streamingResultPtr);
|
|
104
|
+
// Free internal arrays (mfcc, chromagram) allocated by C
|
|
105
|
+
Module._audio_features_free_arrays(streamingResultPtr);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
// --- Batch API ---
|
|
109
|
+
/**
|
|
110
|
+
* Compute audio features for a buffer of samples via WASM C++.
|
|
111
|
+
* Lazy-loads the WASM module on first call.
|
|
112
|
+
*/
|
|
113
|
+
export async function computeAudioFeaturesWasm(audioData, sampleRate, fftLength = 1024, nMfcc = 13, nMelFilters = 26, computeMfcc = true, computeChroma = true) {
|
|
114
|
+
const Module = await getModule();
|
|
115
|
+
const numSamples = audioData.length;
|
|
116
|
+
const inputPtr = Module._malloc(numSamples * 4);
|
|
117
|
+
Module.HEAPF32.set(audioData, inputPtr >> 2);
|
|
118
|
+
const resultPtr = Module._audio_features_compute(inputPtr, numSamples, sampleRate, fftLength, nMfcc, nMelFilters, computeMfcc ? 1 : 0, computeChroma ? 1 : 0);
|
|
119
|
+
Module._free(inputPtr);
|
|
120
|
+
if (resultPtr === 0) {
|
|
121
|
+
throw new Error('audio_features_compute returned null');
|
|
122
|
+
}
|
|
123
|
+
const result = readResult(Module, resultPtr);
|
|
124
|
+
Module._audio_features_free(resultPtr);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=audioFeaturesWasm.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnB,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACxB,CAAA;IAED,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAEtB,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IAC3D,CAAC;IAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC5C,MAAM,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAA;IAEtC,OAAO,MAAM,CAAA;AACjB,CAAC","sourcesContent":["import type { AudioFeaturesWasmModule } from './audio-features-wasm'\nimport { getMelSpectrogramWasmUrl } from './wasmConfig'\n\nexport interface AudioFeaturesWasmResult {\n spectralCentroid: number\n spectralFlatness: number\n spectralRolloff: number\n spectralBandwidth: number\n mfcc: number[]\n chromagram: number[]\n}\n\nlet modulePromise: Promise<AudioFeaturesWasmModule> | null = null\n\nfunction getModule(): Promise<AudioFeaturesWasmModule> {\n if (!modulePromise) {\n modulePromise = (async () => {\n const url = getMelSpectrogramWasmUrl()\n // webpackIgnore + @vite-ignore prevent bundlers from trying to resolve the URL\n const mod = await import(/* webpackIgnore: true */ /* @vite-ignore */ url)\n const factory = mod.default ?? mod\n return factory() as Promise<AudioFeaturesWasmModule>\n })().catch((err) => {\n modulePromise = null\n throw err\n })\n }\n return modulePromise\n}\n\n// --- Struct layout for CAudioFeaturesResult (wasm32) ---\n// Offset 0: float spectralCentroid (4 bytes)\n// Offset 4: float spectralFlatness (4 bytes)\n// Offset 8: float spectralRolloff (4 bytes)\n// Offset 12: float spectralBandwidth (4 bytes)\n// Offset 16: float* mfcc (4 bytes pointer)\n// Offset 20: int mfccCount (4 bytes)\n// Offset 24: float* chromagram (4 bytes pointer)\n// Offset 28: int chromagramCount (4 bytes)\nconst STRUCT_SIZE = 32\n\nfunction readResult(\n Module: AudioFeaturesWasmModule,\n ptr: number\n): AudioFeaturesWasmResult {\n const spectralCentroid = Module.getValue(ptr, 'float')\n const spectralFlatness = Module.getValue(ptr + 4, 'float')\n const spectralRolloff = Module.getValue(ptr + 8, 'float')\n const spectralBandwidth = Module.getValue(ptr + 12, 'float')\n\n const mfccPtr = Module.getValue(ptr + 16, 'i32')\n const mfccCount = Module.getValue(ptr + 20, 'i32')\n const chromaPtr = Module.getValue(ptr + 24, 'i32')\n const chromaCount = Module.getValue(ptr + 28, 'i32')\n\n const mfcc: number[] = []\n if (mfccPtr && mfccCount > 0) {\n const offset = mfccPtr >> 2\n for (let i = 0; i < mfccCount; i++) {\n mfcc.push(Module.HEAPF32[offset + i])\n }\n }\n\n const chromagram: number[] = []\n if (chromaPtr && chromaCount > 0) {\n const offset = chromaPtr >> 2\n for (let i = 0; i < chromaCount; i++) {\n chromagram.push(Module.HEAPF32[offset + i])\n }\n }\n\n return {\n spectralCentroid,\n spectralFlatness,\n spectralRolloff,\n spectralBandwidth,\n mfcc,\n chromagram,\n }\n}\n\n// --- Streaming (per-frame) API ---\n\nlet streamingModule: AudioFeaturesWasmModule | null = null\nlet streamingFramePtr = 0\nlet streamingFrameCapacity = 0\nlet streamingResultPtr = 0\n\n/**\n * Initialise the WASM streaming audio features processor.\n * Call once before computeAudioFeaturesFrameWasm().\n */\nexport async function initAudioFeaturesWasm(\n sampleRate: number,\n fftLength = 1024,\n nMfcc = 13,\n nMelFilters = 26,\n computeMfcc = true,\n computeChroma = true\n): Promise<void> {\n const Module = await getModule()\n streamingModule = Module\n\n Module._audio_features_init(\n sampleRate,\n fftLength,\n nMfcc,\n nMelFilters,\n computeMfcc ? 1 : 0,\n computeChroma ? 1 : 0\n )\n\n // Pre-allocate result struct on WASM heap\n if (streamingResultPtr) Module._free(streamingResultPtr)\n streamingResultPtr = Module._malloc(STRUCT_SIZE)\n // Zero-initialize to prevent freeing garbage pointers on first use\n Module.HEAPU8.fill(0, streamingResultPtr, streamingResultPtr + STRUCT_SIZE)\n\n // Frame input buffer allocated on demand\n streamingFrameCapacity = 0\n streamingFramePtr = 0\n}\n\n/**\n * Compute audio features for a single frame via WASM C++.\n * Returns null if not initialised or on error.\n */\nexport function computeAudioFeaturesFrameWasm(\n samples: Float32Array\n): AudioFeaturesWasmResult | null {\n if (!streamingModule || !streamingResultPtr) return null\n const Module = streamingModule\n\n // (Re-)allocate frame input buffer if needed\n if (samples.length > streamingFrameCapacity) {\n if (streamingFramePtr) Module._free(streamingFramePtr)\n streamingFramePtr = Module._malloc(samples.length * 4)\n streamingFrameCapacity = samples.length\n }\n\n // Copy samples to WASM heap\n Module.HEAPF32.set(samples, streamingFramePtr >> 2)\n\n const ok = Module._audio_features_compute_frame(\n streamingFramePtr,\n samples.length,\n streamingResultPtr\n )\n if (!ok) return null\n\n const result = readResult(Module, streamingResultPtr)\n\n // Free internal arrays (mfcc, chromagram) allocated by C\n Module._audio_features_free_arrays(streamingResultPtr)\n\n return result\n}\n\n// --- Batch API ---\n\n/**\n * Compute audio features for a buffer of samples via WASM C++.\n * Lazy-loads the WASM module on first call.\n */\nexport async function computeAudioFeaturesWasm(\n audioData: Float32Array,\n sampleRate: number,\n fftLength = 1024,\n nMfcc = 13,\n nMelFilters = 26,\n computeMfcc = true,\n computeChroma = true\n): Promise<AudioFeaturesWasmResult> {\n const Module = await getModule()\n\n const numSamples = audioData.length\n const inputPtr = Module._malloc(numSamples * 4)\n Module.HEAPF32.set(audioData, inputPtr >> 2)\n\n const resultPtr = Module._audio_features_compute(\n inputPtr,\n numSamples,\n sampleRate,\n fftLength,\n nMfcc,\n nMelFilters,\n computeMfcc ? 1 : 0,\n computeChroma ? 1 : 0\n )\n\n Module._free(inputPtr)\n\n if (resultPtr === 0) {\n throw new Error('audio_features_compute returned null')\n }\n\n const result = readResult(Module, resultPtr)\n Module._audio_features_free(resultPtr)\n\n return result\n}\n"]}
|
|
@@ -1,111 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// Dynamic import of the prebuilt SINGLE_FILE Emscripten module
|
|
6
|
-
// @ts-expect-error -- prebuilt Emscripten JS glue has no .d.ts
|
|
7
|
-
const mod = await import('../../prebuilt/wasm/mel-spectrogram.js');
|
|
8
|
-
const factory = mod.default ?? mod;
|
|
9
|
-
return factory();
|
|
10
|
-
})().catch((err) => {
|
|
11
|
-
modulePromise = null;
|
|
12
|
-
throw err;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return modulePromise;
|
|
1
|
+
// Native stub — WASM mel spectrogram is web-only.
|
|
2
|
+
// These functions are only called in web contexts; on native, the C++ TurboModule handles mel spectrograms.
|
|
3
|
+
export async function initMelStreamingWasm(_sampleRate, _nMels, _fftLength, _windowSizeSamples, _hopLengthSamples, _fMin, _fMax) {
|
|
4
|
+
throw new Error('WASM mel spectrogram is not available on native');
|
|
16
5
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let streamingNMels = 0;
|
|
20
|
-
let streamingFramePtr = 0;
|
|
21
|
-
let streamingMelPtr = 0;
|
|
22
|
-
let streamingFrameCapacity = 0;
|
|
23
|
-
/**
|
|
24
|
-
* Initialise the WASM streaming processor. Call once before computeMelFrame().
|
|
25
|
-
* Re-initialises only when config changes.
|
|
26
|
-
*/
|
|
27
|
-
export async function initMelStreamingWasm(sampleRate, nMels = 128, fftLength = 2048, windowSizeSamples = 400, hopLengthSamples = 160, fMin = 0, fMax = 0) {
|
|
28
|
-
const Module = await getModule();
|
|
29
|
-
streamingModule = Module;
|
|
30
|
-
const actualFMax = fMax > 0 ? fMax : sampleRate / 2;
|
|
31
|
-
Module._mel_spectrogram_init(sampleRate, fftLength, windowSizeSamples, hopLengthSamples, nMels, fMin, actualFMax, 0 /* hann */);
|
|
32
|
-
streamingNMels = nMels;
|
|
33
|
-
// Pre-allocate output buffer (fixed size)
|
|
34
|
-
if (streamingMelPtr)
|
|
35
|
-
Module._free(streamingMelPtr);
|
|
36
|
-
streamingMelPtr = Module._malloc(nMels * 4);
|
|
37
|
-
// Frame input buffer allocated on demand in computeMelFrame
|
|
38
|
-
streamingFrameCapacity = 0;
|
|
39
|
-
streamingFramePtr = 0;
|
|
6
|
+
export function computeMelFrameWasm(_samples) {
|
|
7
|
+
return null;
|
|
40
8
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* Returns null if not initialised or on error.
|
|
44
|
-
*/
|
|
45
|
-
export function computeMelFrameWasm(samples) {
|
|
46
|
-
if (!streamingModule || !streamingMelPtr)
|
|
47
|
-
return null;
|
|
48
|
-
const Module = streamingModule;
|
|
49
|
-
// (Re-)allocate frame input buffer if needed
|
|
50
|
-
if (samples.length > streamingFrameCapacity) {
|
|
51
|
-
if (streamingFramePtr)
|
|
52
|
-
Module._free(streamingFramePtr);
|
|
53
|
-
streamingFramePtr = Module._malloc(samples.length * 4);
|
|
54
|
-
streamingFrameCapacity = samples.length;
|
|
55
|
-
}
|
|
56
|
-
// Copy samples to WASM heap
|
|
57
|
-
Module.HEAPF32.set(samples, streamingFramePtr >> 2);
|
|
58
|
-
const ok = Module._mel_spectrogram_compute_frame(streamingFramePtr, samples.length, streamingMelPtr);
|
|
59
|
-
if (!ok)
|
|
60
|
-
return null;
|
|
61
|
-
// Read mel output from WASM heap
|
|
62
|
-
const offset = streamingMelPtr >> 2;
|
|
63
|
-
const result = new Array(streamingNMels);
|
|
64
|
-
for (let i = 0; i < streamingNMels; i++) {
|
|
65
|
-
result[i] = Module.HEAPF32[offset + i];
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Computes a mel spectrogram via the WASM-compiled C++ implementation.
|
|
71
|
-
* Lazy-loads the WASM module on first call.
|
|
72
|
-
*/
|
|
73
|
-
export async function computeMelSpectrogramWasm(audioData, sampleRate, nMels, windowSizeSamples, hopLengthSamples, fMin, fMax, windowType, normalize, logScale) {
|
|
74
|
-
const Module = await getModule();
|
|
75
|
-
const fftLength = 2048;
|
|
76
|
-
const windowTypeInt = windowType === 'hamming' ? 1 : 0;
|
|
77
|
-
// Allocate input buffer on WASM heap
|
|
78
|
-
const numSamples = audioData.length;
|
|
79
|
-
const inputPtr = Module._malloc(numSamples * 4); // 4 bytes per float
|
|
80
|
-
Module.HEAPF32.set(audioData, inputPtr >> 2);
|
|
81
|
-
// Call the C bridge
|
|
82
|
-
const resultPtr = Module._mel_spectrogram_compute(inputPtr, numSamples, sampleRate, fftLength, windowSizeSamples, hopLengthSamples, nMels, fMin, fMax, windowTypeInt, logScale ? 1 : 0, normalize ? 1 : 0);
|
|
83
|
-
// Free input buffer
|
|
84
|
-
Module._free(inputPtr);
|
|
85
|
-
if (resultPtr === 0) {
|
|
86
|
-
throw new Error('mel_spectrogram_compute returned null (too few samples?)');
|
|
87
|
-
}
|
|
88
|
-
// Read CMelSpectrogramResult struct (wasm32 pointers are 4 bytes)
|
|
89
|
-
// struct layout: { float* data (offset 0), int timeSteps (offset 4), int nMels (offset 8) }
|
|
90
|
-
const dataPtr = Module.getValue(resultPtr, 'i32');
|
|
91
|
-
const timeSteps = Module.getValue(resultPtr + 4, 'i32');
|
|
92
|
-
const resultNMels = Module.getValue(resultPtr + 8, 'i32');
|
|
93
|
-
if (!dataPtr || timeSteps <= 0 || resultNMels <= 0) {
|
|
94
|
-
Module._mel_spectrogram_free(resultPtr);
|
|
95
|
-
throw new Error('mel_spectrogram_compute returned invalid result struct');
|
|
96
|
-
}
|
|
97
|
-
// Copy spectrogram data to JS arrays
|
|
98
|
-
const spectrogram = [];
|
|
99
|
-
const heapOffset = dataPtr >> 2; // float32 offset into HEAPF32
|
|
100
|
-
for (let t = 0; t < timeSteps; t++) {
|
|
101
|
-
const row = new Array(resultNMels);
|
|
102
|
-
for (let m = 0; m < resultNMels; m++) {
|
|
103
|
-
row[m] = Module.HEAPF32[heapOffset + t * resultNMels + m];
|
|
104
|
-
}
|
|
105
|
-
spectrogram.push(row);
|
|
106
|
-
}
|
|
107
|
-
// Free the C result
|
|
108
|
-
Module._mel_spectrogram_free(resultPtr);
|
|
109
|
-
return spectrogram;
|
|
9
|
+
export async function computeMelSpectrogramWasm(_audioData, _sampleRate, _nMels, _windowSizeSamples, _hopLengthSamples, _fMin, _fMax, _windowType, _normalize, _logScale) {
|
|
10
|
+
throw new Error('WASM mel spectrogram is not available on native');
|
|
110
11
|
}
|
|
111
12
|
//# sourceMappingURL=melSpectrogramWasm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"melSpectrogramWasm.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/melSpectrogramWasm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"melSpectrogramWasm.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/melSpectrogramWasm.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,4GAA4G;AAE5G,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,WAAmB,EACnB,MAAe,EACf,UAAmB,EACnB,kBAA2B,EAC3B,iBAA0B,EAC1B,KAAc,EACd,KAAc;IAEd,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACtD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC3C,UAAwB,EACxB,WAAmB,EACnB,MAAc,EACd,kBAA0B,EAC1B,iBAAyB,EACzB,KAAa,EACb,KAAa,EACb,WAA+B,EAC/B,UAAmB,EACnB,SAAkB;IAElB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;AACtE,CAAC","sourcesContent":["// Native stub — WASM mel spectrogram is web-only.\n// These functions are only called in web contexts; on native, the C++ TurboModule handles mel spectrograms.\n\nexport async function initMelStreamingWasm(\n _sampleRate: number,\n _nMels?: number,\n _fftLength?: number,\n _windowSizeSamples?: number,\n _hopLengthSamples?: number,\n _fMin?: number,\n _fMax?: number\n): Promise<void> {\n throw new Error('WASM mel spectrogram is not available on native')\n}\n\nexport function computeMelFrameWasm(_samples: Float32Array): number[] | null {\n return null\n}\n\nexport async function computeMelSpectrogramWasm(\n _audioData: Float32Array,\n _sampleRate: number,\n _nMels: number,\n _windowSizeSamples: number,\n _hopLengthSamples: number,\n _fMin: number,\n _fMax: number,\n _windowType: 'hann' | 'hamming',\n _normalize: boolean,\n _logScale: boolean\n): Promise<number[][]> {\n throw new Error('WASM mel spectrogram is not available on native')\n}\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { getMelSpectrogramWasmUrl, _registerModuleReset } from './wasmConfig';
|
|
2
|
+
let modulePromise = null;
|
|
3
|
+
_registerModuleReset(() => {
|
|
4
|
+
modulePromise = null;
|
|
5
|
+
});
|
|
6
|
+
function getModule() {
|
|
7
|
+
if (!modulePromise) {
|
|
8
|
+
modulePromise = (async () => {
|
|
9
|
+
const url = getMelSpectrogramWasmUrl();
|
|
10
|
+
// webpackIgnore + @vite-ignore prevent bundlers from trying to resolve the URL
|
|
11
|
+
const mod = await import(/* webpackIgnore: true */ /* @vite-ignore */ url);
|
|
12
|
+
const factory = mod.default ?? mod;
|
|
13
|
+
return factory();
|
|
14
|
+
})().catch((err) => {
|
|
15
|
+
modulePromise = null;
|
|
16
|
+
throw err;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return modulePromise;
|
|
20
|
+
}
|
|
21
|
+
// --- Streaming (per-frame) API for live mel spectrogram ---
|
|
22
|
+
let streamingModule = null;
|
|
23
|
+
let streamingNMels = 0;
|
|
24
|
+
let streamingFramePtr = 0;
|
|
25
|
+
let streamingMelPtr = 0;
|
|
26
|
+
let streamingFrameCapacity = 0;
|
|
27
|
+
/**
|
|
28
|
+
* Initialise the WASM streaming processor. Call once before computeMelFrame().
|
|
29
|
+
* Re-initialises only when config changes.
|
|
30
|
+
*/
|
|
31
|
+
export async function initMelStreamingWasm(sampleRate, nMels = 128, fftLength = 2048, windowSizeSamples = 400, hopLengthSamples = 160, fMin = 0, fMax = 0) {
|
|
32
|
+
const Module = await getModule();
|
|
33
|
+
streamingModule = Module;
|
|
34
|
+
const actualFMax = fMax > 0 ? fMax : sampleRate / 2;
|
|
35
|
+
Module._mel_spectrogram_init(sampleRate, fftLength, windowSizeSamples, hopLengthSamples, nMels, fMin, actualFMax, 0 /* hann */);
|
|
36
|
+
streamingNMels = nMels;
|
|
37
|
+
// Pre-allocate output buffer (fixed size)
|
|
38
|
+
if (streamingMelPtr)
|
|
39
|
+
Module._free(streamingMelPtr);
|
|
40
|
+
streamingMelPtr = Module._malloc(nMels * 4);
|
|
41
|
+
// Frame input buffer allocated on demand in computeMelFrame
|
|
42
|
+
streamingFrameCapacity = 0;
|
|
43
|
+
streamingFramePtr = 0;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Compute a single mel spectrogram frame from raw PCM samples via WASM C++.
|
|
47
|
+
* Returns null if not initialised or on error.
|
|
48
|
+
*/
|
|
49
|
+
export function computeMelFrameWasm(samples) {
|
|
50
|
+
if (!streamingModule || !streamingMelPtr)
|
|
51
|
+
return null;
|
|
52
|
+
const Module = streamingModule;
|
|
53
|
+
// (Re-)allocate frame input buffer if needed
|
|
54
|
+
if (samples.length > streamingFrameCapacity) {
|
|
55
|
+
if (streamingFramePtr)
|
|
56
|
+
Module._free(streamingFramePtr);
|
|
57
|
+
streamingFramePtr = Module._malloc(samples.length * 4);
|
|
58
|
+
streamingFrameCapacity = samples.length;
|
|
59
|
+
}
|
|
60
|
+
// Copy samples to WASM heap
|
|
61
|
+
Module.HEAPF32.set(samples, streamingFramePtr >> 2);
|
|
62
|
+
const ok = Module._mel_spectrogram_compute_frame(streamingFramePtr, samples.length, streamingMelPtr);
|
|
63
|
+
if (!ok)
|
|
64
|
+
return null;
|
|
65
|
+
// Read mel output from WASM heap
|
|
66
|
+
const offset = streamingMelPtr >> 2;
|
|
67
|
+
const result = new Array(streamingNMels);
|
|
68
|
+
for (let i = 0; i < streamingNMels; i++) {
|
|
69
|
+
result[i] = Module.HEAPF32[offset + i];
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Computes a mel spectrogram via the WASM-compiled C++ implementation.
|
|
75
|
+
* Lazy-loads the WASM module on first call.
|
|
76
|
+
*/
|
|
77
|
+
export async function computeMelSpectrogramWasm(audioData, sampleRate, nMels, windowSizeSamples, hopLengthSamples, fMin, fMax, windowType, normalize, logScale) {
|
|
78
|
+
const Module = await getModule();
|
|
79
|
+
const fftLength = 2048;
|
|
80
|
+
const windowTypeInt = windowType === 'hamming' ? 1 : 0;
|
|
81
|
+
// Allocate input buffer on WASM heap
|
|
82
|
+
const numSamples = audioData.length;
|
|
83
|
+
const inputPtr = Module._malloc(numSamples * 4); // 4 bytes per float
|
|
84
|
+
Module.HEAPF32.set(audioData, inputPtr >> 2);
|
|
85
|
+
// Call the C bridge
|
|
86
|
+
const resultPtr = Module._mel_spectrogram_compute(inputPtr, numSamples, sampleRate, fftLength, windowSizeSamples, hopLengthSamples, nMels, fMin, fMax, windowTypeInt, logScale ? 1 : 0, normalize ? 1 : 0);
|
|
87
|
+
// Free input buffer
|
|
88
|
+
Module._free(inputPtr);
|
|
89
|
+
if (resultPtr === 0) {
|
|
90
|
+
throw new Error('mel_spectrogram_compute returned null (too few samples?)');
|
|
91
|
+
}
|
|
92
|
+
// Read CMelSpectrogramResult struct (wasm32 pointers are 4 bytes)
|
|
93
|
+
// struct layout: { float* data (offset 0), int timeSteps (offset 4), int nMels (offset 8) }
|
|
94
|
+
const dataPtr = Module.getValue(resultPtr, 'i32');
|
|
95
|
+
const timeSteps = Module.getValue(resultPtr + 4, 'i32');
|
|
96
|
+
const resultNMels = Module.getValue(resultPtr + 8, 'i32');
|
|
97
|
+
if (!dataPtr || timeSteps <= 0 || resultNMels <= 0) {
|
|
98
|
+
Module._mel_spectrogram_free(resultPtr);
|
|
99
|
+
throw new Error('mel_spectrogram_compute returned invalid result struct');
|
|
100
|
+
}
|
|
101
|
+
// Copy spectrogram data to JS arrays
|
|
102
|
+
const spectrogram = [];
|
|
103
|
+
const heapOffset = dataPtr >> 2; // float32 offset into HEAPF32
|
|
104
|
+
for (let t = 0; t < timeSteps; t++) {
|
|
105
|
+
const row = new Array(resultNMels);
|
|
106
|
+
for (let m = 0; m < resultNMels; m++) {
|
|
107
|
+
row[m] = Module.HEAPF32[heapOffset + t * resultNMels + m];
|
|
108
|
+
}
|
|
109
|
+
spectrogram.push(row);
|
|
110
|
+
}
|
|
111
|
+
// Free the C result
|
|
112
|
+
Module._mel_spectrogram_free(resultPtr);
|
|
113
|
+
return spectrogram;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=melSpectrogramWasm.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"melSpectrogramWasm.web.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/melSpectrogramWasm.web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAE7E,IAAI,aAAa,GAA6C,IAAI,CAAA;AAElE,oBAAoB,CAAC,GAAG,EAAE;IACtB,aAAa,GAAG,IAAI,CAAA;AACxB,CAAC,CAAC,CAAA;AAEF,SAAS,SAAS;IACd,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,aAAa,GAAG,CAAC,KAAK,IAAI,EAAE;YACxB,MAAM,GAAG,GAAG,wBAAwB,EAAE,CAAA;YACtC,+EAA+E;YAC/E,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAA;YAC1E,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAA;YAClC,OAAO,OAAO,EAAuC,CAAA;QACzD,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACf,aAAa,G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C,CAAA;QACvC,MAAM,IAAI,KAAK,CACX,wDAAwD,CAC3D,CAAA;IACL,CAAC;IAED,qCAAqC;IACrC,MAAM,WAAW,GAAe,EAAE,CAAA;IAClC,MAAM,UAAU,GAAG,OAAO,IAAI,CAAC,CAAA,CAAC,8BAA8B;IAC9D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,GAAG,CAAC,GAAG,WAAW,GAAG,CAAC,CAAC,CAAA;QAC7D,CAAC;QACD,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAED,oBAAoB;IACpB,MAAM,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAA;IAEvC,OAAO,WAAW,CAAA;AACtB,CAAC","sourcesContent":["import type { MelSpectrogramWasmModule } from './mel-spectrogram-wasm'\nimport { getMelSpectrogramWasmUrl, _registerModuleReset } from './wasmConfig'\n\nlet modulePromise: Promise<MelSpectrogramWasmModule> | null = null\n\n_registerModuleReset(() => {\n modulePromise = null\n})\n\nfunction getModule(): Promise<MelSpectrogramWasmModule> {\n if (!modulePromise) {\n modulePromise = (async () => {\n const url = getMelSpectrogramWasmUrl()\n // webpackIgnore + @vite-ignore prevent bundlers from trying to resolve the URL\n const mod = await import(/* webpackIgnore: true */ /* @vite-ignore */ url)\n const factory = mod.default ?? mod\n return factory() as Promise<MelSpectrogramWasmModule>\n })().catch((err) => {\n modulePromise = null\n throw err\n })\n }\n return modulePromise\n}\n\n// --- Streaming (per-frame) API for live mel spectrogram ---\n\nlet streamingModule: MelSpectrogramWasmModule | null = null\nlet streamingNMels = 0\nlet streamingFramePtr = 0\nlet streamingMelPtr = 0\nlet streamingFrameCapacity = 0\n\n/**\n * Initialise the WASM streaming processor. Call once before computeMelFrame().\n * Re-initialises only when config changes.\n */\nexport async function initMelStreamingWasm(\n sampleRate: number,\n nMels = 128,\n fftLength = 2048,\n windowSizeSamples = 400,\n hopLengthSamples = 160,\n fMin = 0,\n fMax = 0\n): Promise<void> {\n const Module = await getModule()\n streamingModule = Module\n const actualFMax = fMax > 0 ? fMax : sampleRate / 2\n Module._mel_spectrogram_init(\n sampleRate,\n fftLength,\n windowSizeSamples,\n hopLengthSamples,\n nMels,\n fMin,\n actualFMax,\n 0 /* hann */\n )\n streamingNMels = nMels\n\n // Pre-allocate output buffer (fixed size)\n if (streamingMelPtr) Module._free(streamingMelPtr)\n streamingMelPtr = Module._malloc(nMels * 4)\n\n // Frame input buffer allocated on demand in computeMelFrame\n streamingFrameCapacity = 0\n streamingFramePtr = 0\n}\n\n/**\n * Compute a single mel spectrogram frame from raw PCM samples via WASM C++.\n * Returns null if not initialised or on error.\n */\nexport function computeMelFrameWasm(samples: Float32Array): number[] | null {\n if (!streamingModule || !streamingMelPtr) return null\n const Module = streamingModule\n\n // (Re-)allocate frame input buffer if needed\n if (samples.length > streamingFrameCapacity) {\n if (streamingFramePtr) Module._free(streamingFramePtr)\n streamingFramePtr = Module._malloc(samples.length * 4)\n streamingFrameCapacity = samples.length\n }\n\n // Copy samples to WASM heap\n Module.HEAPF32.set(samples, streamingFramePtr >> 2)\n\n const ok = Module._mel_spectrogram_compute_frame(\n streamingFramePtr,\n samples.length,\n streamingMelPtr\n )\n if (!ok) return null\n\n // Read mel output from WASM heap\n const offset = streamingMelPtr >> 2\n const result = new Array(streamingNMels)\n for (let i = 0; i < streamingNMels; i++) {\n result[i] = Module.HEAPF32[offset + i]\n }\n return result\n}\n\n/**\n * Computes a mel spectrogram via the WASM-compiled C++ implementation.\n * Lazy-loads the WASM module on first call.\n */\nexport async function computeMelSpectrogramWasm(\n audioData: Float32Array,\n sampleRate: number,\n nMels: number,\n windowSizeSamples: number,\n hopLengthSamples: number,\n fMin: number,\n fMax: number,\n windowType: 'hann' | 'hamming',\n normalize: boolean,\n logScale: boolean\n): Promise<number[][]> {\n const Module = await getModule()\n\n const fftLength = 2048\n const windowTypeInt = windowType === 'hamming' ? 1 : 0\n\n // Allocate input buffer on WASM heap\n const numSamples = audioData.length\n const inputPtr = Module._malloc(numSamples * 4) // 4 bytes per float\n Module.HEAPF32.set(audioData, inputPtr >> 2)\n\n // Call the C bridge\n const resultPtr = Module._mel_spectrogram_compute(\n inputPtr,\n numSamples,\n sampleRate,\n fftLength,\n windowSizeSamples,\n hopLengthSamples,\n nMels,\n fMin,\n fMax,\n windowTypeInt,\n logScale ? 1 : 0,\n normalize ? 1 : 0\n )\n\n // Free input buffer\n Module._free(inputPtr)\n\n if (resultPtr === 0) {\n throw new Error(\n 'mel_spectrogram_compute returned null (too few samples?)'\n )\n }\n\n // Read CMelSpectrogramResult struct (wasm32 pointers are 4 bytes)\n // struct layout: { float* data (offset 0), int timeSteps (offset 4), int nMels (offset 8) }\n const dataPtr = Module.getValue(resultPtr, 'i32')\n const timeSteps = Module.getValue(resultPtr + 4, 'i32')\n const resultNMels = Module.getValue(resultPtr + 8, 'i32')\n\n if (!dataPtr || timeSteps <= 0 || resultNMels <= 0) {\n Module._mel_spectrogram_free(resultPtr)\n throw new Error(\n 'mel_spectrogram_compute returned invalid result struct'\n )\n }\n\n // Copy spectrogram data to JS arrays\n const spectrogram: number[][] = []\n const heapOffset = dataPtr >> 2 // float32 offset into HEAPF32\n for (let t = 0; t < timeSteps; t++) {\n const row = new Array(resultNMels)\n for (let m = 0; m < resultNMels; m++) {\n row[m] = Module.HEAPF32[heapOffset + t * resultNMels + m]\n }\n spectrogram.push(row)\n }\n\n // Free the C result\n Module._mel_spectrogram_free(resultPtr)\n\n return spectrogram\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Version is inlined here — keep in sync with package.json when releasing.
|
|
2
|
+
// The publish.sh script should bump this string alongside package.json.
|
|
3
|
+
const WASM_VERSION = '3.0.2';
|
|
4
|
+
// jsDelivr syncs from npm automatically within ~5 min of publish.
|
|
5
|
+
// GitHub release fallback (attach mel-spectrogram.js as a release asset):
|
|
6
|
+
// https://github.com/deeeed/audiolab/releases/download/@siteed/audio-studio@VERSION/mel-spectrogram.js
|
|
7
|
+
// To use the fallback: setMelSpectrogramWasmUrl('<url>') before any mel-spectrogram API call.
|
|
8
|
+
const DEFAULT_WASM_CDN = `https://cdn.jsdelivr.net/npm/@siteed/audio-studio@${WASM_VERSION}/prebuilt/wasm/mel-spectrogram.js`;
|
|
9
|
+
let _wasmUrl = DEFAULT_WASM_CDN;
|
|
10
|
+
let _modulePromiseReset = null;
|
|
11
|
+
export function _registerModuleReset(fn) {
|
|
12
|
+
_modulePromiseReset = fn;
|
|
13
|
+
}
|
|
14
|
+
export function setMelSpectrogramWasmUrl(url) {
|
|
15
|
+
_wasmUrl = url;
|
|
16
|
+
_modulePromiseReset?.(); // invalidate cached module so next call re-fetches
|
|
17
|
+
}
|
|
18
|
+
export function getMelSpectrogramWasmUrl() {
|
|
19
|
+
return _wasmUrl;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=wasmConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasmConfig.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/wasmConfig.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,wEAAwE;AACxE,MAAM,YAAY,GAAG,OAAO,CAAA;AAC5B,kEAAkE;AAClE,0EAA0E;AAC1E,yGAAyG;AACzG,8FAA8F;AAC9F,MAAM,gBAAgB,GAAG,qDAAqD,YAAY,mCAAmC,CAAA;AAE7H,IAAI,QAAQ,GAAW,gBAAgB,CAAA;AACvC,IAAI,mBAAmB,GAAwB,IAAI,CAAA;AAEnD,MAAM,UAAU,oBAAoB,CAAC,EAAc;IAC/C,mBAAmB,GAAG,EAAE,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,GAAW;IAChD,QAAQ,GAAG,GAAG,CAAA;IACd,mBAAmB,EAAE,EAAE,CAAA,CAAC,mDAAmD;AAC/E,CAAC;AAED,MAAM,UAAU,wBAAwB;IACpC,OAAO,QAAQ,CAAA;AACnB,CAAC","sourcesContent":["// Version is inlined here — keep in sync with package.json when releasing.\n// The publish.sh script should bump this string alongside package.json.\nconst WASM_VERSION = '3.0.2'\n// jsDelivr syncs from npm automatically within ~5 min of publish.\n// GitHub release fallback (attach mel-spectrogram.js as a release asset):\n// https://github.com/deeeed/audiolab/releases/download/@siteed/audio-studio@VERSION/mel-spectrogram.js\n// To use the fallback: setMelSpectrogramWasmUrl('<url>') before any mel-spectrogram API call.\nconst DEFAULT_WASM_CDN = `https://cdn.jsdelivr.net/npm/@siteed/audio-studio@${WASM_VERSION}/prebuilt/wasm/mel-spectrogram.js`\n\nlet _wasmUrl: string = DEFAULT_WASM_CDN\nlet _modulePromiseReset: (() => void) | null = null\n\nexport function _registerModuleReset(fn: () => void): void {\n _modulePromiseReset = fn\n}\n\nexport function setMelSpectrogramWasmUrl(url: string): void {\n _wasmUrl = url\n _modulePromiseReset?.() // invalidate cached module so next call re-fetches\n}\n\nexport function getMelSpectrogramWasmUrl(): string {\n return _wasmUrl\n}\n"]}
|
package/build/esm/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export { getPlatformCapabilities, isEncodingSupported, isBitDepthSupported, getF
|
|
|
17
17
|
export { AudioDeviceManager, audioDeviceManager } from './AudioDeviceManager';
|
|
18
18
|
// Export useAudioDevices hook
|
|
19
19
|
export { useAudioDevices } from './hooks/useAudioDevices';
|
|
20
|
+
export { setMelSpectrogramWasmUrl } from './AudioAnalysis/wasmConfig';
|
|
20
21
|
export { AudioRecorderProvider, AudioStudioModule, extractRawWavAnalysis, extractAudioAnalysis, extractPreview, trimAudio, extractAudioData, extractMelSpectrogram, initMelStreamingWasm, computeMelFrameWasm, MAX_DURATION_MS, useAudioRecorder, useSharedAudioRecorder, };
|
|
21
22
|
/** @deprecated Use AudioStudioModule instead */
|
|
22
23
|
export const ExpoAudioStreamModule = AudioStudioModule;
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AAEf,OAAO,EACH,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EACH,qBAAqB,EACrB,eAAe,GAClB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EACH,oBAAoB,EACpB,mBAAmB,GACtB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACH,qBAAqB,EACrB,sBAAsB,GACzB,MAAM,0BAA0B,CAAA;AACjC,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AAEtC,+BAA+B;AAC/B,OAAO,EACH,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GAE1B,MAAM,iCAAiC,CAAA;AAExC,4BAA4B;AAC5B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE7E,8BAA8B;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EACH,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,sBAAsB,GACzB,CAAA;AAMD,gDAAgD;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAA","sourcesContent":["// src/index.ts\n\nimport {\n extractRawWavAnalysis,\n extractAudioAnalysis,\n} from './AudioAnalysis/extractAudioAnalysis'\nimport { extractAudioData } from './AudioAnalysis/extractAudioData'\nimport {\n extractMelSpectrogram,\n MAX_DURATION_MS,\n} from './AudioAnalysis/extractMelSpectrogram'\nimport { extractPreview } from './AudioAnalysis/extractPreview'\nimport {\n initMelStreamingWasm,\n computeMelFrameWasm,\n} from './AudioAnalysis/melSpectrogramWasm'\nimport {\n AudioRecorderProvider,\n useSharedAudioRecorder,\n} from './AudioRecorder.provider'\nimport AudioStudioModule from './AudioStudioModule'\nimport { trimAudio } from './trimAudio'\nimport { useAudioRecorder } from './useAudioRecorder'\n\nexport * from './utils/convertPCMToFloat32'\nexport * from './utils/getWavFileInfo'\nexport * from './utils/writeWavHeader'\n\n// Export platform capabilities\nexport {\n getPlatformCapabilities,\n isEncodingSupported,\n isBitDepthSupported,\n getFallbackEncoding,\n getFallbackBitDepth,\n validateRecordingConfig,\n type PlatformCapabilities,\n} from './constants/platformLimitations'\n\n// Export AudioDeviceManager\nexport { AudioDeviceManager, audioDeviceManager } from './AudioDeviceManager'\n\n// Export useAudioDevices hook\nexport { useAudioDevices } from './hooks/useAudioDevices'\n\nexport {\n AudioRecorderProvider,\n AudioStudioModule,\n extractRawWavAnalysis,\n extractAudioAnalysis,\n extractPreview,\n trimAudio,\n extractAudioData,\n extractMelSpectrogram,\n initMelStreamingWasm,\n computeMelFrameWasm,\n MAX_DURATION_MS,\n useAudioRecorder,\n useSharedAudioRecorder,\n}\n\n// Export all types\nexport type * from './AudioAnalysis/AudioAnalysis.types'\nexport type * from './AudioStudio.types'\n\n/** @deprecated Use AudioStudioModule instead */\nexport const ExpoAudioStreamModule = AudioStudioModule\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AAEf,OAAO,EACH,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EACH,qBAAqB,EACrB,eAAe,GAClB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EACH,oBAAoB,EACpB,mBAAmB,GACtB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACH,qBAAqB,EACrB,sBAAsB,GACzB,MAAM,0BAA0B,CAAA;AACjC,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AAEtC,+BAA+B;AAC/B,OAAO,EACH,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GAE1B,MAAM,iCAAiC,CAAA;AAExC,4BAA4B;AAC5B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE7E,8BAA8B;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,OAAO,EACH,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,sBAAsB,GACzB,CAAA;AAMD,gDAAgD;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAA","sourcesContent":["// src/index.ts\n\nimport {\n extractRawWavAnalysis,\n extractAudioAnalysis,\n} from './AudioAnalysis/extractAudioAnalysis'\nimport { extractAudioData } from './AudioAnalysis/extractAudioData'\nimport {\n extractMelSpectrogram,\n MAX_DURATION_MS,\n} from './AudioAnalysis/extractMelSpectrogram'\nimport { extractPreview } from './AudioAnalysis/extractPreview'\nimport {\n initMelStreamingWasm,\n computeMelFrameWasm,\n} from './AudioAnalysis/melSpectrogramWasm'\nimport {\n AudioRecorderProvider,\n useSharedAudioRecorder,\n} from './AudioRecorder.provider'\nimport AudioStudioModule from './AudioStudioModule'\nimport { trimAudio } from './trimAudio'\nimport { useAudioRecorder } from './useAudioRecorder'\n\nexport * from './utils/convertPCMToFloat32'\nexport * from './utils/getWavFileInfo'\nexport * from './utils/writeWavHeader'\n\n// Export platform capabilities\nexport {\n getPlatformCapabilities,\n isEncodingSupported,\n isBitDepthSupported,\n getFallbackEncoding,\n getFallbackBitDepth,\n validateRecordingConfig,\n type PlatformCapabilities,\n} from './constants/platformLimitations'\n\n// Export AudioDeviceManager\nexport { AudioDeviceManager, audioDeviceManager } from './AudioDeviceManager'\n\n// Export useAudioDevices hook\nexport { useAudioDevices } from './hooks/useAudioDevices'\n\nexport { setMelSpectrogramWasmUrl } from './AudioAnalysis/wasmConfig'\n\nexport {\n AudioRecorderProvider,\n AudioStudioModule,\n extractRawWavAnalysis,\n extractAudioAnalysis,\n extractPreview,\n trimAudio,\n extractAudioData,\n extractMelSpectrogram,\n initMelStreamingWasm,\n computeMelFrameWasm,\n MAX_DURATION_MS,\n useAudioRecorder,\n useSharedAudioRecorder,\n}\n\n// Export all types\nexport type * from './AudioAnalysis/AudioAnalysis.types'\nexport type * from './AudioStudio.types'\n\n/** @deprecated Use AudioStudioModule instead */\nexport const ExpoAudioStreamModule = AudioStudioModule\n"]}
|