@libraz/libsonare 1.7.1 → 1.8.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/NOTICE +178 -0
- package/README.md +26 -170
- package/dist/_chain_config.d.ts +14 -0
- package/dist/_chain_config.d.ts.map +1 -0
- package/dist/_effects_common.d.ts +6 -0
- package/dist/_effects_common.d.ts.map +1 -0
- package/dist/_feature_validation.d.ts +8 -0
- package/dist/_feature_validation.d.ts.map +1 -0
- package/dist/_fft_options.d.ts +24 -0
- package/dist/_fft_options.d.ts.map +1 -0
- package/dist/align_take.d.ts +50 -0
- package/dist/align_take.d.ts.map +1 -0
- package/dist/analysis.d.ts +29 -5837
- package/dist/analysis.d.ts.map +1 -0
- package/dist/analysis.js +873 -722
- package/dist/analysis.js.map +1 -1
- package/dist/analysis_helpers.d.ts +9 -0
- package/dist/analysis_helpers.d.ts.map +1 -0
- package/dist/audio.d.ts +163 -0
- package/dist/audio.d.ts.map +1 -0
- package/dist/clip_page_streamer.d.ts +133 -0
- package/dist/clip_page_streamer.d.ts.map +1 -0
- package/dist/codes.d.ts +44 -0
- package/dist/codes.d.ts.map +1 -0
- package/dist/effects_mastering.d.ts +23 -0
- package/dist/effects_mastering.d.ts.map +1 -0
- package/dist/effects_note_ops.d.ts +477 -0
- package/dist/effects_note_ops.d.ts.map +1 -0
- package/dist/effects_percussive.d.ts +185 -0
- package/dist/effects_percussive.d.ts.map +1 -0
- package/dist/effects_separation.d.ts +65 -0
- package/dist/effects_separation.d.ts.map +1 -0
- package/dist/effects_spectral.d.ts +28 -0
- package/dist/effects_spectral.d.ts.map +1 -0
- package/dist/effects_timepitch.d.ts +129 -0
- package/dist/effects_timepitch.d.ts.map +1 -0
- package/dist/effects_voice_change.d.ts +53 -0
- package/dist/effects_voice_change.d.ts.map +1 -0
- package/dist/errors.d.ts +51 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/feature_core.d.ts +341 -0
- package/dist/feature_core.d.ts.map +1 -0
- package/dist/feature_decompose.d.ts +278 -0
- package/dist/feature_decompose.d.ts.map +1 -0
- package/dist/feature_inverse.d.ts +128 -0
- package/dist/feature_inverse.d.ts.map +1 -0
- package/dist/feature_loudness.d.ts +66 -0
- package/dist/feature_loudness.d.ts.map +1 -0
- package/dist/feature_music.d.ts +307 -0
- package/dist/feature_music.d.ts.map +1 -0
- package/dist/feature_pitch.d.ts +108 -0
- package/dist/feature_pitch.d.ts.map +1 -0
- package/dist/feature_resample.d.ts +16 -0
- package/dist/feature_resample.d.ts.map +1 -0
- package/dist/feature_spectral.d.ts +137 -0
- package/dist/feature_spectral.d.ts.map +1 -0
- package/dist/feature_spectrogram.d.ts +198 -0
- package/dist/feature_spectrogram.d.ts.map +1 -0
- package/dist/features.d.ts +10 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/hrtf/default.shrf +0 -0
- package/dist/index.d.ts +74 -7329
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3816 -1359
- package/dist/index.js.map +1 -1
- package/dist/instrument_types.d.ts +517 -0
- package/dist/instrument_types.d.ts.map +1 -0
- package/dist/live_audio.d.ts +35 -0
- package/dist/live_audio.d.ts.map +1 -0
- package/dist/mastering_chain.d.ts +213 -0
- package/dist/mastering_chain.d.ts.map +1 -0
- package/dist/mastering_core.d.ts +457 -0
- package/dist/mastering_core.d.ts.map +1 -0
- package/dist/mastering_dynamics.d.ts +80 -0
- package/dist/mastering_dynamics.d.ts.map +1 -0
- package/dist/metering.d.ts +287 -0
- package/dist/metering.d.ts.map +1 -0
- package/dist/mixer.d.ts +464 -0
- package/dist/mixer.d.ts.map +1 -0
- package/dist/mixing_assistant.d.ts +62 -0
- package/dist/mixing_assistant.d.ts.map +1 -0
- package/dist/mixing_oneshot.d.ts +40 -0
- package/dist/mixing_oneshot.d.ts.map +1 -0
- package/dist/module_state.d.ts +15 -0
- package/dist/module_state.d.ts.map +1 -0
- package/dist/opfs_clip_pages.d.ts +28 -0
- package/dist/opfs_clip_pages.d.ts.map +1 -0
- package/dist/playback_renderer.d.ts +128 -0
- package/dist/playback_renderer.d.ts.map +1 -0
- package/dist/polyphony.d.ts +202 -0
- package/dist/polyphony.d.ts.map +1 -0
- package/dist/project.d.ts +8 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project_class.d.ts +562 -0
- package/dist/project_class.d.ts.map +1 -0
- package/dist/project_internal.d.ts +194 -0
- package/dist/project_internal.d.ts.map +1 -0
- package/dist/project_synth.d.ts +74 -0
- package/dist/project_synth.d.ts.map +1 -0
- package/dist/project_types.d.ts +652 -0
- package/dist/project_types.d.ts.map +1 -0
- package/dist/public_types.d.ts +185 -0
- package/dist/public_types.d.ts.map +1 -0
- package/dist/public_types_acoustic.d.ts +215 -0
- package/dist/public_types_acoustic.d.ts.map +1 -0
- package/dist/public_types_mastering.d.ts +510 -0
- package/dist/public_types_mastering.d.ts.map +1 -0
- package/dist/public_types_mixing.d.ts +436 -0
- package/dist/public_types_mixing.d.ts.map +1 -0
- package/dist/public_types_music.d.ts +619 -0
- package/dist/public_types_music.d.ts.map +1 -0
- package/dist/public_types_playback.d.ts +164 -0
- package/dist/public_types_playback.d.ts.map +1 -0
- package/dist/public_types_realtime.d.ts +174 -0
- package/dist/public_types_realtime.d.ts.map +1 -0
- package/dist/public_types_repair.d.ts +424 -0
- package/dist/public_types_repair.d.ts.map +1 -0
- package/dist/public_types_spectral.d.ts +697 -0
- package/dist/public_types_spectral.d.ts.map +1 -0
- package/dist/quick_analysis.d.ts +445 -0
- package/dist/quick_analysis.d.ts.map +1 -0
- package/dist/realtime_engine.d.ts +850 -0
- package/dist/realtime_engine.d.ts.map +1 -0
- package/dist/realtime_voice_changer.d.ts +158 -0
- package/dist/realtime_voice_changer.d.ts.map +1 -0
- package/dist/repair_dereverb.d.ts +187 -0
- package/dist/repair_dereverb.d.ts.map +1 -0
- package/dist/repair_impulsive.d.ts +186 -0
- package/dist/repair_impulsive.d.ts.map +1 -0
- package/dist/repair_noise.d.ts +239 -0
- package/dist/repair_noise.d.ts.map +1 -0
- package/dist/repair_trim.d.ts +123 -0
- package/dist/repair_trim.d.ts.map +1 -0
- package/dist/sample_bank.d.ts +84 -0
- package/dist/sample_bank.d.ts.map +1 -0
- package/dist/scale.d.ts +10 -0
- package/dist/scale.d.ts.map +1 -0
- package/dist/schemas/mixer-scene.schema.json +393 -0
- package/dist/schemas/playback-renderer-config.schema.json +392 -0
- package/dist/sonare-analysis.d.ts +8 -0
- package/dist/sonare-analysis.js +2 -2
- package/dist/sonare-analysis.wasm +0 -0
- package/dist/sonare.d.ts +3909 -0
- package/dist/sonare.js +2 -2
- package/dist/sonare.wasm +0 -0
- package/dist/stream_analyzer.d.ts +163 -0
- package/dist/stream_analyzer.d.ts.map +1 -0
- package/dist/stream_types.d.ts +214 -0
- package/dist/stream_types.d.ts.map +1 -0
- package/dist/streaming_mixing.d.ts +6 -0
- package/dist/streaming_mixing.d.ts.map +1 -0
- package/dist/streaming_processors.d.ts +335 -0
- package/dist/streaming_processors.d.ts.map +1 -0
- package/dist/transcribe.d.ts +77 -0
- package/dist/transcribe.d.ts.map +1 -0
- package/dist/validation.d.ts +140 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/web_midi.d.ts +77 -0
- package/dist/web_midi.d.ts.map +1 -0
- package/dist/worker.d.ts +5 -48
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +94 -41
- package/dist/worker.js.map +1 -1
- package/dist/worker_client.d.ts +96 -0
- package/dist/worker_client.d.ts.map +1 -0
- package/dist/worker_protocol.d.ts +43 -0
- package/dist/worker_protocol.d.ts.map +1 -0
- package/dist/worklet/audio_types.d.ts +21 -0
- package/dist/worklet/audio_types.d.ts.map +1 -0
- package/dist/worklet/engine-automation.d.ts +29 -0
- package/dist/worklet/engine-automation.d.ts.map +1 -0
- package/dist/worklet/engine-capture-facade.d.ts +35 -0
- package/dist/worklet/engine-capture-facade.d.ts.map +1 -0
- package/dist/worklet/engine-clips.d.ts +23 -0
- package/dist/worklet/engine-clips.d.ts.map +1 -0
- package/dist/worklet/engine-markers.d.ts +40 -0
- package/dist/worklet/engine-markers.d.ts.map +1 -0
- package/dist/worklet/engine-mixer-facade.d.ts +128 -0
- package/dist/worklet/engine-mixer-facade.d.ts.map +1 -0
- package/dist/worklet/engine-node.d.ts +81 -0
- package/dist/worklet/engine-node.d.ts.map +1 -0
- package/dist/worklet/engine-offline.d.ts +81 -0
- package/dist/worklet/engine-offline.d.ts.map +1 -0
- package/dist/worklet/engine-options.d.ts +12 -0
- package/dist/worklet/engine-options.d.ts.map +1 -0
- package/dist/worklet/engine-parameter-facade.d.ts +106 -0
- package/dist/worklet/engine-parameter-facade.d.ts.map +1 -0
- package/dist/worklet/engine-processor.d.ts +68 -0
- package/dist/worklet/engine-processor.d.ts.map +1 -0
- package/dist/worklet/engine-register.d.ts +2 -0
- package/dist/worklet/engine-register.d.ts.map +1 -0
- package/dist/worklet/engine-strips.d.ts +73 -0
- package/dist/worklet/engine-strips.d.ts.map +1 -0
- package/dist/worklet/engine-sync.d.ts +37 -0
- package/dist/worklet/engine-sync.d.ts.map +1 -0
- package/dist/worklet/engine-tempo-facade.d.ts +48 -0
- package/dist/worklet/engine-tempo-facade.d.ts.map +1 -0
- package/dist/worklet/engine.d.ts +397 -0
- package/dist/worklet/engine.d.ts.map +1 -0
- package/dist/worklet/guards.d.ts +47 -0
- package/dist/worklet/guards.d.ts.map +1 -0
- package/dist/worklet/messages.d.ts +710 -0
- package/dist/worklet/messages.d.ts.map +1 -0
- package/dist/worklet/mixer-processor.d.ts +46 -0
- package/dist/worklet/mixer-processor.d.ts.map +1 -0
- package/dist/worklet/playback-processor.d.ts +62 -0
- package/dist/worklet/playback-processor.d.ts.map +1 -0
- package/dist/worklet/protocol.d.ts +323 -0
- package/dist/worklet/protocol.d.ts.map +1 -0
- package/dist/worklet/voice-changer-processor.d.ts +41 -0
- package/dist/worklet/voice-changer-processor.d.ts.map +1 -0
- package/dist/worklet.d.ts +16 -2142
- package/dist/worklet.d.ts.map +1 -0
- package/dist/worklet.js +2889 -466
- package/dist/worklet.js.map +1 -1
- package/package.json +23 -12
- package/src/_effects_common.ts +17 -0
- package/src/_feature_validation.ts +34 -0
- package/src/_fft_options.ts +39 -0
- package/src/align_take.ts +64 -0
- package/src/analysis.ts +56 -3
- package/src/analysis_helpers.ts +7 -0
- package/src/audio.ts +106 -3
- package/src/codes.ts +39 -2
- package/src/effects_mastering.ts +97 -22
- package/src/effects_note_ops.ts +635 -0
- package/src/effects_percussive.ts +217 -0
- package/src/effects_separation.ts +150 -0
- package/src/effects_spectral.ts +60 -0
- package/src/effects_timepitch.ts +377 -0
- package/src/errors.ts +23 -1
- package/src/feature_core.ts +127 -2
- package/src/feature_decompose.ts +633 -0
- package/src/feature_inverse.ts +454 -0
- package/src/feature_loudness.ts +125 -0
- package/src/feature_music.ts +107 -14
- package/src/feature_pitch.ts +96 -1
- package/src/feature_spectral.ts +16 -611
- package/src/feature_spectrogram.ts +63 -450
- package/src/features.ts +36 -22
- package/src/index.ts +285 -30
- package/src/instrument_types.ts +645 -0
- package/src/live_audio.ts +27 -1
- package/src/mastering_chain.ts +184 -0
- package/src/mastering_core.ts +346 -32
- package/src/mastering_dynamics.ts +22 -11
- package/src/metering.ts +67 -24
- package/src/mixer.ts +212 -3
- package/src/mixing_assistant.ts +138 -0
- package/src/mixing_oneshot.ts +10 -5
- package/src/module_state.ts +24 -2
- package/src/playback_renderer.ts +252 -0
- package/src/polyphony.ts +279 -0
- package/src/project.ts +64 -24
- package/src/project_class.ts +502 -29
- package/src/project_internal.ts +151 -42
- package/src/project_synth.ts +67 -1
- package/src/project_types.ts +302 -270
- package/src/public_types.ts +122 -3
- package/src/public_types_acoustic.ts +112 -3
- package/src/public_types_mastering.ts +254 -73
- package/src/public_types_mixing.ts +363 -1
- package/src/public_types_music.ts +312 -2
- package/src/public_types_playback.ts +195 -0
- package/src/public_types_realtime.ts +39 -7
- package/src/public_types_repair.ts +446 -0
- package/src/public_types_spectral.ts +487 -1
- package/src/quick_analysis.ts +203 -26
- package/src/realtime_engine.ts +750 -28
- package/src/realtime_voice_changer.ts +55 -1
- package/src/repair_dereverb.ts +299 -0
- package/src/repair_impulsive.ts +395 -0
- package/src/repair_noise.ts +425 -0
- package/src/repair_trim.ts +226 -0
- package/src/sample_bank.ts +113 -0
- package/src/sonare.js.d.ts +1125 -30
- package/src/stream_analyzer.ts +36 -4
- package/src/stream_types.ts +37 -0
- package/src/streaming_mixing.ts +1 -1
- package/src/streaming_processors.ts +212 -10
- package/src/transcribe.ts +89 -0
- package/src/validation.ts +285 -11
- package/src/web_midi.ts +1 -6
- package/src/worker.ts +18 -2
- package/src/worklet/audio_types.ts +37 -0
- package/src/worklet/engine-mixer-facade.ts +444 -10
- package/src/worklet/engine-node.ts +85 -28
- package/src/worklet/engine-offline.ts +14 -8
- package/src/worklet/engine-parameter-facade.ts +21 -0
- package/src/worklet/engine-processor.ts +307 -71
- package/src/worklet/engine-register.ts +32 -18
- package/src/worklet/engine-strips.ts +280 -9
- package/src/worklet/engine-sync.ts +14 -6
- package/src/worklet/engine.ts +365 -31
- package/src/worklet/guards.ts +140 -44
- package/src/worklet/messages.ts +239 -2
- package/src/worklet/mixer-processor.ts +109 -47
- package/src/worklet/playback-processor.ts +300 -0
- package/src/worklet/protocol.ts +53 -3
- package/src/worklet/voice-changer-processor.ts +17 -11
- package/src/worklet.ts +22 -0
- package/src/effects_transform.ts +0 -718
- package/src/mastering_repair.ts +0 -273
package/src/effects_transform.ts
DELETED
|
@@ -1,718 +0,0 @@
|
|
|
1
|
-
import { getSonareModule } from './module_state';
|
|
2
|
-
import type {
|
|
3
|
-
HpssResult,
|
|
4
|
-
NoteMoveOptions,
|
|
5
|
-
NoteStretchOptions,
|
|
6
|
-
PitchCorrectOptions,
|
|
7
|
-
SpectralEditOptions,
|
|
8
|
-
SpectralRegionOp,
|
|
9
|
-
VoicedFlags,
|
|
10
|
-
} from './public_types';
|
|
11
|
-
import type { ValidateOptions } from './validation';
|
|
12
|
-
import { assertSampleRate, assertSamples } from './validation';
|
|
13
|
-
|
|
14
|
-
function requireModule() {
|
|
15
|
-
return getSonareModule();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// The embind layer reads the companion voicing array as Float32Array. A flag is
|
|
19
|
-
// a decision, not a magnitude: collapse to 1/0 on truthiness, which is the same
|
|
20
|
-
// reduction the Node facade applies, so both surfaces agree on every accepted
|
|
21
|
-
// input type.
|
|
22
|
-
function toVoicedFloat32(voiced: VoicedFlags): Float32Array {
|
|
23
|
-
const out = new Float32Array(voiced.length);
|
|
24
|
-
for (let index = 0; index < voiced.length; index += 1) {
|
|
25
|
-
out[index] = voiced[index] ? 1 : 0;
|
|
26
|
-
}
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function resolveEffectFftOptions(
|
|
31
|
-
fnName: string,
|
|
32
|
-
nFft: unknown,
|
|
33
|
-
hopLength: unknown,
|
|
34
|
-
): { nFft: number; hopLength: number } {
|
|
35
|
-
const resolvedNFft = nFft === undefined ? 2048 : nFft;
|
|
36
|
-
const resolvedHopLength = hopLength === undefined ? 512 : hopLength;
|
|
37
|
-
if (typeof resolvedNFft !== 'number' || !Number.isInteger(resolvedNFft)) {
|
|
38
|
-
throw new TypeError(`${fnName}: nFft must be an integer`);
|
|
39
|
-
}
|
|
40
|
-
if (resolvedNFft < 2 || resolvedNFft > 2 ** 30) {
|
|
41
|
-
throw new RangeError(`${fnName}: nFft must be an even power of two >= 2`);
|
|
42
|
-
}
|
|
43
|
-
if ((resolvedNFft & (resolvedNFft - 1)) !== 0) {
|
|
44
|
-
throw new RangeError(`${fnName}: nFft must be an even power of two >= 2`);
|
|
45
|
-
}
|
|
46
|
-
if (typeof resolvedHopLength !== 'number' || !Number.isInteger(resolvedHopLength)) {
|
|
47
|
-
throw new TypeError(`${fnName}: hopLength must be an integer`);
|
|
48
|
-
}
|
|
49
|
-
if (resolvedHopLength <= 0 || resolvedHopLength > 2 ** 31 - 1) {
|
|
50
|
-
throw new RangeError(`${fnName}: hopLength must be a positive integer`);
|
|
51
|
-
}
|
|
52
|
-
return { nFft: resolvedNFft, hopLength: resolvedHopLength };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export type NormalizeMode = 'peak' | 'rms';
|
|
56
|
-
|
|
57
|
-
function resolveNormalizeMode(value: unknown): NormalizeMode {
|
|
58
|
-
if (value === undefined) {
|
|
59
|
-
return 'peak';
|
|
60
|
-
}
|
|
61
|
-
if (typeof value !== 'string') {
|
|
62
|
-
throw new TypeError("normalize: mode must be the string 'peak' or 'rms'");
|
|
63
|
-
}
|
|
64
|
-
if (value !== 'peak' && value !== 'rms') {
|
|
65
|
-
throw new RangeError("normalize: mode must be the string 'peak' or 'rms'");
|
|
66
|
-
}
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function resolveHardMask(value: unknown, fnName: string): boolean {
|
|
71
|
-
if (value === undefined) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (typeof value !== 'boolean') {
|
|
75
|
-
throw new TypeError(`${fnName}: hardMask must be a boolean`);
|
|
76
|
-
}
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Canonical request form for HPSS. */
|
|
81
|
-
export interface HpssRequest {
|
|
82
|
-
samples: Float32Array;
|
|
83
|
-
sampleRate?: number;
|
|
84
|
-
kernelHarmonic?: number;
|
|
85
|
-
kernelPercussive?: number;
|
|
86
|
-
nFft?: number;
|
|
87
|
-
hopLength?: number;
|
|
88
|
-
hardMask?: boolean;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface HarmonicRequest extends ValidateOptions {
|
|
92
|
-
samples: Float32Array;
|
|
93
|
-
sampleRate?: number;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface PercussiveRequest extends ValidateOptions {
|
|
97
|
-
samples: Float32Array;
|
|
98
|
-
sampleRate?: number;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface TimeStretchRequest extends ValidateOptions {
|
|
102
|
-
samples: Float32Array;
|
|
103
|
-
sampleRate?: number;
|
|
104
|
-
rate: number;
|
|
105
|
-
nFft?: number;
|
|
106
|
-
hopLength?: number;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface PitchShiftRequest extends ValidateOptions {
|
|
110
|
-
samples: Float32Array;
|
|
111
|
-
sampleRate?: number;
|
|
112
|
-
semitones: number;
|
|
113
|
-
nFft?: number;
|
|
114
|
-
hopLength?: number;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface PitchCorrectToMidiRequest extends ValidateOptions {
|
|
118
|
-
samples: Float32Array;
|
|
119
|
-
sampleRate?: number;
|
|
120
|
-
currentMidi?: number;
|
|
121
|
-
targetMidi?: number;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface PitchCorrectToMidiTimevaryingRequest extends ValidateOptions {
|
|
125
|
-
samples: Float32Array;
|
|
126
|
-
f0Hz: Float32Array;
|
|
127
|
-
targetMidi: number;
|
|
128
|
-
sampleRate?: number;
|
|
129
|
-
hopLength?: number;
|
|
130
|
-
voiced?: VoicedFlags;
|
|
131
|
-
voicedProb?: Float32Array;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export interface PitchCorrectTimevaryingRequest extends PitchCorrectOptions {
|
|
135
|
-
samples: Float32Array;
|
|
136
|
-
f0Hz: Float32Array;
|
|
137
|
-
sampleRate?: number;
|
|
138
|
-
hopLength?: number;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface NoteStretchRequest extends NoteStretchOptions, ValidateOptions {
|
|
142
|
-
samples: Float32Array;
|
|
143
|
-
sampleRate?: number;
|
|
144
|
-
}
|
|
145
|
-
export interface NoteMoveRequest extends NoteMoveOptions, ValidateOptions {
|
|
146
|
-
samples: Float32Array;
|
|
147
|
-
sampleRate?: number;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface NormalizeRequest extends ValidateOptions {
|
|
151
|
-
samples: Float32Array;
|
|
152
|
-
sampleRate?: number;
|
|
153
|
-
targetDb?: number;
|
|
154
|
-
mode?: NormalizeMode;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface SpectralEditRequest extends SpectralEditOptions, ValidateOptions {
|
|
158
|
-
samples: Float32Array;
|
|
159
|
-
sampleRate: number;
|
|
160
|
-
ops?: SpectralRegionOp[];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// ============================================================================
|
|
164
|
-
// Effects
|
|
165
|
-
// ============================================================================
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Perform Harmonic-Percussive Source Separation (HPSS).
|
|
169
|
-
*
|
|
170
|
-
* @param samples - Audio samples (mono, float32)
|
|
171
|
-
* @param sampleRate - Sample rate in Hz (default: 22050)
|
|
172
|
-
* @param kernelHarmonic - Horizontal median filter size for harmonic (default: 31)
|
|
173
|
-
* @param kernelPercussive - Vertical median filter size for percussive (default: 31)
|
|
174
|
-
* @returns Separated harmonic and percussive components
|
|
175
|
-
*/
|
|
176
|
-
export function hpss(request: HpssRequest): HpssResult;
|
|
177
|
-
export function hpss(
|
|
178
|
-
samples: Float32Array,
|
|
179
|
-
sampleRate?: number,
|
|
180
|
-
kernelHarmonic?: number,
|
|
181
|
-
kernelPercussive?: number,
|
|
182
|
-
nFft?: number,
|
|
183
|
-
hopLength?: number,
|
|
184
|
-
hardMask?: boolean,
|
|
185
|
-
): HpssResult;
|
|
186
|
-
export function hpss(
|
|
187
|
-
samples: Float32Array | HpssRequest,
|
|
188
|
-
sampleRate = 22050,
|
|
189
|
-
kernelHarmonic = 31,
|
|
190
|
-
kernelPercussive = 31,
|
|
191
|
-
nFft?: number,
|
|
192
|
-
hopLength?: number,
|
|
193
|
-
hardMask?: boolean,
|
|
194
|
-
): HpssResult {
|
|
195
|
-
const request =
|
|
196
|
-
samples instanceof Float32Array
|
|
197
|
-
? { samples, sampleRate, kernelHarmonic, kernelPercussive, nFft, hopLength, hardMask }
|
|
198
|
-
: samples;
|
|
199
|
-
const fftOptions = resolveEffectFftOptions('hpss', request.nFft, request.hopLength);
|
|
200
|
-
const resolvedHardMask = resolveHardMask(request.hardMask, 'hpss');
|
|
201
|
-
return requireModule().hpssEx(
|
|
202
|
-
request.samples,
|
|
203
|
-
request.sampleRate ?? 22050,
|
|
204
|
-
request.kernelHarmonic ?? 31,
|
|
205
|
-
request.kernelPercussive ?? 31,
|
|
206
|
-
fftOptions.nFft,
|
|
207
|
-
fftOptions.hopLength,
|
|
208
|
-
resolvedHardMask,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Extract harmonic component from audio.
|
|
214
|
-
*
|
|
215
|
-
* @param samples - Audio samples (mono, float32)
|
|
216
|
-
* @param sampleRate - Sample rate in Hz
|
|
217
|
-
* @returns Harmonic component
|
|
218
|
-
*/
|
|
219
|
-
export function harmonic(request: HarmonicRequest): Float32Array;
|
|
220
|
-
export function harmonic(
|
|
221
|
-
samples: Float32Array,
|
|
222
|
-
sampleRate?: number,
|
|
223
|
-
options?: ValidateOptions,
|
|
224
|
-
): Float32Array;
|
|
225
|
-
export function harmonic(
|
|
226
|
-
samples: Float32Array | HarmonicRequest,
|
|
227
|
-
sampleRate = 22050,
|
|
228
|
-
options: ValidateOptions = {},
|
|
229
|
-
): Float32Array {
|
|
230
|
-
const request = samples instanceof Float32Array ? { samples, sampleRate, ...options } : samples;
|
|
231
|
-
assertSamples('harmonic', request.samples, request.validate !== false);
|
|
232
|
-
return requireModule().harmonic(request.samples, request.sampleRate ?? 22050);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Extract percussive component from audio.
|
|
237
|
-
*
|
|
238
|
-
* @param samples - Audio samples (mono, float32)
|
|
239
|
-
* @param sampleRate - Sample rate in Hz
|
|
240
|
-
* @returns Percussive component
|
|
241
|
-
*/
|
|
242
|
-
export function percussive(request: PercussiveRequest): Float32Array;
|
|
243
|
-
export function percussive(
|
|
244
|
-
samples: Float32Array,
|
|
245
|
-
sampleRate?: number,
|
|
246
|
-
options?: ValidateOptions,
|
|
247
|
-
): Float32Array;
|
|
248
|
-
export function percussive(
|
|
249
|
-
samples: Float32Array | PercussiveRequest,
|
|
250
|
-
sampleRate = 22050,
|
|
251
|
-
options: ValidateOptions = {},
|
|
252
|
-
): Float32Array {
|
|
253
|
-
const request = samples instanceof Float32Array ? { samples, sampleRate, ...options } : samples;
|
|
254
|
-
assertSamples('percussive', request.samples, request.validate !== false);
|
|
255
|
-
return requireModule().percussive(request.samples, request.sampleRate ?? 22050);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Time-stretch audio without changing pitch.
|
|
260
|
-
*
|
|
261
|
-
* @param samples - Audio samples (mono, float32)
|
|
262
|
-
* @param sampleRate - Sample rate in Hz (default: 22050)
|
|
263
|
-
* @param rate - Time stretch rate (0.5 = double duration, 2.0 = half duration)
|
|
264
|
-
* @returns Time-stretched audio
|
|
265
|
-
*/
|
|
266
|
-
export function timeStretch(request: TimeStretchRequest): Float32Array;
|
|
267
|
-
export function timeStretch(
|
|
268
|
-
samples: Float32Array,
|
|
269
|
-
sampleRate: number,
|
|
270
|
-
rate: number,
|
|
271
|
-
options?: ValidateOptions,
|
|
272
|
-
): Float32Array;
|
|
273
|
-
export function timeStretch(
|
|
274
|
-
samples: Float32Array,
|
|
275
|
-
sampleRate: number,
|
|
276
|
-
rate: number,
|
|
277
|
-
nFft?: number,
|
|
278
|
-
hopLength?: number,
|
|
279
|
-
options?: ValidateOptions,
|
|
280
|
-
): Float32Array;
|
|
281
|
-
export function timeStretch(
|
|
282
|
-
samples: Float32Array | TimeStretchRequest,
|
|
283
|
-
sampleRate?: number,
|
|
284
|
-
rate?: number,
|
|
285
|
-
nFftOrOptions?: number | ValidateOptions,
|
|
286
|
-
hopLength?: number,
|
|
287
|
-
options: ValidateOptions = {},
|
|
288
|
-
): Float32Array {
|
|
289
|
-
if (
|
|
290
|
-
nFftOrOptions !== undefined &&
|
|
291
|
-
nFftOrOptions !== null &&
|
|
292
|
-
typeof nFftOrOptions !== 'number' &&
|
|
293
|
-
typeof nFftOrOptions !== 'object'
|
|
294
|
-
) {
|
|
295
|
-
throw new TypeError('timeStretch: nFft must be an integer or options object');
|
|
296
|
-
}
|
|
297
|
-
if (nFftOrOptions === null) {
|
|
298
|
-
throw new TypeError('timeStretch: nFft must be an integer or options object');
|
|
299
|
-
}
|
|
300
|
-
const positionalOptions =
|
|
301
|
-
typeof nFftOrOptions === 'object' && nFftOrOptions !== null ? nFftOrOptions : options;
|
|
302
|
-
const positionalNFft = typeof nFftOrOptions === 'number' ? nFftOrOptions : undefined;
|
|
303
|
-
const request: TimeStretchRequest =
|
|
304
|
-
samples instanceof Float32Array
|
|
305
|
-
? {
|
|
306
|
-
samples,
|
|
307
|
-
sampleRate,
|
|
308
|
-
rate: rate as number,
|
|
309
|
-
nFft: positionalNFft,
|
|
310
|
-
hopLength,
|
|
311
|
-
...positionalOptions,
|
|
312
|
-
}
|
|
313
|
-
: samples;
|
|
314
|
-
assertSamples('timeStretch', request.samples, request.validate !== false);
|
|
315
|
-
const fftOptions = resolveEffectFftOptions('timeStretch', request.nFft, request.hopLength);
|
|
316
|
-
return requireModule().timeStretchEx(
|
|
317
|
-
request.samples,
|
|
318
|
-
request.sampleRate ?? 22050,
|
|
319
|
-
request.rate,
|
|
320
|
-
fftOptions.nFft,
|
|
321
|
-
fftOptions.hopLength,
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Pitch-shift audio without changing duration.
|
|
327
|
-
*
|
|
328
|
-
* @param samples - Audio samples (mono, float32)
|
|
329
|
-
* @param sampleRate - Sample rate in Hz (default: 22050)
|
|
330
|
-
* @param semitones - Pitch shift in semitones (+12 = one octave up, -12 = one octave down)
|
|
331
|
-
* @returns Pitch-shifted audio
|
|
332
|
-
*/
|
|
333
|
-
export function pitchShift(request: PitchShiftRequest): Float32Array;
|
|
334
|
-
export function pitchShift(
|
|
335
|
-
samples: Float32Array,
|
|
336
|
-
sampleRate: number,
|
|
337
|
-
semitones: number,
|
|
338
|
-
options?: ValidateOptions,
|
|
339
|
-
): Float32Array;
|
|
340
|
-
export function pitchShift(
|
|
341
|
-
samples: Float32Array,
|
|
342
|
-
sampleRate: number,
|
|
343
|
-
semitones: number,
|
|
344
|
-
nFft?: number,
|
|
345
|
-
hopLength?: number,
|
|
346
|
-
options?: ValidateOptions,
|
|
347
|
-
): Float32Array;
|
|
348
|
-
export function pitchShift(
|
|
349
|
-
samples: Float32Array | PitchShiftRequest,
|
|
350
|
-
sampleRate?: number,
|
|
351
|
-
semitones?: number,
|
|
352
|
-
nFftOrOptions?: number | ValidateOptions,
|
|
353
|
-
hopLength?: number,
|
|
354
|
-
options: ValidateOptions = {},
|
|
355
|
-
): Float32Array {
|
|
356
|
-
if (
|
|
357
|
-
nFftOrOptions !== undefined &&
|
|
358
|
-
nFftOrOptions !== null &&
|
|
359
|
-
typeof nFftOrOptions !== 'number' &&
|
|
360
|
-
typeof nFftOrOptions !== 'object'
|
|
361
|
-
) {
|
|
362
|
-
throw new TypeError('pitchShift: nFft must be an integer or options object');
|
|
363
|
-
}
|
|
364
|
-
if (nFftOrOptions === null) {
|
|
365
|
-
throw new TypeError('pitchShift: nFft must be an integer or options object');
|
|
366
|
-
}
|
|
367
|
-
const positionalOptions =
|
|
368
|
-
typeof nFftOrOptions === 'object' && nFftOrOptions !== null ? nFftOrOptions : options;
|
|
369
|
-
const positionalNFft = typeof nFftOrOptions === 'number' ? nFftOrOptions : undefined;
|
|
370
|
-
const request: PitchShiftRequest =
|
|
371
|
-
samples instanceof Float32Array
|
|
372
|
-
? {
|
|
373
|
-
samples,
|
|
374
|
-
sampleRate,
|
|
375
|
-
semitones: semitones as number,
|
|
376
|
-
nFft: positionalNFft,
|
|
377
|
-
hopLength,
|
|
378
|
-
...positionalOptions,
|
|
379
|
-
}
|
|
380
|
-
: samples;
|
|
381
|
-
assertSamples('pitchShift', request.samples, request.validate !== false);
|
|
382
|
-
const fftOptions = resolveEffectFftOptions('pitchShift', request.nFft, request.hopLength);
|
|
383
|
-
return requireModule().pitchShiftEx(
|
|
384
|
-
request.samples,
|
|
385
|
-
request.sampleRate ?? 22050,
|
|
386
|
-
request.semitones,
|
|
387
|
-
fftOptions.nFft,
|
|
388
|
-
fftOptions.hopLength,
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Pitch-correct audio from a current MIDI note to a target MIDI note.
|
|
394
|
-
*
|
|
395
|
-
* Applies one constant, immediate transpose with no retune glide and preserves
|
|
396
|
-
* the input buffer length. Use {@link pitchCorrectToMidiTimevarying} for a
|
|
397
|
-
* caller-supplied pitch contour.
|
|
398
|
-
*
|
|
399
|
-
* @param samples - Audio samples (mono, float32)
|
|
400
|
-
* @param sampleRate - Sample rate in Hz
|
|
401
|
-
* @param currentMidi - Detected/current MIDI note number
|
|
402
|
-
* @param targetMidi - Desired MIDI note number
|
|
403
|
-
* @returns Pitch-corrected audio
|
|
404
|
-
*/
|
|
405
|
-
export function pitchCorrectToMidi(request: PitchCorrectToMidiRequest): Float32Array;
|
|
406
|
-
export function pitchCorrectToMidi(
|
|
407
|
-
samples: Float32Array,
|
|
408
|
-
sampleRate?: number,
|
|
409
|
-
currentMidi?: number,
|
|
410
|
-
targetMidi?: number,
|
|
411
|
-
options?: ValidateOptions,
|
|
412
|
-
): Float32Array;
|
|
413
|
-
export function pitchCorrectToMidi(
|
|
414
|
-
samples: Float32Array | PitchCorrectToMidiRequest,
|
|
415
|
-
sampleRate = 22050,
|
|
416
|
-
currentMidi = 69.0,
|
|
417
|
-
targetMidi = 69.0,
|
|
418
|
-
options: ValidateOptions = {},
|
|
419
|
-
): Float32Array {
|
|
420
|
-
const request =
|
|
421
|
-
samples instanceof Float32Array
|
|
422
|
-
? { samples, sampleRate, currentMidi, targetMidi, ...options }
|
|
423
|
-
: samples;
|
|
424
|
-
assertSamples('pitchCorrectToMidi', request.samples, request.validate !== false);
|
|
425
|
-
return requireModule().pitchCorrectToMidi(
|
|
426
|
-
request.samples,
|
|
427
|
-
request.sampleRate ?? 22050,
|
|
428
|
-
request.currentMidi ?? 69.0,
|
|
429
|
-
request.targetMidi ?? 69.0,
|
|
430
|
-
);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Contour-following ("time-varying") pitch correction toward a MIDI target.
|
|
435
|
-
*
|
|
436
|
-
* Unlike {@link pitchCorrectToMidi} (a single constant transpose), this follows
|
|
437
|
-
* the caller-supplied per-frame `f0Hz` contour and retunes every voiced frame
|
|
438
|
-
* toward `targetMidi`, so vibrato/drift in the source is tracked rather than
|
|
439
|
-
* flattened. `voiced` (truthy = voiced) and `voicedProb` ([0,1]) are optional;
|
|
440
|
-
* omitting them treats every frame as voiced. An `f0Hz` NaN is accepted only
|
|
441
|
-
* when the corresponding `voiced` entry is falsy, matching pYIN output. The
|
|
442
|
-
* `voicedFlag` / `voicedProb` arrays of a {@link PitchResult} can be passed
|
|
443
|
-
* through directly.
|
|
444
|
-
*
|
|
445
|
-
* @param samples - Audio samples (mono, float32)
|
|
446
|
-
* @param f0Hz - Per-frame measured F0 in Hz (one entry per analysis frame)
|
|
447
|
-
* @param targetMidi - Desired MIDI note number
|
|
448
|
-
* @param sampleRate - Sample rate in Hz
|
|
449
|
-
* @param hopLength - F0 hop in samples (frame i covers sample i*hopLength)
|
|
450
|
-
* @param voiced - Optional per-frame voiced flags (truthy = voiced)
|
|
451
|
-
* @param voicedProb - Optional per-frame voicing probability in [0, 1]
|
|
452
|
-
* @returns Pitch-corrected audio
|
|
453
|
-
*/
|
|
454
|
-
export function pitchCorrectToMidiTimevarying(
|
|
455
|
-
request: PitchCorrectToMidiTimevaryingRequest,
|
|
456
|
-
): Float32Array;
|
|
457
|
-
export function pitchCorrectToMidiTimevarying(
|
|
458
|
-
samples: Float32Array,
|
|
459
|
-
f0Hz: Float32Array,
|
|
460
|
-
targetMidi: number,
|
|
461
|
-
sampleRate?: number,
|
|
462
|
-
hopLength?: number,
|
|
463
|
-
voiced?: VoicedFlags,
|
|
464
|
-
voicedProb?: Float32Array,
|
|
465
|
-
options?: ValidateOptions,
|
|
466
|
-
): Float32Array;
|
|
467
|
-
export function pitchCorrectToMidiTimevarying(
|
|
468
|
-
samples: Float32Array | PitchCorrectToMidiTimevaryingRequest,
|
|
469
|
-
f0Hz?: Float32Array,
|
|
470
|
-
targetMidi?: number,
|
|
471
|
-
sampleRate = 22050,
|
|
472
|
-
hopLength = 512,
|
|
473
|
-
voiced?: VoicedFlags,
|
|
474
|
-
voicedProb?: Float32Array,
|
|
475
|
-
options: ValidateOptions = {},
|
|
476
|
-
): Float32Array {
|
|
477
|
-
const request: PitchCorrectToMidiTimevaryingRequest =
|
|
478
|
-
samples instanceof Float32Array
|
|
479
|
-
? {
|
|
480
|
-
samples,
|
|
481
|
-
f0Hz: f0Hz as Float32Array,
|
|
482
|
-
targetMidi: targetMidi as number,
|
|
483
|
-
sampleRate,
|
|
484
|
-
hopLength,
|
|
485
|
-
voiced,
|
|
486
|
-
voicedProb,
|
|
487
|
-
...options,
|
|
488
|
-
}
|
|
489
|
-
: samples;
|
|
490
|
-
assertSamples('pitchCorrectToMidiTimevarying', request.samples, request.validate !== false);
|
|
491
|
-
if (request.voiced && request.voiced.length !== request.f0Hz.length) {
|
|
492
|
-
throw new RangeError('pitchCorrectToMidiTimevarying: voiced length must match f0Hz length');
|
|
493
|
-
}
|
|
494
|
-
if (request.voicedProb && request.voicedProb.length !== request.f0Hz.length) {
|
|
495
|
-
throw new RangeError('pitchCorrectToMidiTimevarying: voicedProb length must match f0Hz length');
|
|
496
|
-
}
|
|
497
|
-
const voicedF32 = request.voiced ? toVoicedFloat32(request.voiced) : undefined;
|
|
498
|
-
return requireModule().pitchCorrectToMidiTimevarying(
|
|
499
|
-
request.samples,
|
|
500
|
-
request.sampleRate ?? 22050,
|
|
501
|
-
request.f0Hz,
|
|
502
|
-
request.targetMidi,
|
|
503
|
-
request.hopLength ?? 512,
|
|
504
|
-
voicedF32,
|
|
505
|
-
request.voicedProb,
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
/**
|
|
510
|
-
* Contour-following pitch correction toward a fixed MIDI note OR a musical
|
|
511
|
-
* scale, with tunable retune strength and vibrato preservation.
|
|
512
|
-
*
|
|
513
|
-
* Generalises {@link pitchCorrectToMidiTimevarying}: the same caller-supplied
|
|
514
|
-
* per-frame `f0Hz` contour drives correction, but `options.mode` selects between
|
|
515
|
-
* a fixed-MIDI target (`'midi'`, default) and scale quantisation (`'scale'`),
|
|
516
|
-
* and the retune knobs shape natural-vs-robotic correction. An `f0Hz` NaN is
|
|
517
|
-
* accepted only for a frame marked unvoiced.
|
|
518
|
-
*
|
|
519
|
-
* @param samples - Audio samples (mono, float32)
|
|
520
|
-
* @param f0Hz - Per-frame measured F0 in Hz (one entry per analysis frame)
|
|
521
|
-
* @param sampleRate - Sample rate in Hz
|
|
522
|
-
* @param hopLength - F0 hop in samples (frame i covers sample i*hopLength)
|
|
523
|
-
* @param options - Target mode + retune knobs + optional voiced/voicedProb arrays
|
|
524
|
-
* @returns Pitch-corrected audio
|
|
525
|
-
*/
|
|
526
|
-
export function pitchCorrectTimevarying(request: PitchCorrectTimevaryingRequest): Float32Array;
|
|
527
|
-
export function pitchCorrectTimevarying(
|
|
528
|
-
samples: Float32Array,
|
|
529
|
-
f0Hz: Float32Array,
|
|
530
|
-
sampleRate?: number,
|
|
531
|
-
hopLength?: number,
|
|
532
|
-
options?: PitchCorrectOptions,
|
|
533
|
-
): Float32Array;
|
|
534
|
-
export function pitchCorrectTimevarying(
|
|
535
|
-
samples: Float32Array | PitchCorrectTimevaryingRequest,
|
|
536
|
-
f0Hz?: Float32Array,
|
|
537
|
-
sampleRate = 22050,
|
|
538
|
-
hopLength = 512,
|
|
539
|
-
options: PitchCorrectOptions = {},
|
|
540
|
-
): Float32Array {
|
|
541
|
-
const request: PitchCorrectTimevaryingRequest =
|
|
542
|
-
samples instanceof Float32Array
|
|
543
|
-
? { samples, f0Hz: f0Hz as Float32Array, sampleRate, hopLength, ...options }
|
|
544
|
-
: samples;
|
|
545
|
-
assertSamples('pitchCorrectTimevarying', request.samples, request.validate !== false);
|
|
546
|
-
if (request.voiced && request.voiced.length !== request.f0Hz.length) {
|
|
547
|
-
throw new RangeError('pitchCorrectTimevarying: voiced length must match f0Hz length');
|
|
548
|
-
}
|
|
549
|
-
if (request.voicedProb && request.voicedProb.length !== request.f0Hz.length) {
|
|
550
|
-
throw new RangeError('pitchCorrectTimevarying: voicedProb length must match f0Hz length');
|
|
551
|
-
}
|
|
552
|
-
const nativeOptions = {
|
|
553
|
-
...request,
|
|
554
|
-
voiced: request.voiced ? toVoicedFloat32(request.voiced) : undefined,
|
|
555
|
-
};
|
|
556
|
-
return requireModule().pitchCorrectTimevarying(
|
|
557
|
-
request.samples,
|
|
558
|
-
request.sampleRate ?? 22050,
|
|
559
|
-
request.f0Hz,
|
|
560
|
-
request.hopLength ?? 512,
|
|
561
|
-
nativeOptions,
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Time-stretch a note region between two sample offsets without changing pitch.
|
|
567
|
-
*
|
|
568
|
-
* @param samples - Audio samples (mono, float32)
|
|
569
|
-
* @param sampleRate - Sample rate in Hz
|
|
570
|
-
* @param onsetSample - Note onset position in samples
|
|
571
|
-
* @param offsetSample - Note offset position in samples
|
|
572
|
-
* @param stretchRatio - Stretch ratio (0.5 = half duration, 2.0 = double duration)
|
|
573
|
-
* @returns Audio with the note region stretched
|
|
574
|
-
*/
|
|
575
|
-
export function noteStretch(request: NoteStretchRequest): Float32Array;
|
|
576
|
-
export function noteStretch(
|
|
577
|
-
samples: Float32Array,
|
|
578
|
-
sampleRate?: number,
|
|
579
|
-
options?: NoteStretchOptions & ValidateOptions,
|
|
580
|
-
): Float32Array;
|
|
581
|
-
export function noteStretch(
|
|
582
|
-
samples: Float32Array | NoteStretchRequest,
|
|
583
|
-
sampleRate = 22050,
|
|
584
|
-
options: NoteStretchOptions & ValidateOptions = {},
|
|
585
|
-
): Float32Array {
|
|
586
|
-
const request = samples instanceof Float32Array ? { samples, sampleRate, ...options } : samples;
|
|
587
|
-
assertSamples('noteStretch', request.samples, request.validate !== false);
|
|
588
|
-
return requireModule().noteStretch(
|
|
589
|
-
request.samples,
|
|
590
|
-
request.sampleRate ?? 22050,
|
|
591
|
-
request.onsetSample ?? 0,
|
|
592
|
-
request.offsetSample ?? request.samples.length,
|
|
593
|
-
request.stretchRatio ?? 1.0,
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
/** Move a note region to a new onset without changing its duration. */
|
|
598
|
-
export function noteMove(request: NoteMoveRequest): Float32Array;
|
|
599
|
-
export function noteMove(
|
|
600
|
-
samples: Float32Array,
|
|
601
|
-
sampleRate?: number,
|
|
602
|
-
options?: NoteMoveOptions & ValidateOptions,
|
|
603
|
-
): Float32Array;
|
|
604
|
-
export function noteMove(
|
|
605
|
-
samples: Float32Array | NoteMoveRequest,
|
|
606
|
-
sampleRate = 22050,
|
|
607
|
-
options: NoteMoveOptions & ValidateOptions = {},
|
|
608
|
-
): Float32Array {
|
|
609
|
-
const request = samples instanceof Float32Array ? { samples, sampleRate, ...options } : samples;
|
|
610
|
-
assertSamples('noteMove', request.samples, request.validate !== false);
|
|
611
|
-
return requireModule().noteMove(
|
|
612
|
-
request.samples,
|
|
613
|
-
request.sampleRate ?? 22050,
|
|
614
|
-
request.onsetSample ?? 0,
|
|
615
|
-
request.offsetSample ?? request.samples.length,
|
|
616
|
-
request.targetOnsetSample ?? 0,
|
|
617
|
-
);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Normalize audio to a target peak or RMS level.
|
|
622
|
-
*
|
|
623
|
-
* @param samples - Audio samples (mono, float32)
|
|
624
|
-
* @param sampleRate - Sample rate in Hz (default: 22050)
|
|
625
|
-
* @param targetDb - Finite target at or below 0 dBFS (default: 0 dB = full scale).
|
|
626
|
-
* For `mode: 'peak'`, this is the peak target; for `mode: 'rms'`, this is the RMS target.
|
|
627
|
-
* @param mode - Normalization mode: `'peak'` (default) or `'rms'`.
|
|
628
|
-
* @returns Normalized audio
|
|
629
|
-
*/
|
|
630
|
-
export function normalize(request: NormalizeRequest): Float32Array;
|
|
631
|
-
export function normalize(
|
|
632
|
-
samples: Float32Array,
|
|
633
|
-
sampleRate: number,
|
|
634
|
-
targetDb?: number,
|
|
635
|
-
options?: ValidateOptions,
|
|
636
|
-
): Float32Array;
|
|
637
|
-
export function normalize(
|
|
638
|
-
samples: Float32Array,
|
|
639
|
-
sampleRate: number,
|
|
640
|
-
targetDb?: number,
|
|
641
|
-
mode?: NormalizeMode,
|
|
642
|
-
options?: ValidateOptions,
|
|
643
|
-
): Float32Array;
|
|
644
|
-
export function normalize(
|
|
645
|
-
samples: Float32Array | NormalizeRequest,
|
|
646
|
-
sampleRate?: number,
|
|
647
|
-
targetDb = 0.0,
|
|
648
|
-
modeOrOptions: NormalizeMode | ValidateOptions = 'peak',
|
|
649
|
-
options: ValidateOptions = {},
|
|
650
|
-
): Float32Array {
|
|
651
|
-
if (
|
|
652
|
-
modeOrOptions !== undefined &&
|
|
653
|
-
modeOrOptions !== null &&
|
|
654
|
-
typeof modeOrOptions !== 'string' &&
|
|
655
|
-
typeof modeOrOptions !== 'object'
|
|
656
|
-
) {
|
|
657
|
-
throw new TypeError("normalize: mode must be the string 'peak' or 'rms'");
|
|
658
|
-
}
|
|
659
|
-
if (modeOrOptions === null) {
|
|
660
|
-
throw new TypeError("normalize: mode must be the string 'peak' or 'rms'");
|
|
661
|
-
}
|
|
662
|
-
const positionalOptions =
|
|
663
|
-
typeof modeOrOptions === 'object' && modeOrOptions !== null ? modeOrOptions : options;
|
|
664
|
-
const positionalMode = typeof modeOrOptions === 'string' ? modeOrOptions : undefined;
|
|
665
|
-
const request: NormalizeRequest =
|
|
666
|
-
samples instanceof Float32Array
|
|
667
|
-
? { samples, sampleRate, targetDb, mode: positionalMode, ...positionalOptions }
|
|
668
|
-
: samples;
|
|
669
|
-
assertSamples('normalize', request.samples, request.validate !== false);
|
|
670
|
-
const mode = resolveNormalizeMode(request.mode);
|
|
671
|
-
return requireModule().normalizeEx(
|
|
672
|
-
request.samples,
|
|
673
|
-
request.sampleRate ?? 22050,
|
|
674
|
-
request.targetDb ?? 0.0,
|
|
675
|
-
mode,
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Apply region-based spectral edits (gain/attenuate/mute/heal) to mono audio.
|
|
681
|
-
*
|
|
682
|
-
* Each op is a time x frequency rectangle applied in array order over a single
|
|
683
|
-
* STFT buffer, so a later op observes the result of earlier ops. The output has
|
|
684
|
-
* the same length and sample rate as the input; an empty `ops` list is an
|
|
685
|
-
* identity transform (within the iSTFT's own tolerance).
|
|
686
|
-
*
|
|
687
|
-
* @param samples - Audio samples (mono, float32)
|
|
688
|
-
* @param sampleRate - Sample rate in Hz
|
|
689
|
-
* @param ops - Region edit ops applied in order ({@link SpectralRegionOp})
|
|
690
|
-
* @param options - STFT + heal configuration ({@link SpectralEditOptions})
|
|
691
|
-
* @returns Edited audio
|
|
692
|
-
*/
|
|
693
|
-
export function spectralEdit(request: SpectralEditRequest): Float32Array;
|
|
694
|
-
export function spectralEdit(
|
|
695
|
-
samples: Float32Array,
|
|
696
|
-
sampleRate: number,
|
|
697
|
-
ops?: SpectralRegionOp[],
|
|
698
|
-
options?: SpectralEditOptions & ValidateOptions,
|
|
699
|
-
): Float32Array;
|
|
700
|
-
export function spectralEdit(
|
|
701
|
-
samples: Float32Array | SpectralEditRequest,
|
|
702
|
-
sampleRate?: number,
|
|
703
|
-
ops: SpectralRegionOp[] = [],
|
|
704
|
-
options: SpectralEditOptions & ValidateOptions = {},
|
|
705
|
-
): Float32Array {
|
|
706
|
-
const request: SpectralEditRequest =
|
|
707
|
-
samples instanceof Float32Array
|
|
708
|
-
? { samples, sampleRate: sampleRate as number, ops, ...options }
|
|
709
|
-
: samples;
|
|
710
|
-
assertSamples('spectralEdit', request.samples, request.validate !== false);
|
|
711
|
-
assertSampleRate('spectralEdit', request.sampleRate);
|
|
712
|
-
return requireModule().spectralEdit(
|
|
713
|
-
request.samples,
|
|
714
|
-
request.sampleRate,
|
|
715
|
-
request.ops ?? [],
|
|
716
|
-
request as unknown as Record<string, unknown>,
|
|
717
|
-
);
|
|
718
|
-
}
|