@codexo/exojs-audio-fx 0.19.0 → 0.20.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/README.md +7 -53
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +12 -20
- package/dist/esm/AudioAnalyser.d.ts +0 -125
- package/dist/esm/AudioAnalyser.d.ts.map +0 -1
- package/dist/esm/AudioAnalyser.js +0 -369
- package/dist/esm/AudioAnalyser.js.map +0 -1
- package/dist/esm/BeatDetector.d.ts +0 -286
- package/dist/esm/BeatDetector.d.ts.map +0 -1
- package/dist/esm/BeatDetector.js +0 -419
- package/dist/esm/BeatDetector.js.map +0 -1
- package/dist/esm/PcmStreamSource.d.ts +0 -127
- package/dist/esm/PcmStreamSource.d.ts.map +0 -1
- package/dist/esm/PcmStreamSource.js +0 -308
- package/dist/esm/PcmStreamSource.js.map +0 -1
- package/dist/esm/dsp/fft.d.ts +0 -22
- package/dist/esm/dsp/fft.d.ts.map +0 -1
- package/dist/esm/dsp/mel.d.ts +0 -43
- package/dist/esm/dsp/mel.d.ts.map +0 -1
- package/dist/esm/dsp/mel.js +0 -61
- package/dist/esm/dsp/mel.js.map +0 -1
- package/dist/esm/dsp/tempogram.d.ts +0 -192
- package/dist/esm/dsp/tempogram.d.ts.map +0 -1
- package/dist/esm/effects/AutoWahEffect.d.ts +0 -128
- package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
- package/dist/esm/effects/AutoWahEffect.js +0 -214
- package/dist/esm/effects/AutoWahEffect.js.map +0 -1
- package/dist/esm/effects/BitCrusherEffect.d.ts +0 -64
- package/dist/esm/effects/BitCrusherEffect.d.ts.map +0 -1
- package/dist/esm/effects/BitCrusherEffect.js +0 -76
- package/dist/esm/effects/BitCrusherEffect.js.map +0 -1
- package/dist/esm/effects/ChorusEffect.d.ts +0 -54
- package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
- package/dist/esm/effects/ChorusEffect.js +0 -136
- package/dist/esm/effects/ChorusEffect.js.map +0 -1
- package/dist/esm/effects/CompressorEffect.d.ts +0 -56
- package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
- package/dist/esm/effects/CompressorEffect.js +0 -108
- package/dist/esm/effects/CompressorEffect.js.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.d.ts +0 -119
- package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.js +0 -212
- package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
- package/dist/esm/effects/DelayEffect.d.ts +0 -36
- package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/DelayEffect.js +0 -109
- package/dist/esm/effects/DelayEffect.js.map +0 -1
- package/dist/esm/effects/DistortionEffect.d.ts +0 -120
- package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
- package/dist/esm/effects/DistortionEffect.js +0 -194
- package/dist/esm/effects/DistortionEffect.js.map +0 -1
- package/dist/esm/effects/DuckingEffect.d.ts +0 -44
- package/dist/esm/effects/DuckingEffect.d.ts.map +0 -1
- package/dist/esm/effects/DuckingEffect.js +0 -95
- package/dist/esm/effects/DuckingEffect.js.map +0 -1
- package/dist/esm/effects/EqualizerEffect.d.ts +0 -51
- package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
- package/dist/esm/effects/EqualizerEffect.js +0 -124
- package/dist/esm/effects/EqualizerEffect.js.map +0 -1
- package/dist/esm/effects/FlangerEffect.d.ts +0 -99
- package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
- package/dist/esm/effects/FlangerEffect.js +0 -176
- package/dist/esm/effects/FlangerEffect.js.map +0 -1
- package/dist/esm/effects/GranularEffect.d.ts +0 -67
- package/dist/esm/effects/GranularEffect.d.ts.map +0 -1
- package/dist/esm/effects/GranularEffect.js +0 -104
- package/dist/esm/effects/GranularEffect.js.map +0 -1
- package/dist/esm/effects/LimiterEffect.d.ts +0 -125
- package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
- package/dist/esm/effects/LimiterEffect.js +0 -186
- package/dist/esm/effects/LimiterEffect.js.map +0 -1
- package/dist/esm/effects/PhaserEffect.d.ts +0 -127
- package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
- package/dist/esm/effects/PhaserEffect.js +0 -218
- package/dist/esm/effects/PhaserEffect.js.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -84
- package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.js +0 -176
- package/dist/esm/effects/PingPongDelayEffect.js.map +0 -1
- package/dist/esm/effects/PitchShiftEffect.d.ts +0 -46
- package/dist/esm/effects/PitchShiftEffect.d.ts.map +0 -1
- package/dist/esm/effects/PitchShiftEffect.js +0 -64
- package/dist/esm/effects/PitchShiftEffect.js.map +0 -1
- package/dist/esm/effects/ReverbEffect.d.ts +0 -38
- package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
- package/dist/esm/effects/ReverbEffect.js +0 -117
- package/dist/esm/effects/ReverbEffect.js.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +0 -96
- package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.js +0 -157
- package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
- package/dist/esm/effects/TremoloEffect.d.ts +0 -111
- package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
- package/dist/esm/effects/TremoloEffect.js +0 -197
- package/dist/esm/effects/TremoloEffect.js.map +0 -1
- package/dist/esm/effects/VocoderEffect.d.ts +0 -45
- package/dist/esm/effects/VocoderEffect.d.ts.map +0 -1
- package/dist/esm/effects/VocoderEffect.js +0 -73
- package/dist/esm/effects/VocoderEffect.js.map +0 -1
- package/dist/esm/index.d.ts +0 -25
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -24
- package/dist/esm/worklets/beat-detector.worklet.js +0 -6
- package/dist/esm/worklets/beat-detector.worklet.js.map +0 -1
- package/dist/esm/worklets/bit-crusher.worklet.js +0 -6
- package/dist/esm/worklets/bit-crusher.worklet.js.map +0 -1
- package/dist/esm/worklets/ducking.worklet.js +0 -6
- package/dist/esm/worklets/ducking.worklet.js.map +0 -1
- package/dist/esm/worklets/granular.worklet.js +0 -6
- package/dist/esm/worklets/granular.worklet.js.map +0 -1
- package/dist/esm/worklets/pcm-stream.worklet.js +0 -6
- package/dist/esm/worklets/pcm-stream.worklet.js.map +0 -1
- package/dist/esm/worklets/pitch-shift.worklet.js +0 -6
- package/dist/esm/worklets/pitch-shift.worklet.js.map +0 -1
- package/dist/esm/worklets/vocoder.worklet.js +0 -6
- package/dist/esm/worklets/vocoder.worklet.js.map +0 -1
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
|
|
2
|
-
|
|
3
|
-
//#region src/effects/DistortionEffect.ts
|
|
4
|
-
/**
|
|
5
|
-
* Distortion effect built from native Web Audio nodes - no worklet required.
|
|
6
|
-
*
|
|
7
|
-
* The input signal is split into a dry path and a wet path. The wet path runs
|
|
8
|
-
* through a `WaveShaperNode` loaded with a tanh-based soft-clip curve, then
|
|
9
|
-
* through a `BiquadFilterNode` (lowpass) acting as a tone control, before
|
|
10
|
-
* being mixed back with the dry signal. The wave-shaper curve is rebuilt any
|
|
11
|
-
* time `drive` changes. Oversampling is delegated directly to
|
|
12
|
-
* `WaveShaperNode.oversample`.
|
|
13
|
-
*
|
|
14
|
-
* Node graph:
|
|
15
|
-
* ```
|
|
16
|
-
* input(GainNode) ──── dryGain ─────────────────────────── output(GainNode)
|
|
17
|
-
* input ──── waveShaper ── toneFilter ── wetGain ── output
|
|
18
|
-
* ```
|
|
19
|
-
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const dist = new DistortionEffect({ drive: 0.7, wet: 0.9, tone: 0.6 });
|
|
24
|
-
* bus.addEffect(dist);
|
|
25
|
-
*
|
|
26
|
-
* // Soften the drive at runtime:
|
|
27
|
-
* dist.drive = 0.3;
|
|
28
|
-
*
|
|
29
|
-
* // Open the tone filter fully:
|
|
30
|
-
* dist.tone = 1;
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
var DistortionEffect = class DistortionEffect extends AudioEffect {
|
|
34
|
-
_setup = null;
|
|
35
|
-
_drive;
|
|
36
|
-
_wet;
|
|
37
|
-
_oversample;
|
|
38
|
-
_tone;
|
|
39
|
-
_onAudioContextReady = (ctx) => {
|
|
40
|
-
onAudioContextReady.remove(this._onAudioContextReady);
|
|
41
|
-
this._setupNodes(ctx);
|
|
42
|
-
};
|
|
43
|
-
constructor(options = {}) {
|
|
44
|
-
super();
|
|
45
|
-
this._drive = Math.max(0, Math.min(1, options.drive ?? .4));
|
|
46
|
-
this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
|
|
47
|
-
this._oversample = options.oversample ?? "2x";
|
|
48
|
-
this._tone = Math.max(0, Math.min(1, options.tone ?? 1));
|
|
49
|
-
if (isAudioContextReady()) this._setupNodes(getAudioContext());
|
|
50
|
-
else onAudioContextReady.add(this._onAudioContextReady);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* The node where audio enters this effect. Throws if the audio context is
|
|
54
|
-
* not yet initialized.
|
|
55
|
-
*/
|
|
56
|
-
get inputNode() {
|
|
57
|
-
if (!this._setup) throw new Error("DistortionEffect not yet initialized.");
|
|
58
|
-
return this._setup.inputGain;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The node where audio exits this effect. Throws if the audio context is
|
|
62
|
-
* not yet initialized.
|
|
63
|
-
*/
|
|
64
|
-
get outputNode() {
|
|
65
|
-
if (!this._setup) throw new Error("DistortionEffect not yet initialized.");
|
|
66
|
-
return this._setup.outputGain;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Drive amount controlling the soft-clip intensity. Range 0..1, default 0.4.
|
|
70
|
-
* Changing this rebuilds the wave-shaper curve immediately (sample-accurate
|
|
71
|
-
* on the next render quantum).
|
|
72
|
-
*/
|
|
73
|
-
get drive() {
|
|
74
|
-
return this._drive;
|
|
75
|
-
}
|
|
76
|
-
set drive(value) {
|
|
77
|
-
this._drive = Math.max(0, Math.min(1, value));
|
|
78
|
-
if (this._setup) this._setup.waveShaper.curve = DistortionEffect._buildCurve(this._drive);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Wet (distorted) mix level, 0..1. The dry level is automatically `1 - wet`.
|
|
82
|
-
* Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
|
|
83
|
-
*/
|
|
84
|
-
get wet() {
|
|
85
|
-
return this._wet;
|
|
86
|
-
}
|
|
87
|
-
set wet(value) {
|
|
88
|
-
this._wet = Math.max(0, Math.min(1, value));
|
|
89
|
-
if (this._setup) {
|
|
90
|
-
const ctx = this._setup.wetGain.context;
|
|
91
|
-
this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
|
|
92
|
-
this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Oversampling mode for the `WaveShaperNode`. One of `'none'`, `'2x'`, or
|
|
97
|
-
* `'4x'`. Higher values reduce aliasing but increase CPU usage. Default `'2x'`.
|
|
98
|
-
*/
|
|
99
|
-
get oversample() {
|
|
100
|
-
return this._oversample;
|
|
101
|
-
}
|
|
102
|
-
set oversample(value) {
|
|
103
|
-
this._oversample = value;
|
|
104
|
-
if (this._setup) this._setup.waveShaper.oversample = this._oversample;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Tone control: low-pass cutoff on the wet path. 0 = fully dark (~100 Hz),
|
|
108
|
-
* 1 = fully open (~20 kHz). Mapped logarithmically. Default 1.
|
|
109
|
-
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
110
|
-
*/
|
|
111
|
-
get tone() {
|
|
112
|
-
return this._tone;
|
|
113
|
-
}
|
|
114
|
-
set tone(value) {
|
|
115
|
-
this._tone = Math.max(0, Math.min(1, value));
|
|
116
|
-
if (this._setup) {
|
|
117
|
-
const ctx = this._setup.toneFilter.context;
|
|
118
|
-
this._setup.toneFilter.frequency.setTargetAtTime(DistortionEffect._toneToFrequency(this._tone), ctx.currentTime, .01);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
destroy() {
|
|
122
|
-
onAudioContextReady.remove(this._onAudioContextReady);
|
|
123
|
-
if (this._setup) {
|
|
124
|
-
this._setup.inputGain.disconnect();
|
|
125
|
-
this._setup.waveShaper.disconnect();
|
|
126
|
-
this._setup.toneFilter.disconnect();
|
|
127
|
-
this._setup.dryGain.disconnect();
|
|
128
|
-
this._setup.wetGain.disconnect();
|
|
129
|
-
this._setup.outputGain.disconnect();
|
|
130
|
-
this._setup = null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Build a 256-point tanh-based soft-clip curve for the given drive (0..1).
|
|
135
|
-
*
|
|
136
|
-
* Maps drive to a distortion amount `a = drive * 400 + 1`, then fills the
|
|
137
|
-
* curve with `tanh(x * a) / tanh(a)` so that the output is always bounded
|
|
138
|
-
* to [-1, 1]. At drive=0, `a = 1` and the curve is `tanh(x) / tanh(1)`,
|
|
139
|
-
* which has a small-signal gain of `1/tanh(1) ≈ 1.31` - not perfectly
|
|
140
|
-
* linear. At drive=1, `a = 401` and the curve approximates a hard-clipper.
|
|
141
|
-
*/
|
|
142
|
-
static _buildCurve(drive) {
|
|
143
|
-
const n = 256;
|
|
144
|
-
const curve = new Float32Array(n);
|
|
145
|
-
const amount = drive * 400 + 1;
|
|
146
|
-
const norm = Math.tanh(amount);
|
|
147
|
-
for (let i = 0; i < n; i++) {
|
|
148
|
-
const x = i * 2 / 255 - 1;
|
|
149
|
-
curve[i] = Math.tanh(x * amount) / norm;
|
|
150
|
-
}
|
|
151
|
-
return curve;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Map tone (0..1) to a low-pass cutoff frequency in Hz.
|
|
155
|
-
* Logarithmic scale: 100 Hz at tone=0, 20 000 Hz at tone=1.
|
|
156
|
-
*/
|
|
157
|
-
static _toneToFrequency(tone) {
|
|
158
|
-
return 100 * Math.pow(200, tone);
|
|
159
|
-
}
|
|
160
|
-
_setupNodes(ctx) {
|
|
161
|
-
const inputGain = ctx.createGain();
|
|
162
|
-
const outputGain = ctx.createGain();
|
|
163
|
-
const dryGain = ctx.createGain();
|
|
164
|
-
const wetGain = ctx.createGain();
|
|
165
|
-
const waveShaper = ctx.createWaveShaper();
|
|
166
|
-
const toneFilter = ctx.createBiquadFilter();
|
|
167
|
-
inputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
168
|
-
outputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
169
|
-
dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
|
|
170
|
-
wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
|
|
171
|
-
waveShaper.curve = DistortionEffect._buildCurve(this._drive);
|
|
172
|
-
waveShaper.oversample = this._oversample;
|
|
173
|
-
toneFilter.type = "lowpass";
|
|
174
|
-
toneFilter.frequency.setValueAtTime(DistortionEffect._toneToFrequency(this._tone), ctx.currentTime);
|
|
175
|
-
inputGain.connect(dryGain);
|
|
176
|
-
dryGain.connect(outputGain);
|
|
177
|
-
inputGain.connect(waveShaper);
|
|
178
|
-
waveShaper.connect(toneFilter);
|
|
179
|
-
toneFilter.connect(wetGain);
|
|
180
|
-
wetGain.connect(outputGain);
|
|
181
|
-
this._setup = {
|
|
182
|
-
inputGain,
|
|
183
|
-
outputGain,
|
|
184
|
-
dryGain,
|
|
185
|
-
wetGain,
|
|
186
|
-
waveShaper,
|
|
187
|
-
toneFilter
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
//#endregion
|
|
193
|
-
export { DistortionEffect };
|
|
194
|
-
//# sourceMappingURL=DistortionEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DistortionEffect.js","names":[],"sources":["../../../src/effects/DistortionEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link DistortionEffect}. */\nexport interface DistortionEffectOptions {\n /**\n * Drive amount: controls the intensity of the tanh soft-clip curve.\n * Range 0..1, default 0.4. Higher values produce heavier, more saturated\n * distortion; lower values produce a milder soft-clip. Note that even at\n * drive=0 the curve is not perfectly linear - the formula\n * `tanh(x) / tanh(1)` has a gain of `1/tanh(1) ≈ 1.31` at the origin.\n */\n drive?: number;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.0.\n */\n wet?: number;\n /**\n * Oversampling mode applied by the `WaveShaperNode`. Higher oversampling\n * reduces aliasing artifacts at the cost of extra CPU. One of `'none'`,\n * `'2x'`, or `'4x'`. Default `'2x'`.\n */\n oversample?: OverSampleType;\n /**\n * Tone control: cutoff of a post-distortion low-pass filter on the wet path.\n * Mapped logarithmically from 100 Hz (tone=0, fully dark) to 20 kHz\n * (tone=1, fully open). Range 0..1, default 1.\n */\n tone?: number;\n}\n\ninterface DistortionEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly waveShaper: WaveShaperNode;\n readonly toneFilter: BiquadFilterNode;\n}\n\n/**\n * Distortion effect built from native Web Audio nodes - no worklet required.\n *\n * The input signal is split into a dry path and a wet path. The wet path runs\n * through a `WaveShaperNode` loaded with a tanh-based soft-clip curve, then\n * through a `BiquadFilterNode` (lowpass) acting as a tone control, before\n * being mixed back with the dry signal. The wave-shaper curve is rebuilt any\n * time `drive` changes. Oversampling is delegated directly to\n * `WaveShaperNode.oversample`.\n *\n * Node graph:\n * ```\n * input(GainNode) ──── dryGain ─────────────────────────── output(GainNode)\n * input ──── waveShaper ── toneFilter ── wetGain ── output\n * ```\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.\n *\n * @example\n * ```ts\n * const dist = new DistortionEffect({ drive: 0.7, wet: 0.9, tone: 0.6 });\n * bus.addEffect(dist);\n *\n * // Soften the drive at runtime:\n * dist.drive = 0.3;\n *\n * // Open the tone filter fully:\n * dist.tone = 1;\n * ```\n */\nexport class DistortionEffect extends AudioEffect {\n private _setup: DistortionEffectSetup | null = null;\n private _drive: number;\n private _wet: number;\n private _oversample: OverSampleType;\n private _tone: number;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\n\n public constructor(options: DistortionEffectOptions = {}) {\n super();\n this._drive = Math.max(0, Math.min(1, options.drive ?? 0.4));\n this._wet = Math.max(0, Math.min(1, options.wet ?? 1));\n this._oversample = options.oversample ?? '2x';\n this._tone = Math.max(0, Math.min(1, options.tone ?? 1));\n if (isAudioContextReady()) {\n this._setupNodes(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\n }\n\n /**\n * The node where audio enters this effect. Throws if the audio context is\n * not yet initialized.\n */\n public get inputNode(): AudioNode {\n if (!this._setup) throw new Error('DistortionEffect not yet initialized.');\n return this._setup.inputGain;\n }\n\n /**\n * The node where audio exits this effect. Throws if the audio context is\n * not yet initialized.\n */\n public get outputNode(): AudioNode {\n if (!this._setup) throw new Error('DistortionEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n /**\n * Drive amount controlling the soft-clip intensity. Range 0..1, default 0.4.\n * Changing this rebuilds the wave-shaper curve immediately (sample-accurate\n * on the next render quantum).\n */\n public get drive(): number {\n return this._drive;\n }\n\n public set drive(value: number) {\n this._drive = Math.max(0, Math.min(1, value));\n if (this._setup) {\n this._setup.waveShaper.curve = DistortionEffect._buildCurve(this._drive);\n }\n }\n\n /**\n * Wet (distorted) mix level, 0..1. The dry level is automatically `1 - wet`.\n * Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.\n */\n public get wet(): number {\n return this._wet;\n }\n\n public set wet(value: number) {\n this._wet = Math.max(0, Math.min(1, value));\n if (this._setup) {\n const ctx = this._setup.wetGain.context;\n this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, 0.01);\n this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, 0.01);\n }\n }\n\n /**\n * Oversampling mode for the `WaveShaperNode`. One of `'none'`, `'2x'`, or\n * `'4x'`. Higher values reduce aliasing but increase CPU usage. Default `'2x'`.\n */\n public get oversample(): OverSampleType {\n return this._oversample;\n }\n\n public set oversample(value: OverSampleType) {\n this._oversample = value;\n if (this._setup) {\n this._setup.waveShaper.oversample = this._oversample;\n }\n }\n\n /**\n * Tone control: low-pass cutoff on the wet path. 0 = fully dark (~100 Hz),\n * 1 = fully open (~20 kHz). Mapped logarithmically. Default 1.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get tone(): number {\n return this._tone;\n }\n\n public set tone(value: number) {\n this._tone = Math.max(0, Math.min(1, value));\n if (this._setup) {\n const ctx = this._setup.toneFilter.context;\n this._setup.toneFilter.frequency.setTargetAtTime(DistortionEffect._toneToFrequency(this._tone), ctx.currentTime, 0.01);\n }\n }\n\n public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n if (this._setup) {\n this._setup.inputGain.disconnect();\n this._setup.waveShaper.disconnect();\n this._setup.toneFilter.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.outputGain.disconnect();\n this._setup = null;\n }\n }\n\n /**\n * Build a 256-point tanh-based soft-clip curve for the given drive (0..1).\n *\n * Maps drive to a distortion amount `a = drive * 400 + 1`, then fills the\n * curve with `tanh(x * a) / tanh(a)` so that the output is always bounded\n * to [-1, 1]. At drive=0, `a = 1` and the curve is `tanh(x) / tanh(1)`,\n * which has a small-signal gain of `1/tanh(1) ≈ 1.31` - not perfectly\n * linear. At drive=1, `a = 401` and the curve approximates a hard-clipper.\n */\n private static _buildCurve(drive: number): Float32Array<ArrayBuffer> {\n const n = 256;\n const curve: Float32Array<ArrayBuffer> = new Float32Array(n);\n // drive=0 → amount=1 (mild curve: gain ≈ 1/tanh(1) ≈ 1.31 at origin); drive=1 → amount=401 (near hard-clip)\n const amount = drive * 400 + 1;\n const norm = Math.tanh(amount);\n for (let i = 0; i < n; i++) {\n const x = (i * 2) / (n - 1) - 1;\n curve[i] = Math.tanh(x * amount) / norm;\n }\n return curve;\n }\n\n /**\n * Map tone (0..1) to a low-pass cutoff frequency in Hz.\n * Logarithmic scale: 100 Hz at tone=0, 20 000 Hz at tone=1.\n */\n private static _toneToFrequency(tone: number): number {\n // 100 * 200^tone: 100 Hz at 0, 20 000 Hz at 1\n return 100 * Math.pow(200, tone);\n }\n\n private _setupNodes(ctx: AudioContext): void {\n const inputGain = ctx.createGain();\n const outputGain = ctx.createGain();\n const dryGain = ctx.createGain();\n const wetGain = ctx.createGain();\n const waveShaper = ctx.createWaveShaper();\n const toneFilter = ctx.createBiquadFilter();\n\n inputGain.gain.setValueAtTime(1, ctx.currentTime);\n outputGain.gain.setValueAtTime(1, ctx.currentTime);\n dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);\n wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);\n\n waveShaper.curve = DistortionEffect._buildCurve(this._drive);\n waveShaper.oversample = this._oversample;\n\n toneFilter.type = 'lowpass';\n toneFilter.frequency.setValueAtTime(DistortionEffect._toneToFrequency(this._tone), ctx.currentTime);\n\n // Dry path: input → dryGain → output\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet path: input → waveShaper → toneFilter → wetGain → output\n inputGain.connect(waveShaper);\n waveShaper.connect(toneFilter);\n toneFilter.connect(wetGain);\n wetGain.connect(outputGain);\n\n this._setup = { inputGain, output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AAK;GAC1B,MAAM,IAAK,IAAI,IAAM,MAAS;GAC9B,MAAM,KAAK,KAAK,KAAK,IAAI,MAAM,IAAI;EACrC;EACA,OAAO;CACT;;;;;CAMA,OAAe,iBAAiB,MAAsB;EAEpD,OAAO,MAAM,KAAK,IAAI,KAAK,IAAI;CACjC;CAEA,AAAQ,YAAY,KAAyB;EAC3C,MAAM,YAAY,IAAI,WAAW;EACjC,MAAM,aAAa,IAAI,WAAW;EAClC,MAAM,UAAU,IAAI,WAAW;EAC/B,MAAM,UAAU,IAAI,WAAW;EAC/B,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,aAAa,IAAI,mBAAmB;EAE1C,UAAU,KAAK,eAAe,GAAG,IAAI,WAAW;EAChD,WAAW,KAAK,eAAe,GAAG,IAAI,WAAW;EACjD,QAAQ,KAAK,eAAe,IAAI,KAAK,MAAM,IAAI,WAAW;EAC1D,QAAQ,KAAK,eAAe,KAAK,MAAM,IAAI,WAAW;EAEtD,WAAW,QAAQ,iBAAiB,YAAY,KAAK,MAAM;EAC3D,WAAW,aAAa,KAAK;EAE7B,WAAW,OAAO;EAClB,WAAW,UAAU,eAAe,iBAAiB,iBAAiB,KAAK,KAAK,GAAG,IAAI,WAAW;EAGlG,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,UAAU;EAC5B,WAAW,QAAQ,UAAU;EAC7B,WAAW,QAAQ,OAAO;EAC1B,QAAQ,QAAQ,UAAU;EAE1B,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAY;EAAW;CAClF;AACF"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type AudioBus, WorkletEffect } from '@codexo/exojs';
|
|
2
|
-
/** Construction options for {@link DuckingEffect}. `sidechain` is required. */
|
|
3
|
-
export interface DuckingEffectOptions {
|
|
4
|
-
sidechain: AudioBus;
|
|
5
|
-
threshold?: number;
|
|
6
|
-
ratio?: number;
|
|
7
|
-
attackMs?: number;
|
|
8
|
-
releaseMs?: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Sidechain compressor (ducker) implemented as an {@link WorkletEffect}.
|
|
12
|
-
* Attenuates the main audio signal whenever the `sidechain` {@link AudioBus}
|
|
13
|
-
* exceeds the threshold, then releases when it drops back down. Commonly used
|
|
14
|
-
* to duck background music under dialogue or sound effects. Attack and release
|
|
15
|
-
* times are expressed in milliseconds and converted internally to one-pole
|
|
16
|
-
* filter coefficients.
|
|
17
|
-
*/
|
|
18
|
-
export declare class DuckingEffect extends WorkletEffect {
|
|
19
|
-
private readonly _sidechain;
|
|
20
|
-
private _threshold;
|
|
21
|
-
private _ratio;
|
|
22
|
-
private _attackMs;
|
|
23
|
-
private _releaseMs;
|
|
24
|
-
constructor(options: DuckingEffectOptions);
|
|
25
|
-
protected get _workletName(): string;
|
|
26
|
-
protected get _workletSource(): string;
|
|
27
|
-
protected get _workletOptions(): AudioWorkletNodeOptions;
|
|
28
|
-
protected _onWorkletReady(audioContext: AudioContext): void;
|
|
29
|
-
/** Convert ms time-constant to one-pole filter coefficient at given sample rate. */
|
|
30
|
-
private _msToCoeff;
|
|
31
|
-
/** Sidechain level above which the main signal is attenuated, in dBFS. Range −100..0, default −20. */
|
|
32
|
-
get threshold(): number;
|
|
33
|
-
set threshold(value: number);
|
|
34
|
-
/** Compression ratio applied to the main signal above the threshold. Range 1..20, default 4. */
|
|
35
|
-
get ratio(): number;
|
|
36
|
-
set ratio(value: number);
|
|
37
|
-
/** Attack time in milliseconds - how quickly the ducker engages. Default 30. */
|
|
38
|
-
get attackMs(): number;
|
|
39
|
-
set attackMs(value: number);
|
|
40
|
-
/** Release time in milliseconds - how quickly the ducker disengages. Default 300. */
|
|
41
|
-
get releaseMs(): number;
|
|
42
|
-
set releaseMs(value: number);
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=DuckingEffect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file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MAAM,EAKjC;CACF"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import ducking_worklet_default from "../worklets/ducking.worklet.js";
|
|
2
|
-
import { WorkletEffect } from "@codexo/exojs";
|
|
3
|
-
|
|
4
|
-
//#region src/effects/DuckingEffect.ts
|
|
5
|
-
/**
|
|
6
|
-
* Sidechain compressor (ducker) implemented as an {@link WorkletEffect}.
|
|
7
|
-
* Attenuates the main audio signal whenever the `sidechain` {@link AudioBus}
|
|
8
|
-
* exceeds the threshold, then releases when it drops back down. Commonly used
|
|
9
|
-
* to duck background music under dialogue or sound effects. Attack and release
|
|
10
|
-
* times are expressed in milliseconds and converted internally to one-pole
|
|
11
|
-
* filter coefficients.
|
|
12
|
-
*/
|
|
13
|
-
var DuckingEffect = class extends WorkletEffect {
|
|
14
|
-
_sidechain = null;
|
|
15
|
-
_threshold;
|
|
16
|
-
_ratio;
|
|
17
|
-
_attackMs;
|
|
18
|
-
_releaseMs;
|
|
19
|
-
constructor(options) {
|
|
20
|
-
super();
|
|
21
|
-
if (!options.sidechain) throw new Error("DuckingEffect requires a sidechain AudioBus.");
|
|
22
|
-
this._sidechain = options.sidechain;
|
|
23
|
-
this._threshold = options.threshold ?? -20;
|
|
24
|
-
this._ratio = options.ratio ?? 4;
|
|
25
|
-
this._attackMs = options.attackMs ?? 30;
|
|
26
|
-
this._releaseMs = options.releaseMs ?? 300;
|
|
27
|
-
}
|
|
28
|
-
get _workletName() {
|
|
29
|
-
return "exojs-ducking";
|
|
30
|
-
}
|
|
31
|
-
get _workletSource() {
|
|
32
|
-
return ducking_worklet_default;
|
|
33
|
-
}
|
|
34
|
-
get _workletOptions() {
|
|
35
|
-
return {
|
|
36
|
-
numberOfInputs: 2,
|
|
37
|
-
numberOfOutputs: 1
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
_onWorkletReady(audioContext) {
|
|
41
|
-
if (!this._sidechain) return;
|
|
42
|
-
this._setAudioParam("threshold", this._threshold);
|
|
43
|
-
this._setAudioParam("ratio", this._ratio);
|
|
44
|
-
this._setAudioParam("attack", this._msToCoeff(this._attackMs, audioContext.sampleRate));
|
|
45
|
-
this._setAudioParam("release", this._msToCoeff(this._releaseMs, audioContext.sampleRate));
|
|
46
|
-
const sidechain = this._sidechain;
|
|
47
|
-
const sidechainOut = sidechain.getOutputNode();
|
|
48
|
-
if (sidechainOut && this._workletNode) sidechainOut.connect(this._workletNode, 0, 1);
|
|
49
|
-
else sidechain.onceSetup(() => {
|
|
50
|
-
const node = sidechain.getOutputNode();
|
|
51
|
-
if (node && this._workletNode) node.connect(this._workletNode, 0, 1);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/** Convert ms time-constant to one-pole filter coefficient at given sample rate. */
|
|
55
|
-
_msToCoeff(ms, sampleRate) {
|
|
56
|
-
const tau = ms * .001 * sampleRate;
|
|
57
|
-
return 1 - Math.exp(-1 / Math.max(1, tau));
|
|
58
|
-
}
|
|
59
|
-
/** Sidechain level above which the main signal is attenuated, in dBFS. Range −100..0, default −20. */
|
|
60
|
-
get threshold() {
|
|
61
|
-
return this._threshold;
|
|
62
|
-
}
|
|
63
|
-
set threshold(value) {
|
|
64
|
-
this._threshold = Math.max(-100, Math.min(0, value));
|
|
65
|
-
this._setAudioParam("threshold", this._threshold);
|
|
66
|
-
}
|
|
67
|
-
/** Compression ratio applied to the main signal above the threshold. Range 1..20, default 4. */
|
|
68
|
-
get ratio() {
|
|
69
|
-
return this._ratio;
|
|
70
|
-
}
|
|
71
|
-
set ratio(value) {
|
|
72
|
-
this._ratio = Math.max(1, Math.min(20, value));
|
|
73
|
-
this._setAudioParam("ratio", this._ratio);
|
|
74
|
-
}
|
|
75
|
-
/** Attack time in milliseconds - how quickly the ducker engages. Default 30. */
|
|
76
|
-
get attackMs() {
|
|
77
|
-
return this._attackMs;
|
|
78
|
-
}
|
|
79
|
-
set attackMs(value) {
|
|
80
|
-
this._attackMs = Math.max(.001, value);
|
|
81
|
-
if (this._workletNode) this._setAudioParam("attack", this._msToCoeff(this._attackMs, this._workletNode.context.sampleRate));
|
|
82
|
-
}
|
|
83
|
-
/** Release time in milliseconds - how quickly the ducker disengages. Default 300. */
|
|
84
|
-
get releaseMs() {
|
|
85
|
-
return this._releaseMs;
|
|
86
|
-
}
|
|
87
|
-
set releaseMs(value) {
|
|
88
|
-
this._releaseMs = Math.max(.001, value);
|
|
89
|
-
if (this._workletNode) this._setAudioParam("release", this._msToCoeff(this._releaseMs, this._workletNode.context.sampleRate));
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
export { DuckingEffect };
|
|
95
|
-
//# sourceMappingURL=DuckingEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DuckingEffect.js","names":["duckingWorkletSource"],"sources":["../../../src/effects/DuckingEffect.ts"],"sourcesContent":["import { type AudioBus, WorkletEffect } from '@codexo/exojs';\n\nimport duckingWorkletSource from '../worklets/ducking.worklet.ts?worklet';\n\n/** Construction options for {@link DuckingEffect}. `sidechain` is required. */\nexport interface DuckingEffectOptions {\n sidechain: AudioBus;\n threshold?: number;\n ratio?: number;\n attackMs?: number;\n releaseMs?: number;\n}\n\n/**\n * Sidechain compressor (ducker) implemented as an {@link WorkletEffect}.\n * Attenuates the main audio signal whenever the `sidechain` {@link AudioBus}\n * exceeds the threshold, then releases when it drops back down. Commonly used\n * to duck background music under dialogue or sound effects. Attack and release\n * times are expressed in milliseconds and converted internally to one-pole\n * filter coefficients.\n */\nexport class DuckingEffect extends WorkletEffect {\n // Declared nullable because super() may trigger _onWorkletReady before the\n // subclass constructor body runs (if construction is aborted by a throw).\n private readonly _sidechain: AudioBus | null = null;\n private _threshold: number;\n private _ratio: number;\n private _attackMs: number;\n private _releaseMs: number;\n\n public constructor(options: DuckingEffectOptions) {\n super();\n if (!options.sidechain) {\n throw new Error('DuckingEffect requires a sidechain AudioBus.');\n }\n this._sidechain = options.sidechain;\n this._threshold = options.threshold ?? -20;\n this._ratio = options.ratio ?? 4;\n this._attackMs = options.attackMs ?? 30;\n this._releaseMs = options.releaseMs ?? 300;\n }\n\n protected get _workletName(): string {\n return 'exojs-ducking';\n }\n\n protected get _workletSource(): string {\n return duckingWorkletSource;\n }\n\n protected override get _workletOptions(): AudioWorkletNodeOptions {\n return { numberOfInputs: 2, numberOfOutputs: 1 };\n }\n\n protected override _onWorkletReady(audioContext: AudioContext): void {\n // Guard against partially-constructed instances (constructor threw after super()).\n if (!this._sidechain) return;\n\n // Apply current parameter values\n this._setAudioParam('threshold', this._threshold);\n this._setAudioParam('ratio', this._ratio);\n this._setAudioParam('attack', this._msToCoeff(this._attackMs, audioContext.sampleRate));\n this._setAudioParam('release', this._msToCoeff(this._releaseMs, audioContext.sampleRate));\n\n // Wire sidechain to input 1 of the worklet\n const sidechain = this._sidechain;\n const sidechainOut = sidechain.getOutputNode();\n if (sidechainOut && this._workletNode) {\n sidechainOut.connect(this._workletNode, 0, 1);\n } else {\n sidechain.onceSetup(() => {\n const node = sidechain.getOutputNode();\n if (node && this._workletNode) {\n node.connect(this._workletNode, 0, 1);\n }\n });\n }\n }\n\n /** Convert ms time-constant to one-pole filter coefficient at given sample rate. */\n private _msToCoeff(ms: number, sampleRate: number): number {\n const tau = ms * 0.001 * sampleRate;\n return 1 - Math.exp(-1 / Math.max(1, tau));\n }\n\n /** Sidechain level above which the main signal is attenuated, in dBFS. Range −100..0, default −20. */\n public get threshold(): number {\n return this._threshold;\n }\n public set threshold(value: number) {\n this._threshold = Math.max(-100, Math.min(0, value));\n this._setAudioParam('threshold', this._threshold);\n }\n\n /** Compression ratio applied to the main signal above the threshold. Range 1..20, default 4. */\n public get ratio(): number {\n return this._ratio;\n }\n public set ratio(value: number) {\n this._ratio = Math.max(1, Math.min(20, value));\n this._setAudioParam('ratio', this._ratio);\n }\n\n /** Attack time in milliseconds - how quickly the ducker engages. Default 30. */\n public get attackMs(): number {\n return this._attackMs;\n }\n public set attackMs(value: number) {\n this._attackMs = Math.max(0.001, value);\n if (this._workletNode) {\n this._setAudioParam('attack', this._msToCoeff(this._attackMs, this._workletNode.context.sampleRate));\n }\n }\n\n /** Release time in milliseconds - how quickly the ducker disengages. Default 300. */\n public get releaseMs(): number {\n return this._releaseMs;\n }\n public set releaseMs(value: number) {\n this._releaseMs = Math.max(0.001, value);\n if (this._workletNode) {\n this._setAudioParam('release', this._msToCoeff(this._releaseMs, this._workletNode.context.sampleRate));\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,IAAa,gBAAb,cAAmC,cAAc;CAG/C,AAAiB,aAA8B;CAC/C,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,SAA+B;EAChD,MAAM;EACN,IAAI,CAAC,QAAQ,WACX,MAAM,IAAI,MAAM,8CAA8C;EAEhE,KAAK,aAAa,QAAQ;EAC1B,KAAK,aAAa,QAAQ,aAAa;EACvC,KAAK,SAAS,QAAQ,SAAS;EAC/B,KAAK,YAAY,QAAQ,YAAY;EACrC,KAAK,aAAa,QAAQ,aAAa;CACzC;CAEA,IAAc,eAAuB;EACnC,OAAO;CACT;CAEA,IAAc,iBAAyB;EACrC,OAAOA;CACT;CAEA,IAAuB,kBAA2C;EAChE,OAAO;GAAE,gBAAgB;GAAG,iBAAiB;EAAE;CACjD;CAEA,AAAmB,gBAAgB,cAAkC;EAEnE,IAAI,CAAC,KAAK,YAAY;EAGtB,KAAK,eAAe,aAAa,KAAK,UAAU;EAChD,KAAK,eAAe,SAAS,KAAK,MAAM;EACxC,KAAK,eAAe,UAAU,KAAK,WAAW,KAAK,WAAW,aAAa,UAAU,CAAC;EACtF,KAAK,eAAe,WAAW,KAAK,WAAW,KAAK,YAAY,aAAa,UAAU,CAAC;EAGxF,MAAM,YAAY,KAAK;EACvB,MAAM,eAAe,UAAU,cAAc;EAC7C,IAAI,gBAAgB,KAAK,cACvB,aAAa,QAAQ,KAAK,cAAc,GAAG,CAAC;OAE5C,UAAU,gBAAgB;GACxB,MAAM,OAAO,UAAU,cAAc;GACrC,IAAI,QAAQ,KAAK,cACf,KAAK,QAAQ,KAAK,cAAc,GAAG,CAAC;EAExC,CAAC;CAEL;;CAGA,AAAQ,WAAW,IAAY,YAA4B;EACzD,MAAM,MAAM,KAAK,OAAQ;EACzB,OAAO,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,GAAG,CAAC;CAC3C;;CAGA,IAAW,YAAoB;EAC7B,OAAO,KAAK;CACd;CACA,IAAW,UAAU,OAAe;EAClC,KAAK,aAAa,KAAK,IAAI,MAAM,KAAK,IAAI,GAAG,KAAK,CAAC;EACnD,KAAK,eAAe,aAAa,KAAK,UAAU;CAClD;;CAGA,IAAW,QAAgB;EACzB,OAAO,KAAK;CACd;CACA,IAAW,MAAM,OAAe;EAC9B,KAAK,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC;EAC7C,KAAK,eAAe,SAAS,KAAK,MAAM;CAC1C;;CAGA,IAAW,WAAmB;EAC5B,OAAO,KAAK;CACd;CACA,IAAW,SAAS,OAAe;EACjC,KAAK,YAAY,KAAK,IAAI,MAAO,KAAK;EACtC,IAAI,KAAK,cACP,KAAK,eAAe,UAAU,KAAK,WAAW,KAAK,WAAW,KAAK,aAAa,QAAQ,UAAU,CAAC;CAEvG;;CAGA,IAAW,YAAoB;EAC7B,OAAO,KAAK;CACd;CACA,IAAW,UAAU,OAAe;EAClC,KAAK,aAAa,KAAK,IAAI,MAAO,KAAK;EACvC,IAAI,KAAK,cACP,KAAK,eAAe,WAAW,KAAK,WAAW,KAAK,YAAY,KAAK,aAAa,QAAQ,UAAU,CAAC;CAEzG;AACF"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { AudioEffect } from '@codexo/exojs';
|
|
2
|
-
/** Construction options for {@link EqualizerEffect}. */
|
|
3
|
-
export interface EqualizerEffectOptions {
|
|
4
|
-
low?: number;
|
|
5
|
-
mid?: number;
|
|
6
|
-
high?: number;
|
|
7
|
-
lowFrequency?: number;
|
|
8
|
-
midFrequency?: number;
|
|
9
|
-
highFrequency?: number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Three-band equalizer (low shelf / peaking mid / high shelf) built from a
|
|
13
|
-
* series chain of `BiquadFilterNode` instances. Gain values are in dB and
|
|
14
|
-
* clamped to ±40 dB. All six parameters (gains + frequencies) are
|
|
15
|
-
* adjustable at runtime via the corresponding setters; gain changes use a
|
|
16
|
-
* short exponential ramp to avoid clicks.
|
|
17
|
-
*/
|
|
18
|
-
export declare class EqualizerEffect extends AudioEffect {
|
|
19
|
-
private _setup;
|
|
20
|
-
private _low;
|
|
21
|
-
private readonly _onAudioContextReady;
|
|
22
|
-
private _mid;
|
|
23
|
-
private _high;
|
|
24
|
-
private _lowFrequency;
|
|
25
|
-
private _midFrequency;
|
|
26
|
-
private _highFrequency;
|
|
27
|
-
constructor(options?: EqualizerEffectOptions);
|
|
28
|
-
get inputNode(): AudioNode;
|
|
29
|
-
get outputNode(): AudioNode;
|
|
30
|
-
/** Low-shelf gain in dB applied below `lowFrequency`. Range −40..40, default 0. */
|
|
31
|
-
get low(): number;
|
|
32
|
-
set low(value: number);
|
|
33
|
-
/** Peaking mid-band gain in dB centered at `midFrequency`. Range −40..40, default 0. */
|
|
34
|
-
get mid(): number;
|
|
35
|
-
set mid(value: number);
|
|
36
|
-
/** High-shelf gain in dB applied above `highFrequency`. Range −40..40, default 0. */
|
|
37
|
-
get high(): number;
|
|
38
|
-
set high(value: number);
|
|
39
|
-
/** Cutoff frequency in Hz of the low-shelf band. Default 250. */
|
|
40
|
-
get lowFrequency(): number;
|
|
41
|
-
set lowFrequency(value: number);
|
|
42
|
-
/** Center frequency in Hz of the peaking mid band. Default 1500. */
|
|
43
|
-
get midFrequency(): number;
|
|
44
|
-
set midFrequency(value: number);
|
|
45
|
-
/** Cutoff frequency in Hz of the high-shelf band. Default 6000. */
|
|
46
|
-
get highFrequency(): number;
|
|
47
|
-
set highFrequency(value: number);
|
|
48
|
-
destroy(): void;
|
|
49
|
-
private _setupNodes;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=EqualizerEffect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EqualizerEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/EqualizerEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6D,MAAM,eAAe,CAAC;AAEvG,wDAAwD;AACxD,MAAM,WAAW,sBAAsB;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAQD;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IACF,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,cAAc,CAAS;IAE/B,YAAmB,OAAO,GAAE,sBAA2B,EAatD;IAED,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED,IAAW,UAAU,IAAI,SAAS,CAGjC;IAED,mFAAmF;IACnF,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAK3B;IAED,wFAAwF;IACxF,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAK3B;IAED,qFAAqF;IACrF,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAK5B;IAED,iEAAiE;IACjE,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED,IAAW,YAAY,CAAC,KAAK,EAAE,MAAM,EAKpC;IAED,oEAAoE;IACpE,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED,IAAW,YAAY,CAAC,KAAK,EAAE,MAAM,EAKpC;IAED,mEAAmE;IACnE,IAAW,aAAa,IAAI,MAAM,CAEjC;IAED,IAAW,aAAa,CAAC,KAAK,EAAE,MAAM,EAKrC;IAEe,OAAO,IAAI,IAAI,CAQ9B;IAED,OAAO,CAAC,WAAW;CAsBpB"}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
|
|
2
|
-
|
|
3
|
-
//#region src/effects/EqualizerEffect.ts
|
|
4
|
-
/**
|
|
5
|
-
* Three-band equalizer (low shelf / peaking mid / high shelf) built from a
|
|
6
|
-
* series chain of `BiquadFilterNode` instances. Gain values are in dB and
|
|
7
|
-
* clamped to ±40 dB. All six parameters (gains + frequencies) are
|
|
8
|
-
* adjustable at runtime via the corresponding setters; gain changes use a
|
|
9
|
-
* short exponential ramp to avoid clicks.
|
|
10
|
-
*/
|
|
11
|
-
var EqualizerEffect = class extends AudioEffect {
|
|
12
|
-
_setup = null;
|
|
13
|
-
_low;
|
|
14
|
-
_onAudioContextReady = (ctx) => {
|
|
15
|
-
onAudioContextReady.remove(this._onAudioContextReady);
|
|
16
|
-
this._setupNodes(ctx);
|
|
17
|
-
};
|
|
18
|
-
_mid;
|
|
19
|
-
_high;
|
|
20
|
-
_lowFrequency;
|
|
21
|
-
_midFrequency;
|
|
22
|
-
_highFrequency;
|
|
23
|
-
constructor(options = {}) {
|
|
24
|
-
super();
|
|
25
|
-
this._low = Math.max(-40, Math.min(40, options.low ?? 0));
|
|
26
|
-
this._mid = Math.max(-40, Math.min(40, options.mid ?? 0));
|
|
27
|
-
this._high = Math.max(-40, Math.min(40, options.high ?? 0));
|
|
28
|
-
this._lowFrequency = options.lowFrequency ?? 250;
|
|
29
|
-
this._midFrequency = options.midFrequency ?? 1500;
|
|
30
|
-
this._highFrequency = options.highFrequency ?? 6e3;
|
|
31
|
-
if (isAudioContextReady()) this._setupNodes(getAudioContext());
|
|
32
|
-
else onAudioContextReady.add(this._onAudioContextReady);
|
|
33
|
-
}
|
|
34
|
-
get inputNode() {
|
|
35
|
-
if (!this._setup) throw new Error("EqualizerEffect not yet initialized.");
|
|
36
|
-
return this._setup.lowShelf;
|
|
37
|
-
}
|
|
38
|
-
get outputNode() {
|
|
39
|
-
if (!this._setup) throw new Error("EqualizerEffect not yet initialized.");
|
|
40
|
-
return this._setup.highShelf;
|
|
41
|
-
}
|
|
42
|
-
/** Low-shelf gain in dB applied below `lowFrequency`. Range −40..40, default 0. */
|
|
43
|
-
get low() {
|
|
44
|
-
return this._low;
|
|
45
|
-
}
|
|
46
|
-
set low(value) {
|
|
47
|
-
this._low = Math.max(-40, Math.min(40, value));
|
|
48
|
-
if (this._setup) this._setup.lowShelf.gain.setTargetAtTime(this._low, this._setup.lowShelf.context.currentTime, .01);
|
|
49
|
-
}
|
|
50
|
-
/** Peaking mid-band gain in dB centered at `midFrequency`. Range −40..40, default 0. */
|
|
51
|
-
get mid() {
|
|
52
|
-
return this._mid;
|
|
53
|
-
}
|
|
54
|
-
set mid(value) {
|
|
55
|
-
this._mid = Math.max(-40, Math.min(40, value));
|
|
56
|
-
if (this._setup) this._setup.peaking.gain.setTargetAtTime(this._mid, this._setup.peaking.context.currentTime, .01);
|
|
57
|
-
}
|
|
58
|
-
/** High-shelf gain in dB applied above `highFrequency`. Range −40..40, default 0. */
|
|
59
|
-
get high() {
|
|
60
|
-
return this._high;
|
|
61
|
-
}
|
|
62
|
-
set high(value) {
|
|
63
|
-
this._high = Math.max(-40, Math.min(40, value));
|
|
64
|
-
if (this._setup) this._setup.highShelf.gain.setTargetAtTime(this._high, this._setup.highShelf.context.currentTime, .01);
|
|
65
|
-
}
|
|
66
|
-
/** Cutoff frequency in Hz of the low-shelf band. Default 250. */
|
|
67
|
-
get lowFrequency() {
|
|
68
|
-
return this._lowFrequency;
|
|
69
|
-
}
|
|
70
|
-
set lowFrequency(value) {
|
|
71
|
-
this._lowFrequency = Math.max(0, value);
|
|
72
|
-
if (this._setup) this._setup.lowShelf.frequency.setTargetAtTime(this._lowFrequency, this._setup.lowShelf.context.currentTime, .01);
|
|
73
|
-
}
|
|
74
|
-
/** Center frequency in Hz of the peaking mid band. Default 1500. */
|
|
75
|
-
get midFrequency() {
|
|
76
|
-
return this._midFrequency;
|
|
77
|
-
}
|
|
78
|
-
set midFrequency(value) {
|
|
79
|
-
this._midFrequency = Math.max(0, value);
|
|
80
|
-
if (this._setup) this._setup.peaking.frequency.setTargetAtTime(this._midFrequency, this._setup.peaking.context.currentTime, .01);
|
|
81
|
-
}
|
|
82
|
-
/** Cutoff frequency in Hz of the high-shelf band. Default 6000. */
|
|
83
|
-
get highFrequency() {
|
|
84
|
-
return this._highFrequency;
|
|
85
|
-
}
|
|
86
|
-
set highFrequency(value) {
|
|
87
|
-
this._highFrequency = Math.max(0, value);
|
|
88
|
-
if (this._setup) this._setup.highShelf.frequency.setTargetAtTime(this._highFrequency, this._setup.highShelf.context.currentTime, .01);
|
|
89
|
-
}
|
|
90
|
-
destroy() {
|
|
91
|
-
onAudioContextReady.remove(this._onAudioContextReady);
|
|
92
|
-
if (this._setup) {
|
|
93
|
-
this._setup.lowShelf.disconnect();
|
|
94
|
-
this._setup.peaking.disconnect();
|
|
95
|
-
this._setup.highShelf.disconnect();
|
|
96
|
-
this._setup = null;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
_setupNodes(ctx) {
|
|
100
|
-
const lowShelf = ctx.createBiquadFilter();
|
|
101
|
-
lowShelf.type = "lowshelf";
|
|
102
|
-
lowShelf.frequency.setValueAtTime(this._lowFrequency, ctx.currentTime);
|
|
103
|
-
lowShelf.gain.setValueAtTime(this._low, ctx.currentTime);
|
|
104
|
-
const peaking = ctx.createBiquadFilter();
|
|
105
|
-
peaking.type = "peaking";
|
|
106
|
-
peaking.frequency.setValueAtTime(this._midFrequency, ctx.currentTime);
|
|
107
|
-
peaking.gain.setValueAtTime(this._mid, ctx.currentTime);
|
|
108
|
-
const highShelf = ctx.createBiquadFilter();
|
|
109
|
-
highShelf.type = "highshelf";
|
|
110
|
-
highShelf.frequency.setValueAtTime(this._highFrequency, ctx.currentTime);
|
|
111
|
-
highShelf.gain.setValueAtTime(this._high, ctx.currentTime);
|
|
112
|
-
lowShelf.connect(peaking);
|
|
113
|
-
peaking.connect(highShelf);
|
|
114
|
-
this._setup = {
|
|
115
|
-
lowShelf,
|
|
116
|
-
peaking,
|
|
117
|
-
highShelf
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
//#endregion
|
|
123
|
-
export { EqualizerEffect };
|
|
124
|
-
//# sourceMappingURL=EqualizerEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EqualizerEffect.js","names":[],"sources":["../../../src/effects/EqualizerEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link EqualizerEffect}. */\nexport interface EqualizerEffectOptions {\n low?: number;\n mid?: number;\n high?: number;\n lowFrequency?: number;\n midFrequency?: number;\n highFrequency?: number;\n}\n\ninterface EqualizerEffectSetup {\n readonly lowShelf: BiquadFilterNode;\n readonly peaking: BiquadFilterNode;\n readonly highShelf: BiquadFilterNode;\n}\n\n/**\n * Three-band equalizer (low shelf / peaking mid / high shelf) built from a\n * series chain of `BiquadFilterNode` instances. Gain values are in dB and\n * clamped to ±40 dB. All six parameters (gains + frequencies) are\n * adjustable at runtime via the corresponding setters; gain changes use a\n * short exponential ramp to avoid clicks.\n */\nexport class EqualizerEffect extends AudioEffect {\n private _setup: EqualizerEffectSetup | null = null;\n private _low: number;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\n private _mid: number;\n private _high: number;\n private _lowFrequency: number;\n private _midFrequency: number;\n private _highFrequency: number;\n\n public constructor(options: EqualizerEffectOptions = {}) {\n super();\n this._low = Math.max(-40, Math.min(40, options.low ?? 0));\n this._mid = Math.max(-40, Math.min(40, options.mid ?? 0));\n this._high = Math.max(-40, Math.min(40, options.high ?? 0));\n this._lowFrequency = options.lowFrequency ?? 250;\n this._midFrequency = options.midFrequency ?? 1500;\n this._highFrequency = options.highFrequency ?? 6000;\n if (isAudioContextReady()) {\n this._setupNodes(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\n }\n\n public get inputNode(): AudioNode {\n if (!this._setup) throw new Error('EqualizerEffect not yet initialized.');\n return this._setup.lowShelf;\n }\n\n public get outputNode(): AudioNode {\n if (!this._setup) throw new Error('EqualizerEffect not yet initialized.');\n return this._setup.highShelf;\n }\n\n /** Low-shelf gain in dB applied below `lowFrequency`. Range −40..40, default 0. */\n public get low(): number {\n return this._low;\n }\n\n public set low(value: number) {\n this._low = Math.max(-40, Math.min(40, value));\n if (this._setup) {\n this._setup.lowShelf.gain.setTargetAtTime(this._low, this._setup.lowShelf.context.currentTime, 0.01);\n }\n }\n\n /** Peaking mid-band gain in dB centered at `midFrequency`. Range −40..40, default 0. */\n public get mid(): number {\n return this._mid;\n }\n\n public set mid(value: number) {\n this._mid = Math.max(-40, Math.min(40, value));\n if (this._setup) {\n this._setup.peaking.gain.setTargetAtTime(this._mid, this._setup.peaking.context.currentTime, 0.01);\n }\n }\n\n /** High-shelf gain in dB applied above `highFrequency`. Range −40..40, default 0. */\n public get high(): number {\n return this._high;\n }\n\n public set high(value: number) {\n this._high = Math.max(-40, Math.min(40, value));\n if (this._setup) {\n this._setup.highShelf.gain.setTargetAtTime(this._high, this._setup.highShelf.context.currentTime, 0.01);\n }\n }\n\n /** Cutoff frequency in Hz of the low-shelf band. Default 250. */\n public get lowFrequency(): number {\n return this._lowFrequency;\n }\n\n public set lowFrequency(value: number) {\n this._lowFrequency = Math.max(0, value);\n if (this._setup) {\n this._setup.lowShelf.frequency.setTargetAtTime(this._lowFrequency, this._setup.lowShelf.context.currentTime, 0.01);\n }\n }\n\n /** Center frequency in Hz of the peaking mid band. Default 1500. */\n public get midFrequency(): number {\n return this._midFrequency;\n }\n\n public set midFrequency(value: number) {\n this._midFrequency = Math.max(0, value);\n if (this._setup) {\n this._setup.peaking.frequency.setTargetAtTime(this._midFrequency, this._setup.peaking.context.currentTime, 0.01);\n }\n }\n\n /** Cutoff frequency in Hz of the high-shelf band. Default 6000. */\n public get highFrequency(): number {\n return this._highFrequency;\n }\n\n public set highFrequency(value: number) {\n this._highFrequency = Math.max(0, value);\n if (this._setup) {\n this._setup.highShelf.frequency.setTargetAtTime(this._highFrequency, this._setup.highShelf.context.currentTime, 0.01);\n }\n }\n\n public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n if (this._setup) {\n this._setup.lowShelf.disconnect();\n this._setup.peaking.disconnect();\n this._setup.highShelf.disconnect();\n this._setup = null;\n }\n }\n\n private _setupNodes(ctx: AudioContext): void {\n const lowShelf = ctx.createBiquadFilter();\n lowShelf.type = 'lowshelf';\n lowShelf.frequency.setValueAtTime(this._lowFrequency, ctx.currentTime);\n lowShelf.gain.setValueAtTime(this._low, ctx.currentTime);\n\n const peaking = ctx.createBiquadFilter();\n peaking.type = 'peaking';\n peaking.frequency.setValueAtTime(this._midFrequency, ctx.currentTime);\n peaking.gain.setValueAtTime(this._mid, ctx.currentTime);\n\n const highShelf = ctx.createBiquadFilter();\n highShelf.type = 'highshelf';\n highShelf.frequency.setValueAtTime(this._highFrequency, ctx.currentTime);\n highShelf.gain.setValueAtTime(this._high, ctx.currentTime);\n\n // Series chain: lowShelf → peaking → highShelf\n lowShelf.connect(peaking);\n peaking.connect(highSh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