@libraz/libsonare 1.5.2 → 1.5.4
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 +69 -725
- package/dist/index.d.ts +1155 -183
- package/dist/index.js +4924 -3935
- package/dist/index.js.map +1 -1
- package/dist/sonare.js +1 -1
- package/dist/sonare.wasm +0 -0
- package/dist/worklet.d.ts +29 -1
- package/dist/worklet.js +1141 -970
- package/dist/worklet.js.map +1 -1
- package/package.json +15 -3
- package/src/_chain_config.ts +46 -0
- package/src/audio.ts +24 -4
- package/src/codes.ts +27 -4
- package/src/effects_mastering.ts +25 -1
- package/src/effects_transform.ts +292 -46
- package/src/effects_voice_change.ts +46 -53
- package/src/feature_core.ts +316 -12
- package/src/feature_music.ts +371 -4
- package/src/feature_pitch.ts +61 -0
- package/src/feature_resample.ts +17 -2
- package/src/feature_spectral.ts +349 -2
- package/src/feature_spectrogram.ts +336 -0
- package/src/index.ts +130 -1
- package/src/mastering_chain.ts +305 -50
- package/src/mastering_core.ts +232 -16
- package/src/mastering_dynamics.ts +66 -10
- package/src/mastering_repair.ts +119 -7
- package/src/metering.ts +370 -83
- package/src/mixer.ts +9 -2
- package/src/mixing_oneshot.ts +25 -5
- package/src/module_state.ts +1 -1
- package/src/project_class.ts +30 -6
- package/src/project_internal.ts +12 -2
- package/src/project_types.ts +25 -2
- package/src/public_types_mastering.ts +114 -4
- package/src/public_types_spectral.ts +7 -0
- package/src/quick_analysis.ts +325 -117
- package/src/realtime_engine.ts +8 -0
- package/src/realtime_voice_changer.ts +79 -3
- package/src/sonare.js.d.ts +35 -0
- package/src/stream_analyzer.ts +20 -1
- package/src/stream_types.ts +12 -1
- package/src/validation.ts +17 -2
- package/src/worklet/engine-clips.ts +67 -2
- package/src/worklet/engine-processor.ts +33 -5
- package/src/worklet/engine.ts +7 -3
- package/src/worklet/guards.ts +3 -0
- package/src/worklet/messages.ts +27 -0
|
@@ -21,6 +21,75 @@ function requireModule() {
|
|
|
21
21
|
|
|
22
22
|
type GuardedOptions = ValidateOptions;
|
|
23
23
|
|
|
24
|
+
/** Canonical request form for basic frame-based spectrogram features. */
|
|
25
|
+
export interface SpectrogramRequest extends GuardedOptions {
|
|
26
|
+
samples: Float32Array;
|
|
27
|
+
sampleRate?: number;
|
|
28
|
+
nFft?: number;
|
|
29
|
+
hopLength?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ChromaSpectrogramRequest extends GuardedOptions {
|
|
33
|
+
samples: Float32Array;
|
|
34
|
+
sampleRate?: number;
|
|
35
|
+
hopLength?: number;
|
|
36
|
+
nChroma?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface MelSpectrogramRequest extends SpectrogramRequest {
|
|
40
|
+
nMels?: number;
|
|
41
|
+
fmin?: number;
|
|
42
|
+
fmax?: number;
|
|
43
|
+
htk?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface MfccRequest extends MelSpectrogramRequest {
|
|
47
|
+
nMfcc?: number;
|
|
48
|
+
lifter?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface MfccToMelRequest extends GuardedOptions {
|
|
52
|
+
mfccCoefficients: Float32Array;
|
|
53
|
+
nMfcc: number;
|
|
54
|
+
nFrames: number;
|
|
55
|
+
nMels?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Canonical request form for reconstruction from a Mel power spectrogram. */
|
|
59
|
+
export interface MelToStftRequest extends GuardedOptions {
|
|
60
|
+
melPower: Float32Array;
|
|
61
|
+
nMels: number;
|
|
62
|
+
nFrames: number;
|
|
63
|
+
sampleRate?: number;
|
|
64
|
+
nFft?: number;
|
|
65
|
+
fmin?: number;
|
|
66
|
+
fmax?: number;
|
|
67
|
+
htk?: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Canonical request form for Griffin-Lim reconstruction from Mel power. */
|
|
71
|
+
export interface MelToAudioRequest extends MelToStftRequest {
|
|
72
|
+
hopLength?: number;
|
|
73
|
+
nIter?: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Canonical request form for Griffin-Lim reconstruction from MFCCs. */
|
|
77
|
+
export interface MfccToAudioRequest extends MfccToMelRequest {
|
|
78
|
+
sampleRate?: number;
|
|
79
|
+
nFft?: number;
|
|
80
|
+
hopLength?: number;
|
|
81
|
+
fmin?: number;
|
|
82
|
+
fmax?: number;
|
|
83
|
+
nIter?: number;
|
|
84
|
+
htk?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface TrimRequest extends GuardedOptions {
|
|
88
|
+
samples: Float32Array;
|
|
89
|
+
sampleRate: number;
|
|
90
|
+
thresholdDb?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
24
93
|
function validateSpectrogramSamples(
|
|
25
94
|
fnName: string,
|
|
26
95
|
samples: Float32Array,
|
|
@@ -82,12 +151,23 @@ function validateMatrix(
|
|
|
82
151
|
* @param thresholdDb - Silence threshold in dB (default: -60 dB)
|
|
83
152
|
* @returns Trimmed audio
|
|
84
153
|
*/
|
|
154
|
+
export function trim(request: TrimRequest): Float32Array;
|
|
85
155
|
export function trim(
|
|
86
156
|
samples: Float32Array,
|
|
87
157
|
sampleRate: number,
|
|
158
|
+
thresholdDb?: number,
|
|
159
|
+
options?: GuardedOptions,
|
|
160
|
+
): Float32Array;
|
|
161
|
+
export function trim(
|
|
162
|
+
samples: Float32Array | TrimRequest,
|
|
163
|
+
sampleRate = 22050,
|
|
88
164
|
thresholdDb = -60.0,
|
|
89
165
|
options: GuardedOptions = {},
|
|
90
166
|
): Float32Array {
|
|
167
|
+
if (!(samples instanceof Float32Array)) {
|
|
168
|
+
const r = samples;
|
|
169
|
+
return trim(r.samples, r.sampleRate, r.thresholdDb, r);
|
|
170
|
+
}
|
|
91
171
|
validateSpectrogramSamples('trim', samples, sampleRate, options);
|
|
92
172
|
assertFiniteScalar('trim', thresholdDb, 'thresholdDb');
|
|
93
173
|
return requireModule().trim(samples, sampleRate, thresholdDb);
|
|
@@ -106,13 +186,25 @@ export function trim(
|
|
|
106
186
|
* @param hopLength - Hop length (default: 512)
|
|
107
187
|
* @returns STFT result with magnitude and power spectrograms
|
|
108
188
|
*/
|
|
189
|
+
export function stft(request: SpectrogramRequest): StftResult;
|
|
109
190
|
export function stft(
|
|
110
191
|
samples: Float32Array,
|
|
192
|
+
sampleRate?: number,
|
|
193
|
+
nFft?: number,
|
|
194
|
+
hopLength?: number,
|
|
195
|
+
options?: GuardedOptions,
|
|
196
|
+
): StftResult;
|
|
197
|
+
export function stft(
|
|
198
|
+
samples: Float32Array | SpectrogramRequest,
|
|
111
199
|
sampleRate = 22050,
|
|
112
200
|
nFft = 2048,
|
|
113
201
|
hopLength = 512,
|
|
114
202
|
options: GuardedOptions = {},
|
|
115
203
|
): StftResult {
|
|
204
|
+
if (!(samples instanceof Float32Array)) {
|
|
205
|
+
const request = samples;
|
|
206
|
+
return stft(request.samples, request.sampleRate, request.nFft, request.hopLength, request);
|
|
207
|
+
}
|
|
116
208
|
validateSpectrogramSamples('stft', samples, sampleRate, options);
|
|
117
209
|
validatePositiveIntegers('stft', { nFft, hopLength });
|
|
118
210
|
return requireModule().stft(samples, sampleRate, nFft, hopLength);
|
|
@@ -127,13 +219,29 @@ export function stft(
|
|
|
127
219
|
* @param hopLength - Hop length (default: 512)
|
|
128
220
|
* @returns STFT result with dB values
|
|
129
221
|
*/
|
|
222
|
+
export function stftDb(request: SpectrogramRequest): {
|
|
223
|
+
nBins: number;
|
|
224
|
+
nFrames: number;
|
|
225
|
+
db: Float32Array;
|
|
226
|
+
};
|
|
130
227
|
export function stftDb(
|
|
131
228
|
samples: Float32Array,
|
|
229
|
+
sampleRate?: number,
|
|
230
|
+
nFft?: number,
|
|
231
|
+
hopLength?: number,
|
|
232
|
+
options?: GuardedOptions,
|
|
233
|
+
): { nBins: number; nFrames: number; db: Float32Array };
|
|
234
|
+
export function stftDb(
|
|
235
|
+
samples: Float32Array | SpectrogramRequest,
|
|
132
236
|
sampleRate = 22050,
|
|
133
237
|
nFft = 2048,
|
|
134
238
|
hopLength = 512,
|
|
135
239
|
options: GuardedOptions = {},
|
|
136
240
|
): { nBins: number; nFrames: number; db: Float32Array } {
|
|
241
|
+
if (!(samples instanceof Float32Array)) {
|
|
242
|
+
const request = samples;
|
|
243
|
+
return stftDb(request.samples, request.sampleRate, request.nFft, request.hopLength, request);
|
|
244
|
+
}
|
|
137
245
|
validateSpectrogramSamples('stftDb', samples, sampleRate, options);
|
|
138
246
|
validatePositiveIntegers('stftDb', { nFft, hopLength });
|
|
139
247
|
return requireModule().stftDb(samples, sampleRate, nFft, hopLength);
|
|
@@ -148,13 +256,31 @@ export function stftDb(
|
|
|
148
256
|
* @param nChroma - Number of chroma bins (default: 12)
|
|
149
257
|
* @returns Chroma result
|
|
150
258
|
*/
|
|
259
|
+
export function chromaCens(request: ChromaSpectrogramRequest): ChromaResult;
|
|
151
260
|
export function chromaCens(
|
|
152
261
|
samples: Float32Array,
|
|
262
|
+
sampleRate?: number,
|
|
263
|
+
hopLength?: number,
|
|
264
|
+
nChroma?: number,
|
|
265
|
+
options?: GuardedOptions,
|
|
266
|
+
): ChromaResult;
|
|
267
|
+
export function chromaCens(
|
|
268
|
+
samples: Float32Array | ChromaSpectrogramRequest,
|
|
153
269
|
sampleRate = 22050,
|
|
154
270
|
hopLength = 512,
|
|
155
271
|
nChroma = 12,
|
|
156
272
|
options: GuardedOptions = {},
|
|
157
273
|
): ChromaResult {
|
|
274
|
+
if (!(samples instanceof Float32Array)) {
|
|
275
|
+
const request = samples;
|
|
276
|
+
return chromaCens(
|
|
277
|
+
request.samples,
|
|
278
|
+
request.sampleRate,
|
|
279
|
+
request.hopLength,
|
|
280
|
+
request.nChroma,
|
|
281
|
+
request,
|
|
282
|
+
);
|
|
283
|
+
}
|
|
158
284
|
validateSpectrogramSamples('chromaCens', samples, sampleRate, options);
|
|
159
285
|
validatePositiveIntegers('chromaCens', { hopLength, nChroma });
|
|
160
286
|
return requireModule().chromaCens(samples, sampleRate, hopLength, nChroma);
|
|
@@ -169,13 +295,31 @@ export function chromaCens(
|
|
|
169
295
|
* @param nChroma - Number of chroma bins (default: 12)
|
|
170
296
|
* @returns Chroma result
|
|
171
297
|
*/
|
|
298
|
+
export function chromaCqt(request: ChromaSpectrogramRequest): ChromaResult;
|
|
172
299
|
export function chromaCqt(
|
|
173
300
|
samples: Float32Array,
|
|
301
|
+
sampleRate?: number,
|
|
302
|
+
hopLength?: number,
|
|
303
|
+
nChroma?: number,
|
|
304
|
+
options?: GuardedOptions,
|
|
305
|
+
): ChromaResult;
|
|
306
|
+
export function chromaCqt(
|
|
307
|
+
samples: Float32Array | ChromaSpectrogramRequest,
|
|
174
308
|
sampleRate = 22050,
|
|
175
309
|
hopLength = 512,
|
|
176
310
|
nChroma = 12,
|
|
177
311
|
options: GuardedOptions = {},
|
|
178
312
|
): ChromaResult {
|
|
313
|
+
if (!(samples instanceof Float32Array)) {
|
|
314
|
+
const request = samples;
|
|
315
|
+
return chromaCqt(
|
|
316
|
+
request.samples,
|
|
317
|
+
request.sampleRate,
|
|
318
|
+
request.hopLength,
|
|
319
|
+
request.nChroma,
|
|
320
|
+
request,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
179
323
|
validateSpectrogramSamples('chromaCqt', samples, sampleRate, options);
|
|
180
324
|
validatePositiveIntegers('chromaCqt', { hopLength, nChroma });
|
|
181
325
|
return requireModule().chromaCqt(samples, sampleRate, hopLength, nChroma);
|
|
@@ -190,13 +334,31 @@ export function chromaCqt(
|
|
|
190
334
|
* @param nChroma - Number of chroma bins (default: 12)
|
|
191
335
|
* @returns Chroma result
|
|
192
336
|
*/
|
|
337
|
+
export function bassChroma(request: ChromaSpectrogramRequest): ChromaResult;
|
|
193
338
|
export function bassChroma(
|
|
194
339
|
samples: Float32Array,
|
|
340
|
+
sampleRate?: number,
|
|
341
|
+
hopLength?: number,
|
|
342
|
+
nChroma?: number,
|
|
343
|
+
options?: GuardedOptions,
|
|
344
|
+
): ChromaResult;
|
|
345
|
+
export function bassChroma(
|
|
346
|
+
samples: Float32Array | ChromaSpectrogramRequest,
|
|
195
347
|
sampleRate = 22050,
|
|
196
348
|
hopLength = 512,
|
|
197
349
|
nChroma = 12,
|
|
198
350
|
options: GuardedOptions = {},
|
|
199
351
|
): ChromaResult {
|
|
352
|
+
if (!(samples instanceof Float32Array)) {
|
|
353
|
+
const request = samples;
|
|
354
|
+
return bassChroma(
|
|
355
|
+
request.samples,
|
|
356
|
+
request.sampleRate,
|
|
357
|
+
request.hopLength,
|
|
358
|
+
request.nChroma,
|
|
359
|
+
request,
|
|
360
|
+
);
|
|
361
|
+
}
|
|
200
362
|
validateSpectrogramSamples('bassChroma', samples, sampleRate, options);
|
|
201
363
|
validatePositiveIntegers('bassChroma', { hopLength, nChroma });
|
|
202
364
|
return requireModule().bassChroma(samples, sampleRate, hopLength, nChroma);
|
|
@@ -220,8 +382,20 @@ export function bassChroma(
|
|
|
220
382
|
* @param htk - Use the HTK Mel formula instead of Slaney (default: false)
|
|
221
383
|
* @returns Mel spectrogram result
|
|
222
384
|
*/
|
|
385
|
+
export function melSpectrogram(request: MelSpectrogramRequest): MelSpectrogramResult;
|
|
223
386
|
export function melSpectrogram(
|
|
224
387
|
samples: Float32Array,
|
|
388
|
+
sampleRate?: number,
|
|
389
|
+
nFft?: number,
|
|
390
|
+
hopLength?: number,
|
|
391
|
+
nMels?: number,
|
|
392
|
+
fmin?: number,
|
|
393
|
+
fmax?: number,
|
|
394
|
+
htk?: boolean,
|
|
395
|
+
options?: GuardedOptions,
|
|
396
|
+
): MelSpectrogramResult;
|
|
397
|
+
export function melSpectrogram(
|
|
398
|
+
samples: Float32Array | MelSpectrogramRequest,
|
|
225
399
|
sampleRate = 22050,
|
|
226
400
|
nFft = 2048,
|
|
227
401
|
hopLength = 512,
|
|
@@ -231,6 +405,20 @@ export function melSpectrogram(
|
|
|
231
405
|
htk = false,
|
|
232
406
|
options: GuardedOptions = {},
|
|
233
407
|
): MelSpectrogramResult {
|
|
408
|
+
if (!(samples instanceof Float32Array)) {
|
|
409
|
+
const request = samples;
|
|
410
|
+
return melSpectrogram(
|
|
411
|
+
request.samples,
|
|
412
|
+
request.sampleRate,
|
|
413
|
+
request.nFft,
|
|
414
|
+
request.hopLength,
|
|
415
|
+
request.nMels,
|
|
416
|
+
request.fmin,
|
|
417
|
+
request.fmax,
|
|
418
|
+
request.htk,
|
|
419
|
+
request,
|
|
420
|
+
);
|
|
421
|
+
}
|
|
234
422
|
validateSpectrogramSamples('melSpectrogram', samples, sampleRate, options);
|
|
235
423
|
validatePositiveIntegers('melSpectrogram', { nFft, hopLength, nMels });
|
|
236
424
|
validateMelFrequencyRange('melSpectrogram', fmin, fmax, sampleRate);
|
|
@@ -261,8 +449,22 @@ export function melSpectrogram(
|
|
|
261
449
|
* @param lifter - Cepstral liftering coefficient (default: 0 = no liftering)
|
|
262
450
|
* @returns MFCC result
|
|
263
451
|
*/
|
|
452
|
+
export function mfcc(request: MfccRequest): MfccResult;
|
|
264
453
|
export function mfcc(
|
|
265
454
|
samples: Float32Array,
|
|
455
|
+
sampleRate?: number,
|
|
456
|
+
nFft?: number,
|
|
457
|
+
hopLength?: number,
|
|
458
|
+
nMels?: number,
|
|
459
|
+
nMfcc?: number,
|
|
460
|
+
fmin?: number,
|
|
461
|
+
fmax?: number,
|
|
462
|
+
htk?: boolean,
|
|
463
|
+
lifter?: number,
|
|
464
|
+
options?: GuardedOptions,
|
|
465
|
+
): MfccResult;
|
|
466
|
+
export function mfcc(
|
|
467
|
+
samples: Float32Array | MfccRequest,
|
|
266
468
|
sampleRate = 22050,
|
|
267
469
|
nFft = 2048,
|
|
268
470
|
hopLength = 512,
|
|
@@ -274,6 +476,22 @@ export function mfcc(
|
|
|
274
476
|
lifter = 0,
|
|
275
477
|
options: GuardedOptions = {},
|
|
276
478
|
): MfccResult {
|
|
479
|
+
if (!(samples instanceof Float32Array)) {
|
|
480
|
+
const request = samples;
|
|
481
|
+
return mfcc(
|
|
482
|
+
request.samples,
|
|
483
|
+
request.sampleRate,
|
|
484
|
+
request.nFft,
|
|
485
|
+
request.hopLength,
|
|
486
|
+
request.nMels,
|
|
487
|
+
request.nMfcc,
|
|
488
|
+
request.fmin,
|
|
489
|
+
request.fmax,
|
|
490
|
+
request.htk,
|
|
491
|
+
request.lifter,
|
|
492
|
+
request,
|
|
493
|
+
);
|
|
494
|
+
}
|
|
277
495
|
validateSpectrogramSamples('mfcc', samples, sampleRate, options);
|
|
278
496
|
validatePositiveIntegers('mfcc', { nFft, hopLength, nMels, nMfcc });
|
|
279
497
|
validateMelFrequencyRange('mfcc', fmin, fmax, sampleRate);
|
|
@@ -309,10 +527,22 @@ export function mfcc(
|
|
|
309
527
|
* @param htk - Use the HTK Mel formula instead of Slaney (default: false)
|
|
310
528
|
* @returns STFT power spectrogram result
|
|
311
529
|
*/
|
|
530
|
+
export function melToStft(request: MelToStftRequest): StftPowerResult;
|
|
312
531
|
export function melToStft(
|
|
313
532
|
melPower: Float32Array,
|
|
314
533
|
nMels: number,
|
|
315
534
|
nFrames: number,
|
|
535
|
+
sampleRate?: number,
|
|
536
|
+
nFft?: number,
|
|
537
|
+
fmin?: number,
|
|
538
|
+
fmax?: number,
|
|
539
|
+
htk?: boolean,
|
|
540
|
+
options?: GuardedOptions,
|
|
541
|
+
): StftPowerResult;
|
|
542
|
+
export function melToStft(
|
|
543
|
+
melPower: Float32Array | MelToStftRequest,
|
|
544
|
+
nMels = 0,
|
|
545
|
+
nFrames = 0,
|
|
316
546
|
sampleRate = 22050,
|
|
317
547
|
nFft = 2048,
|
|
318
548
|
fmin = 0,
|
|
@@ -320,6 +550,20 @@ export function melToStft(
|
|
|
320
550
|
htk = false,
|
|
321
551
|
options: GuardedOptions = {},
|
|
322
552
|
): StftPowerResult {
|
|
553
|
+
if (!(melPower instanceof Float32Array)) {
|
|
554
|
+
const request = melPower;
|
|
555
|
+
return melToStft(
|
|
556
|
+
request.melPower,
|
|
557
|
+
request.nMels,
|
|
558
|
+
request.nFrames,
|
|
559
|
+
request.sampleRate,
|
|
560
|
+
request.nFft,
|
|
561
|
+
request.fmin,
|
|
562
|
+
request.fmax,
|
|
563
|
+
request.htk,
|
|
564
|
+
request,
|
|
565
|
+
);
|
|
566
|
+
}
|
|
323
567
|
assertSampleRate('melToStft', sampleRate);
|
|
324
568
|
validateMatrix('melToStft', melPower, nMels, nFrames, 'melPower', 'nMels', options);
|
|
325
569
|
validatePositiveIntegers('melToStft', { nFft });
|
|
@@ -343,10 +587,24 @@ export function melToStft(
|
|
|
343
587
|
* @param htk - Use the HTK Mel formula instead of Slaney (default: false)
|
|
344
588
|
* @returns Reconstructed audio samples (mono, float32)
|
|
345
589
|
*/
|
|
590
|
+
export function melToAudio(request: MelToAudioRequest): Float32Array;
|
|
346
591
|
export function melToAudio(
|
|
347
592
|
melPower: Float32Array,
|
|
348
593
|
nMels: number,
|
|
349
594
|
nFrames: number,
|
|
595
|
+
sampleRate?: number,
|
|
596
|
+
nFft?: number,
|
|
597
|
+
hopLength?: number,
|
|
598
|
+
fmin?: number,
|
|
599
|
+
fmax?: number,
|
|
600
|
+
nIter?: number,
|
|
601
|
+
htk?: boolean,
|
|
602
|
+
options?: GuardedOptions,
|
|
603
|
+
): Float32Array;
|
|
604
|
+
export function melToAudio(
|
|
605
|
+
melPower: Float32Array | MelToAudioRequest,
|
|
606
|
+
nMels = 0,
|
|
607
|
+
nFrames = 0,
|
|
350
608
|
sampleRate = 22050,
|
|
351
609
|
nFft = 2048,
|
|
352
610
|
hopLength = 512,
|
|
@@ -356,6 +614,22 @@ export function melToAudio(
|
|
|
356
614
|
htk = false,
|
|
357
615
|
options: GuardedOptions = {},
|
|
358
616
|
): Float32Array {
|
|
617
|
+
if (!(melPower instanceof Float32Array)) {
|
|
618
|
+
const request = melPower;
|
|
619
|
+
return melToAudio(
|
|
620
|
+
request.melPower,
|
|
621
|
+
request.nMels,
|
|
622
|
+
request.nFrames,
|
|
623
|
+
request.sampleRate,
|
|
624
|
+
request.nFft,
|
|
625
|
+
request.hopLength,
|
|
626
|
+
request.fmin,
|
|
627
|
+
request.fmax,
|
|
628
|
+
request.nIter,
|
|
629
|
+
request.htk,
|
|
630
|
+
request,
|
|
631
|
+
);
|
|
632
|
+
}
|
|
359
633
|
assertSampleRate('melToAudio', sampleRate);
|
|
360
634
|
validateMatrix('melToAudio', melPower, nMels, nFrames, 'melPower', 'nMels', options);
|
|
361
635
|
validatePositiveIntegers('melToAudio', { nFft, hopLength, nIter });
|
|
@@ -384,13 +658,31 @@ export function melToAudio(
|
|
|
384
658
|
* @param nMels - Number of Mel bins to reconstruct (default: 128)
|
|
385
659
|
* @returns Mel power spectrogram result
|
|
386
660
|
*/
|
|
661
|
+
export function mfccToMel(request: MfccToMelRequest): MelPowerResult;
|
|
387
662
|
export function mfccToMel(
|
|
388
663
|
mfccCoefficients: Float32Array,
|
|
389
664
|
nMfcc: number,
|
|
390
665
|
nFrames: number,
|
|
666
|
+
nMels?: number,
|
|
667
|
+
options?: GuardedOptions,
|
|
668
|
+
): MelPowerResult;
|
|
669
|
+
export function mfccToMel(
|
|
670
|
+
mfccCoefficients: Float32Array | MfccToMelRequest,
|
|
671
|
+
nMfcc = 0,
|
|
672
|
+
nFrames = 0,
|
|
391
673
|
nMels = 128,
|
|
392
674
|
options: GuardedOptions = {},
|
|
393
675
|
): MelPowerResult {
|
|
676
|
+
if (!(mfccCoefficients instanceof Float32Array)) {
|
|
677
|
+
const request = mfccCoefficients;
|
|
678
|
+
return mfccToMel(
|
|
679
|
+
request.mfccCoefficients,
|
|
680
|
+
request.nMfcc,
|
|
681
|
+
request.nFrames,
|
|
682
|
+
request.nMels,
|
|
683
|
+
request,
|
|
684
|
+
);
|
|
685
|
+
}
|
|
394
686
|
validateMatrix(
|
|
395
687
|
'mfccToMel',
|
|
396
688
|
mfccCoefficients,
|
|
@@ -421,10 +713,25 @@ export function mfccToMel(
|
|
|
421
713
|
* @param htk - Use the HTK Mel formula instead of Slaney (default: false)
|
|
422
714
|
* @returns Reconstructed audio samples (mono, float32)
|
|
423
715
|
*/
|
|
716
|
+
export function mfccToAudio(request: MfccToAudioRequest): Float32Array;
|
|
424
717
|
export function mfccToAudio(
|
|
425
718
|
mfccCoefficients: Float32Array,
|
|
426
719
|
nMfcc: number,
|
|
427
720
|
nFrames: number,
|
|
721
|
+
nMels?: number,
|
|
722
|
+
sampleRate?: number,
|
|
723
|
+
nFft?: number,
|
|
724
|
+
hopLength?: number,
|
|
725
|
+
fmin?: number,
|
|
726
|
+
fmax?: number,
|
|
727
|
+
nIter?: number,
|
|
728
|
+
htk?: boolean,
|
|
729
|
+
options?: GuardedOptions,
|
|
730
|
+
): Float32Array;
|
|
731
|
+
export function mfccToAudio(
|
|
732
|
+
mfccCoefficients: Float32Array | MfccToAudioRequest,
|
|
733
|
+
nMfcc = 0,
|
|
734
|
+
nFrames = 0,
|
|
428
735
|
nMels = 128,
|
|
429
736
|
sampleRate = 22050,
|
|
430
737
|
nFft = 2048,
|
|
@@ -435,6 +742,23 @@ export function mfccToAudio(
|
|
|
435
742
|
htk = false,
|
|
436
743
|
options: GuardedOptions = {},
|
|
437
744
|
): Float32Array {
|
|
745
|
+
if (!(mfccCoefficients instanceof Float32Array)) {
|
|
746
|
+
const request = mfccCoefficients;
|
|
747
|
+
return mfccToAudio(
|
|
748
|
+
request.mfccCoefficients,
|
|
749
|
+
request.nMfcc,
|
|
750
|
+
request.nFrames,
|
|
751
|
+
request.nMels,
|
|
752
|
+
request.sampleRate,
|
|
753
|
+
request.nFft,
|
|
754
|
+
request.hopLength,
|
|
755
|
+
request.fmin,
|
|
756
|
+
request.fmax,
|
|
757
|
+
request.nIter,
|
|
758
|
+
request.htk,
|
|
759
|
+
request,
|
|
760
|
+
);
|
|
761
|
+
}
|
|
438
762
|
assertSampleRate('mfccToAudio', sampleRate);
|
|
439
763
|
validateMatrix(
|
|
440
764
|
'mfccToAudio',
|
|
@@ -481,13 +805,25 @@ export function mfccToAudio(
|
|
|
481
805
|
* @param hopLength - Hop length (default: 512)
|
|
482
806
|
* @returns Chroma features result
|
|
483
807
|
*/
|
|
808
|
+
export function chroma(request: SpectrogramRequest): ChromaResult;
|
|
484
809
|
export function chroma(
|
|
485
810
|
samples: Float32Array,
|
|
811
|
+
sampleRate?: number,
|
|
812
|
+
nFft?: number,
|
|
813
|
+
hopLength?: number,
|
|
814
|
+
options?: GuardedOptions,
|
|
815
|
+
): ChromaResult;
|
|
816
|
+
export function chroma(
|
|
817
|
+
samples: Float32Array | SpectrogramRequest,
|
|
486
818
|
sampleRate = 22050,
|
|
487
819
|
nFft = 2048,
|
|
488
820
|
hopLength = 512,
|
|
489
821
|
options: GuardedOptions = {},
|
|
490
822
|
): ChromaResult {
|
|
823
|
+
if (!(samples instanceof Float32Array)) {
|
|
824
|
+
const request = samples;
|
|
825
|
+
return chroma(request.samples, request.sampleRate, request.nFft, request.hopLength, request);
|
|
826
|
+
}
|
|
491
827
|
validateSpectrogramSamples('chroma', samples, sampleRate, options);
|
|
492
828
|
validatePositiveIntegers('chroma', { nFft, hopLength });
|
|
493
829
|
return requireModule().chroma(samples, sampleRate, nFft, hopLength);
|