@codexo/exojs-audio-fx 0.15.3 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/AudioAnalyser.d.ts +4 -3
- package/dist/esm/AudioAnalyser.d.ts.map +1 -0
- package/dist/esm/AudioAnalyser.js +365 -468
- package/dist/esm/AudioAnalyser.js.map +1 -1
- package/dist/esm/BeatDetector.d.ts +16 -15
- package/dist/esm/BeatDetector.d.ts.map +1 -0
- package/dist/esm/BeatDetector.js +370 -428
- package/dist/esm/BeatDetector.js.map +1 -1
- package/dist/esm/dsp/fft.d.ts +5 -5
- package/dist/esm/dsp/fft.d.ts.map +1 -0
- package/dist/esm/dsp/mel.d.ts +6 -6
- package/dist/esm/dsp/mel.d.ts.map +1 -0
- package/dist/esm/dsp/mel.js +55 -64
- package/dist/esm/dsp/mel.js.map +1 -1
- package/dist/esm/dsp/tempogram.d.ts +60 -20
- package/dist/esm/dsp/tempogram.d.ts.map +1 -0
- package/dist/esm/effects/AutoWahEffect.d.ts +3 -2
- package/dist/esm/effects/AutoWahEffect.d.ts.map +1 -0
- package/dist/esm/effects/AutoWahEffect.js +210 -237
- package/dist/esm/effects/AutoWahEffect.js.map +1 -1
- package/dist/esm/effects/BitCrusherEffect.d.ts +3 -2
- package/dist/esm/effects/BitCrusherEffect.d.ts.map +1 -0
- package/dist/esm/effects/BitCrusherEffect.js +72 -70
- package/dist/esm/effects/BitCrusherEffect.js.map +1 -1
- package/dist/esm/effects/ChorusEffect.d.ts +2 -1
- package/dist/esm/effects/ChorusEffect.d.ts.map +1 -0
- package/dist/esm/effects/ChorusEffect.js +132 -150
- package/dist/esm/effects/ChorusEffect.js.map +1 -1
- package/dist/esm/effects/CompressorEffect.d.ts +2 -1
- package/dist/esm/effects/CompressorEffect.d.ts.map +1 -0
- package/dist/esm/effects/CompressorEffect.js +104 -118
- package/dist/esm/effects/CompressorEffect.js.map +1 -1
- package/dist/esm/effects/ConvolutionEffect.d.ts +10 -5
- package/dist/esm/effects/ConvolutionEffect.d.ts.map +1 -0
- package/dist/esm/effects/ConvolutionEffect.js +208 -189
- package/dist/esm/effects/ConvolutionEffect.js.map +1 -1
- package/dist/esm/effects/DelayEffect.d.ts +1 -0
- package/dist/esm/effects/DelayEffect.d.ts.map +1 -0
- package/dist/esm/effects/DelayEffect.js +105 -109
- package/dist/esm/effects/DelayEffect.js.map +1 -1
- package/dist/esm/effects/DistortionEffect.d.ts +4 -3
- package/dist/esm/effects/DistortionEffect.d.ts.map +1 -0
- package/dist/esm/effects/DistortionEffect.js +190 -195
- package/dist/esm/effects/DistortionEffect.js.map +1 -1
- package/dist/esm/effects/DuckingEffect.d.ts +3 -2
- package/dist/esm/effects/DuckingEffect.d.ts.map +1 -0
- package/dist/esm/effects/DuckingEffect.js +91 -172
- package/dist/esm/effects/DuckingEffect.js.map +1 -1
- package/dist/esm/effects/EqualizerEffect.d.ts +1 -0
- package/dist/esm/effects/EqualizerEffect.d.ts.map +1 -0
- package/dist/esm/effects/EqualizerEffect.js +120 -133
- package/dist/esm/effects/EqualizerEffect.js.map +1 -1
- package/dist/esm/effects/FlangerEffect.d.ts +7 -6
- package/dist/esm/effects/FlangerEffect.d.ts.map +1 -0
- package/dist/esm/effects/FlangerEffect.js +172 -201
- package/dist/esm/effects/FlangerEffect.js.map +1 -1
- package/dist/esm/effects/GranularEffect.d.ts +3 -2
- package/dist/esm/effects/GranularEffect.d.ts.map +1 -0
- package/dist/esm/effects/GranularEffect.js +100 -95
- package/dist/esm/effects/GranularEffect.js.map +1 -1
- package/dist/esm/effects/LimiterEffect.d.ts +1 -0
- package/dist/esm/effects/LimiterEffect.d.ts.map +1 -0
- package/dist/esm/effects/LimiterEffect.js +182 -194
- package/dist/esm/effects/LimiterEffect.js.map +1 -1
- package/dist/esm/effects/PhaserEffect.d.ts +2 -1
- package/dist/esm/effects/PhaserEffect.d.ts.map +1 -0
- package/dist/esm/effects/PhaserEffect.js +214 -254
- package/dist/esm/effects/PhaserEffect.js.map +1 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts +2 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts.map +1 -0
- package/dist/esm/effects/PingPongDelayEffect.js +172 -185
- package/dist/esm/effects/PingPongDelayEffect.js.map +1 -1
- package/dist/esm/effects/PitchShiftEffect.d.ts +3 -2
- package/dist/esm/effects/PitchShiftEffect.d.ts.map +1 -0
- package/dist/esm/effects/PitchShiftEffect.js +60 -60
- package/dist/esm/effects/PitchShiftEffect.js.map +1 -1
- package/dist/esm/effects/ReverbEffect.d.ts +2 -1
- package/dist/esm/effects/ReverbEffect.d.ts.map +1 -0
- package/dist/esm/effects/ReverbEffect.js +113 -117
- package/dist/esm/effects/ReverbEffect.js.map +1 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +4 -3
- package/dist/esm/effects/RingModulatorEffect.d.ts.map +1 -0
- package/dist/esm/effects/RingModulatorEffect.js +153 -161
- package/dist/esm/effects/RingModulatorEffect.js.map +1 -1
- package/dist/esm/effects/TremoloEffect.d.ts +1 -0
- package/dist/esm/effects/TremoloEffect.d.ts.map +1 -0
- package/dist/esm/effects/TremoloEffect.js +193 -201
- package/dist/esm/effects/TremoloEffect.js.map +1 -1
- package/dist/esm/effects/VocoderEffect.d.ts +2 -1
- package/dist/esm/effects/VocoderEffect.d.ts.map +1 -0
- package/dist/esm/effects/VocoderEffect.js +69 -80
- package/dist/esm/effects/VocoderEffect.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +23 -22
- package/dist/esm/worklets/beat-detector.worklet.js +5 -1162
- package/dist/esm/worklets/beat-detector.worklet.js.map +1 -1
- package/dist/esm/worklets/bit-crusher.worklet.js +5 -44
- package/dist/esm/worklets/bit-crusher.worklet.js.map +1 -1
- package/dist/esm/worklets/ducking.worklet.js +6 -0
- package/dist/esm/worklets/ducking.worklet.js.map +1 -0
- package/dist/esm/worklets/granular.worklet.js +5 -97
- package/dist/esm/worklets/granular.worklet.js.map +1 -1
- package/dist/esm/worklets/pitch-shift.worklet.js +5 -128
- package/dist/esm/worklets/pitch-shift.worklet.js.map +1 -1
- package/dist/esm/worklets/vocoder.worklet.js +5 -93
- package/dist/esm/worklets/vocoder.worklet.js.map +1 -1
- package/package.json +7 -7
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/worklets/beat-detector.worklet.d.ts +0 -1
- package/dist/esm/worklets/bit-crusher.worklet.d.ts +0 -1
- package/dist/esm/worklets/granular.worklet.d.ts +0 -1
- package/dist/esm/worklets/pitch-shift.worklet.d.ts +0 -1
- package/dist/esm/worklets/vocoder.worklet.d.ts +0 -1
|
@@ -1,99 +1,104 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import granular_worklet_default from "../worklets/granular.worklet.js";
|
|
2
|
+
import { WorkletEffect } from "@codexo/exojs";
|
|
3
3
|
|
|
4
|
+
//#region src/effects/GranularEffect.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
6
|
+
* Granular synthesis filter - slices input into small Hann-windowed grains
|
|
7
|
+
* and replays them with randomized parameters. Use cases:
|
|
8
|
+
*
|
|
9
|
+
* - Ambient texture: long grain (200ms+), low density (10-30/s), high
|
|
10
|
+
* spread, pitch range 0.5-1.5x. Creates evolving pad-like sounds.
|
|
11
|
+
* - Glitch: short grain (10-20ms), high density (100+/s), very high
|
|
12
|
+
* spread, pitch range 0.7-1.3x. Stuttering, lo-fi effects.
|
|
13
|
+
* - Time-stretch (low pitch with overlap): grain ~50ms, density 50/s,
|
|
14
|
+
* spread 0, pitch 1.0. Pseudo-stretches the input by buffering.
|
|
15
|
+
* - Pitch cloud: medium grain, medium density, pitchMin 0.5, pitchMax 2.0
|
|
16
|
+
* gives a "shimmer" effect of overlapping pitches.
|
|
17
|
+
*/
|
|
18
|
+
var GranularEffect = class extends WorkletEffect {
|
|
19
|
+
_grainSize;
|
|
20
|
+
_density;
|
|
21
|
+
_spread;
|
|
22
|
+
_pitchMin;
|
|
23
|
+
_pitchMax;
|
|
24
|
+
_bufferSeconds;
|
|
25
|
+
_normalizeGain;
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
super();
|
|
28
|
+
this._grainSize = Math.max(.005, Math.min(.5, options.grainSize ?? .05));
|
|
29
|
+
this._density = Math.max(1, Math.min(500, options.density ?? 50));
|
|
30
|
+
this._spread = Math.max(0, Math.min(1, options.spread ?? .5));
|
|
31
|
+
this._pitchMin = Math.max(.25, Math.min(4, options.pitchMin ?? 1));
|
|
32
|
+
this._pitchMax = Math.max(.25, Math.min(4, options.pitchMax ?? 1));
|
|
33
|
+
this._bufferSeconds = options.bufferSeconds ?? 2;
|
|
34
|
+
this._normalizeGain = options.normalizeGain ?? false;
|
|
35
|
+
this.wet = options.wet ?? 1;
|
|
36
|
+
}
|
|
37
|
+
get _workletName() {
|
|
38
|
+
return "exojs-granular";
|
|
39
|
+
}
|
|
40
|
+
get _workletSource() {
|
|
41
|
+
return granular_worklet_default;
|
|
42
|
+
}
|
|
43
|
+
get _workletOptions() {
|
|
44
|
+
return {
|
|
45
|
+
numberOfInputs: 1,
|
|
46
|
+
numberOfOutputs: 1,
|
|
47
|
+
processorOptions: {
|
|
48
|
+
bufferSeconds: this._bufferSeconds,
|
|
49
|
+
normalizeGain: this._normalizeGain
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
_onWorkletReady() {
|
|
54
|
+
this._setAudioParam("grainSize", this._grainSize);
|
|
55
|
+
this._setAudioParam("density", this._density);
|
|
56
|
+
this._setAudioParam("spread", this._spread);
|
|
57
|
+
this._setAudioParam("pitchMin", this._pitchMin);
|
|
58
|
+
this._setAudioParam("pitchMax", this._pitchMax);
|
|
59
|
+
}
|
|
60
|
+
/** Duration of each grain in seconds. Range 0.005..0.5, default 0.05. */
|
|
61
|
+
get grainSize() {
|
|
62
|
+
return this._grainSize;
|
|
63
|
+
}
|
|
64
|
+
set grainSize(value) {
|
|
65
|
+
this._grainSize = Math.max(.005, Math.min(.5, value));
|
|
66
|
+
this._setAudioParam("grainSize", this._grainSize);
|
|
67
|
+
}
|
|
68
|
+
/** Number of grains spawned per second. Range 1..500, default 50. */
|
|
69
|
+
get density() {
|
|
70
|
+
return this._density;
|
|
71
|
+
}
|
|
72
|
+
set density(value) {
|
|
73
|
+
this._density = Math.max(1, Math.min(500, value));
|
|
74
|
+
this._setAudioParam("density", this._density);
|
|
75
|
+
}
|
|
76
|
+
/** Random time-offset spread for grain start positions, 0..1. Higher values scatter grains further into the past. Default 0.5. */
|
|
77
|
+
get spread() {
|
|
78
|
+
return this._spread;
|
|
79
|
+
}
|
|
80
|
+
set spread(value) {
|
|
81
|
+
this._spread = Math.max(0, Math.min(1, value));
|
|
82
|
+
this._setAudioParam("spread", this._spread);
|
|
83
|
+
}
|
|
84
|
+
/** Minimum per-grain pitch ratio. Range 0.25..4, default 1.0. */
|
|
85
|
+
get pitchMin() {
|
|
86
|
+
return this._pitchMin;
|
|
87
|
+
}
|
|
88
|
+
set pitchMin(value) {
|
|
89
|
+
this._pitchMin = Math.max(.25, Math.min(4, value));
|
|
90
|
+
this._setAudioParam("pitchMin", this._pitchMin);
|
|
91
|
+
}
|
|
92
|
+
/** Maximum per-grain pitch ratio. Range 0.25..4, default 1.0. */
|
|
93
|
+
get pitchMax() {
|
|
94
|
+
return this._pitchMax;
|
|
95
|
+
}
|
|
96
|
+
set pitchMax(value) {
|
|
97
|
+
this._pitchMax = Math.max(.25, Math.min(4, value));
|
|
98
|
+
this._setAudioParam("pitchMax", this._pitchMax);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
97
101
|
|
|
102
|
+
//#endregion
|
|
98
103
|
export { GranularEffect };
|
|
99
|
-
//# sourceMappingURL=GranularEffect.js.map
|
|
104
|
+
//# sourceMappingURL=GranularEffect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GranularEffect.js","sources":["
|
|
1
|
+
{"version":3,"file":"GranularEffect.js","names":["granularWorkletSource"],"sources":["../../../src/effects/GranularEffect.ts"],"sourcesContent":["import { WorkletEffect } from '@codexo/exojs';\n\nimport granularWorkletSource from '../worklets/granular.worklet.ts?worklet';\n\nexport interface GranularEffectOptions {\n /** Grain size in seconds. 0.005-0.5. Default 0.05 (50ms). */\n grainSize?: number;\n /** Grains per second (overlap density). 1-500. Default 50. */\n density?: number;\n /** Random offset spread, 0-1. Higher = wider time-window scatter. Default 0.5. */\n spread?: number;\n /** Minimum random pitch ratio per grain. Default 1.0. */\n pitchMin?: number;\n /** Maximum random pitch ratio per grain. Default 1.0. */\n pitchMax?: number;\n /** Dry/wet mix, 0..1. Default 1.0. */\n wet?: number;\n /** Internal circular-buffer length in seconds. Compile-time, not runtime. Default 2. */\n bufferSeconds?: number;\n /**\n * Compensate the density/grainSize-dependent loudness so the wet level stays\n * roughly constant (near unity) instead of rising with overlap. Compile-time,\n * not runtime. Default `false`, which preserves granular's expressive level\n * dynamics - enable it when you want a predictable, density-independent level.\n */\n normalizeGain?: boolean;\n}\n\n/**\n * Granular synthesis filter - slices input into small Hann-windowed grains\n * and replays them with randomized parameters. Use cases:\n *\n * - Ambient texture: long grain (200ms+), low density (10-30/s), high\n * spread, pitch range 0.5-1.5x. Creates evolving pad-like sounds.\n * - Glitch: short grain (10-20ms), high density (100+/s), very high\n * spread, pitch range 0.7-1.3x. Stuttering, lo-fi effects.\n * - Time-stretch (low pitch with overlap): grain ~50ms, density 50/s,\n * spread 0, pitch 1.0. Pseudo-stretches the input by buffering.\n * - Pitch cloud: medium grain, medium density, pitchMin 0.5, pitchMax 2.0\n * gives a \"shimmer\" effect of overlapping pitches.\n */\nexport class GranularEffect extends WorkletEffect {\n private _grainSize: number;\n private _density: number;\n private _spread: number;\n private _pitchMin: number;\n private _pitchMax: number;\n private readonly _bufferSeconds: number;\n private readonly _normalizeGain: boolean;\n\n public constructor(options: GranularEffectOptions = {}) {\n super();\n this._grainSize = Math.max(0.005, Math.min(0.5, options.grainSize ?? 0.05));\n this._density = Math.max(1, Math.min(500, options.density ?? 50));\n this._spread = Math.max(0, Math.min(1, options.spread ?? 0.5));\n this._pitchMin = Math.max(0.25, Math.min(4, options.pitchMin ?? 1));\n this._pitchMax = Math.max(0.25, Math.min(4, options.pitchMax ?? 1));\n this._bufferSeconds = options.bufferSeconds ?? 2;\n this._normalizeGain = options.normalizeGain ?? false;\n this.wet = options.wet ?? 1;\n }\n\n protected get _workletName(): string {\n return 'exojs-granular';\n }\n protected get _workletSource(): string {\n return granularWorkletSource;\n }\n protected override get _workletOptions(): AudioWorkletNodeOptions {\n return {\n numberOfInputs: 1,\n numberOfOutputs: 1,\n processorOptions: { bufferSeconds: this._bufferSeconds, normalizeGain: this._normalizeGain },\n };\n }\n\n protected override _onWorkletReady(): void {\n this._setAudioParam('grainSize', this._grainSize);\n this._setAudioParam('density', this._density);\n this._setAudioParam('spread', this._spread);\n this._setAudioParam('pitchMin', this._pitchMin);\n this._setAudioParam('pitchMax', this._pitchMax);\n }\n\n /** Duration of each grain in seconds. Range 0.005..0.5, default 0.05. */\n public get grainSize(): number {\n return this._grainSize;\n }\n public set grainSize(value: number) {\n this._grainSize = Math.max(0.005, Math.min(0.5, value));\n this._setAudioParam('grainSize', this._grainSize);\n }\n\n /** Number of grains spawned per second. Range 1..500, default 50. */\n public get density(): number {\n return this._density;\n }\n public set density(value: number) {\n this._density = Math.max(1, Math.min(500, value));\n this._setAudioParam('density', this._density);\n }\n\n /** Random time-offset spread for grain start positions, 0..1. Higher values scatter grains further into the past. Default 0.5. */\n public get spread(): number {\n return this._spread;\n }\n public set spread(value: number) {\n this._spread = Math.max(0, Math.min(1, value));\n this._setAudioParam('spread', this._spread);\n }\n\n /** Minimum per-grain pitch ratio. Range 0.25..4, default 1.0. */\n public get pitchMin(): number {\n return this._pitchMin;\n }\n public set pitchMin(value: number) {\n this._pitchMin = Math.max(0.25, Math.min(4, value));\n this._setAudioParam('pitchMin', this._pitchMin);\n }\n\n /** Maximum per-grain pitch ratio. Range 0.25..4, default 1.0. */\n public get pitchMax(): number {\n return this._pitchMax;\n }\n public set pitchMax(value: number) {\n this._pitchMax = Math.max(0.25, Math.min(4, value));\n this._setAudioParam('pitch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
|
-
import { AudioEffect,
|
|
1
|
+
import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
|
|
2
2
|
|
|
3
|
+
//#region src/effects/LimiterEffect.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
compressor.knee.setValueAtTime(this._knee, ctx.currentTime);
|
|
183
|
-
compressor.threshold.setValueAtTime(this._threshold, ctx.currentTime);
|
|
184
|
-
compressor.attack.setValueAtTime(this._attack, ctx.currentTime);
|
|
185
|
-
compressor.release.setValueAtTime(this._release, ctx.currentTime);
|
|
186
|
-
// Dry path: input → dryGain → output
|
|
187
|
-
inputGain.connect(dryGain);
|
|
188
|
-
dryGain.connect(outputGain);
|
|
189
|
-
// Wet path: input → compressor → wetGain → output
|
|
190
|
-
inputGain.connect(compressor);
|
|
191
|
-
compressor.connect(wetGain);
|
|
192
|
-
wetGain.connect(outputGain);
|
|
193
|
-
this._setup = { inputGain, outputGain, compressor, dryGain, wetGain };
|
|
194
|
-
}
|
|
195
|
-
}
|
|
5
|
+
* Brick-wall limiter backed by a Web Audio `DynamicsCompressorNode` configured
|
|
6
|
+
* for hard limiting: a fixed high ratio (~20), zero knee (hard knee), and a
|
|
7
|
+
* fast attack. Use it as a final-chain safety net to prevent clipping and
|
|
8
|
+
* protect downstream output.
|
|
9
|
+
*
|
|
10
|
+
* The compressor `ratio` and `knee` default to brick-wall values (20 and 0
|
|
11
|
+
* respectively) but remain configurable, unlike a truly fixed limiter,
|
|
12
|
+
* because callers occasionally want a softer, more compressor-like limiting
|
|
13
|
+
* curve (lower ratio) or a gentler transition into limiting (larger knee)
|
|
14
|
+
* without switching to {@link CompressorEffect} and losing the dry/wet mix.
|
|
15
|
+
* The effect also exposes a dry/wet mix for API consistency and parallel
|
|
16
|
+
* processing workflows, though a fully-wet signal (`wet = 1`) is the typical
|
|
17
|
+
* configuration.
|
|
18
|
+
*
|
|
19
|
+
* Node graph:
|
|
20
|
+
* ```
|
|
21
|
+
* input(GainNode) → dryGain → output(GainNode)
|
|
22
|
+
* input → compressor → wetGain → output
|
|
23
|
+
* ```
|
|
24
|
+
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const limiter = new LimiterEffect({ threshold: -3, release: 0.1 });
|
|
29
|
+
* masterBus.addEffect(limiter);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
var LimiterEffect = class extends AudioEffect {
|
|
33
|
+
_setup = null;
|
|
34
|
+
_threshold;
|
|
35
|
+
_attack;
|
|
36
|
+
_release;
|
|
37
|
+
_wet;
|
|
38
|
+
_ratio;
|
|
39
|
+
_knee;
|
|
40
|
+
_onAudioContextReady = (ctx) => {
|
|
41
|
+
onAudioContextReady.remove(this._onAudioContextReady);
|
|
42
|
+
this._setupNodes(ctx);
|
|
43
|
+
};
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
super();
|
|
46
|
+
this._threshold = Math.max(-60, Math.min(0, options.threshold ?? -3));
|
|
47
|
+
this._attack = Math.max(0, Math.min(1, options.attack ?? .003));
|
|
48
|
+
this._release = Math.max(0, Math.min(1, options.release ?? .25));
|
|
49
|
+
this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
|
|
50
|
+
this._ratio = Math.max(1, Math.min(20, options.ratio ?? 20));
|
|
51
|
+
this._knee = Math.max(0, Math.min(40, options.knee ?? 0));
|
|
52
|
+
if (isAudioContextReady()) this._setupNodes(getAudioContext());
|
|
53
|
+
else onAudioContextReady.add(this._onAudioContextReady);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The node where audio enters this effect. Throws if the audio context is
|
|
57
|
+
* not yet initialized.
|
|
58
|
+
*/
|
|
59
|
+
get inputNode() {
|
|
60
|
+
if (!this._setup) throw new Error("LimiterEffect not yet initialized.");
|
|
61
|
+
return this._setup.inputGain;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The node where audio exits this effect. Throws if the audio context is
|
|
65
|
+
* not yet initialized.
|
|
66
|
+
*/
|
|
67
|
+
get outputNode() {
|
|
68
|
+
if (!this._setup) throw new Error("LimiterEffect not yet initialized.");
|
|
69
|
+
return this._setup.outputGain;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Threshold in dBFS above which limiting is applied. Range −60..0, default −3.
|
|
73
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
74
|
+
*/
|
|
75
|
+
get threshold() {
|
|
76
|
+
return this._threshold;
|
|
77
|
+
}
|
|
78
|
+
set threshold(value) {
|
|
79
|
+
this._threshold = Math.max(-60, Math.min(0, value));
|
|
80
|
+
if (this._setup) this._setup.compressor.threshold.setTargetAtTime(this._threshold, this._setup.compressor.context.currentTime, .01);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Attack time in seconds for the limiter to engage. Range 0..1, default 0.003.
|
|
84
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
85
|
+
*/
|
|
86
|
+
get attack() {
|
|
87
|
+
return this._attack;
|
|
88
|
+
}
|
|
89
|
+
set attack(value) {
|
|
90
|
+
this._attack = Math.max(0, Math.min(1, value));
|
|
91
|
+
if (this._setup) this._setup.compressor.attack.setTargetAtTime(this._attack, this._setup.compressor.context.currentTime, .01);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Release time in seconds for the limiter to disengage. Range 0..1, default 0.25.
|
|
95
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
96
|
+
*/
|
|
97
|
+
get release() {
|
|
98
|
+
return this._release;
|
|
99
|
+
}
|
|
100
|
+
set release(value) {
|
|
101
|
+
this._release = Math.max(0, Math.min(1, value));
|
|
102
|
+
if (this._setup) this._setup.compressor.release.setTargetAtTime(this._release, this._setup.compressor.context.currentTime, .01);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Input-to-output dB ratio above the threshold. Range 1..20, default 20
|
|
106
|
+
* (brick-wall). Lower for a softer, more compressor-like limiter.
|
|
107
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
108
|
+
*/
|
|
109
|
+
get ratio() {
|
|
110
|
+
return this._ratio;
|
|
111
|
+
}
|
|
112
|
+
set ratio(value) {
|
|
113
|
+
this._ratio = Math.max(1, Math.min(20, value));
|
|
114
|
+
if (this._setup) this._setup.compressor.ratio.setTargetAtTime(this._ratio, this._setup.compressor.context.currentTime, .01);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Width in dB of the transition region around the threshold (soft knee).
|
|
118
|
+
* Range 0..40, default 0 (hard knee). Raise for a gentler transition into
|
|
119
|
+
* limiting. Changes are ramped smoothly via `setTargetAtTime`.
|
|
120
|
+
*/
|
|
121
|
+
get knee() {
|
|
122
|
+
return this._knee;
|
|
123
|
+
}
|
|
124
|
+
set knee(value) {
|
|
125
|
+
this._knee = Math.max(0, Math.min(40, value));
|
|
126
|
+
if (this._setup) this._setup.compressor.knee.setTargetAtTime(this._knee, this._setup.compressor.context.currentTime, .01);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Dry/wet mix level, 0..1. The dry level is automatically `1 - wet`.
|
|
130
|
+
* Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
|
|
131
|
+
*/
|
|
132
|
+
get wet() {
|
|
133
|
+
return this._wet;
|
|
134
|
+
}
|
|
135
|
+
set wet(value) {
|
|
136
|
+
this._wet = Math.max(0, Math.min(1, value));
|
|
137
|
+
if (this._setup) {
|
|
138
|
+
const ctx = this._setup.wetGain.context;
|
|
139
|
+
this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
|
|
140
|
+
this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
destroy() {
|
|
144
|
+
onAudioContextReady.remove(this._onAudioContextReady);
|
|
145
|
+
if (this._setup) {
|
|
146
|
+
this._setup.inputGain.disconnect();
|
|
147
|
+
this._setup.compressor.disconnect();
|
|
148
|
+
this._setup.dryGain.disconnect();
|
|
149
|
+
this._setup.wetGain.disconnect();
|
|
150
|
+
this._setup.outputGain.disconnect();
|
|
151
|
+
this._setup = null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
_setupNodes(ctx) {
|
|
155
|
+
const inputGain = ctx.createGain();
|
|
156
|
+
const outputGain = ctx.createGain();
|
|
157
|
+
const compressor = ctx.createDynamicsCompressor();
|
|
158
|
+
const dryGain = ctx.createGain();
|
|
159
|
+
const wetGain = ctx.createGain();
|
|
160
|
+
inputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
161
|
+
outputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
162
|
+
dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
|
|
163
|
+
wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
|
|
164
|
+
compressor.ratio.setValueAtTime(this._ratio, ctx.currentTime);
|
|
165
|
+
compressor.knee.setValueAtTime(this._knee, ctx.currentTime);
|
|
166
|
+
compressor.threshold.setValueAtTime(this._threshold, ctx.currentTime);
|
|
167
|
+
compressor.attack.setValueAtTime(this._attack, ctx.currentTime);
|
|
168
|
+
compressor.release.setValueAtTime(this._release, ctx.currentTime);
|
|
169
|
+
inputGain.connect(dryGain);
|
|
170
|
+
dryGain.connect(outputGain);
|
|
171
|
+
inputGain.connect(compressor);
|
|
172
|
+
compressor.connect(wetGain);
|
|
173
|
+
wetGain.connect(outputGain);
|
|
174
|
+
this._setup = {
|
|
175
|
+
inputGain,
|
|
176
|
+
outputGain,
|
|
177
|
+
compressor,
|
|
178
|
+
dryGain,
|
|
179
|
+
wetGain
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
196
183
|
|
|
184
|
+
//#endregion
|
|
197
185
|
export { LimiterEffect };
|
|
198
|
-
//# sourceMappingURL=LimiterEffect.js.map
|
|
186
|
+
//# sourceMappingURL=LimiterEffect.js.map
|