@codexo/exojs-audio-fx 0.19.1 → 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 -123
- package/dist/esm/AudioAnalyser.d.ts.map +0 -1
- package/dist/esm/AudioAnalyser.js +0 -295
- package/dist/esm/AudioAnalyser.js.map +0 -1
- package/dist/esm/AudioTap.d.ts +0 -33
- package/dist/esm/AudioTap.d.ts.map +0 -1
- package/dist/esm/AudioTap.js +0 -126
- package/dist/esm/AudioTap.js.map +0 -1
- package/dist/esm/BeatDetector.d.ts +0 -291
- package/dist/esm/BeatDetector.d.ts.map +0 -1
- package/dist/esm/BeatDetector.js +0 -365
- package/dist/esm/BeatDetector.js.map +0 -1
- package/dist/esm/PcmStreamSource.d.ts +0 -132
- package/dist/esm/PcmStreamSource.d.ts.map +0 -1
- package/dist/esm/PcmStreamSource.js +0 -313
- package/dist/esm/PcmStreamSource.js.map +0 -1
- package/dist/esm/ReadyGate.d.ts +0 -25
- package/dist/esm/ReadyGate.d.ts.map +0 -1
- package/dist/esm/ReadyGate.js +0 -69
- package/dist/esm/ReadyGate.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 -127
- package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
- package/dist/esm/effects/AutoWahEffect.js +0 -209
- 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 -60
- package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
- package/dist/esm/effects/ChorusEffect.js +0 -139
- package/dist/esm/effects/ChorusEffect.js.map +0 -1
- package/dist/esm/effects/CompressorEffect.d.ts +0 -55
- package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
- package/dist/esm/effects/CompressorEffect.js +0 -103
- package/dist/esm/effects/CompressorEffect.js.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.d.ts +0 -118
- package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.js +0 -207
- package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
- package/dist/esm/effects/DelayEffect.d.ts +0 -35
- package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/DelayEffect.js +0 -104
- package/dist/esm/effects/DelayEffect.js.map +0 -1
- package/dist/esm/effects/DistortionEffect.d.ts +0 -116
- package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
- package/dist/esm/effects/DistortionEffect.js +0 -189
- 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 -89
- package/dist/esm/effects/DuckingEffect.js.map +0 -1
- package/dist/esm/effects/EqualizerEffect.d.ts +0 -50
- package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
- package/dist/esm/effects/EqualizerEffect.js +0 -119
- package/dist/esm/effects/EqualizerEffect.js.map +0 -1
- package/dist/esm/effects/FlangerEffect.d.ts +0 -107
- package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
- package/dist/esm/effects/FlangerEffect.js +0 -178
- 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 -129
- package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
- package/dist/esm/effects/LimiterEffect.js +0 -185
- package/dist/esm/effects/LimiterEffect.js.map +0 -1
- package/dist/esm/effects/PhaserEffect.d.ts +0 -126
- package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
- package/dist/esm/effects/PhaserEffect.js +0 -213
- package/dist/esm/effects/PhaserEffect.js.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -83
- package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.js +0 -171
- 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 -37
- package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
- package/dist/esm/effects/ReverbEffect.js +0 -112
- package/dist/esm/effects/ReverbEffect.js.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +0 -95
- package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.js +0 -152
- package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
- package/dist/esm/effects/TremoloEffect.d.ts +0 -108
- package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
- package/dist/esm/effects/TremoloEffect.js +0 -192
- 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 -68
- 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/disposable-processor.d.ts +0 -13
- package/dist/esm/worklets/disposable-processor.d.ts.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,189 +0,0 @@
|
|
|
1
|
-
import { AudioEffect } 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
|
-
constructor(options = {}) {
|
|
40
|
-
super();
|
|
41
|
-
this._drive = Math.max(0, Math.min(1, options.drive ?? .4));
|
|
42
|
-
this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
|
|
43
|
-
this._oversample = options.oversample ?? "2x";
|
|
44
|
-
this._tone = Math.max(0, Math.min(1, options.tone ?? 1));
|
|
45
|
-
this._deferSetup((context) => this._setupNodes(context));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* The node where audio enters this effect. Throws if the audio context is
|
|
49
|
-
* not yet initialized.
|
|
50
|
-
*/
|
|
51
|
-
get inputNode() {
|
|
52
|
-
if (!this._setup) throw new Error("DistortionEffect not yet initialized.");
|
|
53
|
-
return this._setup.inputGain;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* The node where audio exits this effect. Throws if the audio context is
|
|
57
|
-
* not yet initialized.
|
|
58
|
-
*/
|
|
59
|
-
get outputNode() {
|
|
60
|
-
if (!this._setup) throw new Error("DistortionEffect not yet initialized.");
|
|
61
|
-
return this._setup.outputGain;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Drive amount, 0..1: 0 is transparent, 1 a near hard clip. Default 0.4.
|
|
65
|
-
* Changing this rebuilds the wave-shaper curve immediately (sample-accurate
|
|
66
|
-
* on the next render quantum).
|
|
67
|
-
*/
|
|
68
|
-
get drive() {
|
|
69
|
-
return this._drive;
|
|
70
|
-
}
|
|
71
|
-
set drive(value) {
|
|
72
|
-
this._drive = Math.max(0, Math.min(1, value));
|
|
73
|
-
if (this._setup) this._setup.waveShaper.curve = DistortionEffect._buildCurve(this._drive);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Wet (distorted) mix level, 0..1. The dry level is automatically `1 - wet`.
|
|
77
|
-
* Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
|
|
78
|
-
*/
|
|
79
|
-
get wet() {
|
|
80
|
-
return this._wet;
|
|
81
|
-
}
|
|
82
|
-
set wet(value) {
|
|
83
|
-
this._wet = Math.max(0, Math.min(1, value));
|
|
84
|
-
if (this._setup) {
|
|
85
|
-
const ctx = this._setup.wetGain.context;
|
|
86
|
-
this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
|
|
87
|
-
this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Oversampling mode for the `WaveShaperNode`. One of `'none'`, `'2x'`, or
|
|
92
|
-
* `'4x'`. Higher values reduce aliasing but increase CPU usage. Default `'2x'`.
|
|
93
|
-
*/
|
|
94
|
-
get oversample() {
|
|
95
|
-
return this._oversample;
|
|
96
|
-
}
|
|
97
|
-
set oversample(value) {
|
|
98
|
-
this._oversample = value;
|
|
99
|
-
if (this._setup) this._setup.waveShaper.oversample = this._oversample;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Tone control: low-pass cutoff on the wet path. 0 = fully dark (~100 Hz),
|
|
103
|
-
* 1 = fully open (~20 kHz). Mapped logarithmically. Default 1.
|
|
104
|
-
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
105
|
-
*/
|
|
106
|
-
get tone() {
|
|
107
|
-
return this._tone;
|
|
108
|
-
}
|
|
109
|
-
set tone(value) {
|
|
110
|
-
this._tone = Math.max(0, Math.min(1, value));
|
|
111
|
-
if (this._setup) {
|
|
112
|
-
const ctx = this._setup.toneFilter.context;
|
|
113
|
-
this._setup.toneFilter.frequency.setTargetAtTime(DistortionEffect._toneToFrequency(this._tone), ctx.currentTime, .01);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
destroy() {
|
|
117
|
-
this._teardown();
|
|
118
|
-
if (this._setup) {
|
|
119
|
-
this._setup.inputGain.disconnect();
|
|
120
|
-
this._setup.waveShaper.disconnect();
|
|
121
|
-
this._setup.toneFilter.disconnect();
|
|
122
|
-
this._setup.dryGain.disconnect();
|
|
123
|
-
this._setup.wetGain.disconnect();
|
|
124
|
-
this._setup.outputGain.disconnect();
|
|
125
|
-
this._setup = null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Build a 256-point curve for the given drive (0..1): the identity blended
|
|
130
|
-
* with a soft clip `tanh(x * a) / tanh(a)`, `a = drive * 400 + 1`, by `drive`.
|
|
131
|
-
*
|
|
132
|
-
* The blend is what makes drive=0 exactly transparent. A bare soft clip is
|
|
133
|
-
* never linear (at a = 1 its small-signal gain is 1/tanh(1) ≈ 1.31), and
|
|
134
|
-
* special-casing 0 would make the sound jump at the first step above it.
|
|
135
|
-
* Both curves run from -1 to 1 and rise monotonically, so the blend does too.
|
|
136
|
-
*/
|
|
137
|
-
static _buildCurve(drive) {
|
|
138
|
-
const n = 256;
|
|
139
|
-
const curve = new Float32Array(n);
|
|
140
|
-
const amount = drive * 400 + 1;
|
|
141
|
-
const norm = Math.tanh(amount);
|
|
142
|
-
for (let i = 0; i < n; i++) {
|
|
143
|
-
const x = i * 2 / 255 - 1;
|
|
144
|
-
curve[i] = x * (1 - drive) + Math.tanh(x * amount) / norm * drive;
|
|
145
|
-
}
|
|
146
|
-
return curve;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Map tone (0..1) to a low-pass cutoff frequency in Hz.
|
|
150
|
-
* Logarithmic scale: 100 Hz at tone=0, 20 000 Hz at tone=1.
|
|
151
|
-
*/
|
|
152
|
-
static _toneToFrequency(tone) {
|
|
153
|
-
return 100 * Math.pow(200, tone);
|
|
154
|
-
}
|
|
155
|
-
_setupNodes(ctx) {
|
|
156
|
-
const inputGain = ctx.createGain();
|
|
157
|
-
const outputGain = ctx.createGain();
|
|
158
|
-
const dryGain = ctx.createGain();
|
|
159
|
-
const wetGain = ctx.createGain();
|
|
160
|
-
const waveShaper = ctx.createWaveShaper();
|
|
161
|
-
const toneFilter = ctx.createBiquadFilter();
|
|
162
|
-
inputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
163
|
-
outputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
164
|
-
dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
|
|
165
|
-
wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
|
|
166
|
-
waveShaper.curve = DistortionEffect._buildCurve(this._drive);
|
|
167
|
-
waveShaper.oversample = this._oversample;
|
|
168
|
-
toneFilter.type = "lowpass";
|
|
169
|
-
toneFilter.frequency.setValueAtTime(DistortionEffect._toneToFrequency(this._tone), ctx.currentTime);
|
|
170
|
-
inputGain.connect(dryGain);
|
|
171
|
-
dryGain.connect(outputGain);
|
|
172
|
-
inputGain.connect(waveShaper);
|
|
173
|
-
waveShaper.connect(toneFilter);
|
|
174
|
-
toneFilter.connect(wetGain);
|
|
175
|
-
wetGain.connect(outputGain);
|
|
176
|
-
this._setup = {
|
|
177
|
-
inputGain,
|
|
178
|
-
outputGain,
|
|
179
|
-
dryGain,
|
|
180
|
-
wetGain,
|
|
181
|
-
waveShaper,
|
|
182
|
-
toneFilter
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
//#endregion
|
|
188
|
-
export { DistortionEffect };
|
|
189
|
-
//# sourceMappingURL=DistortionEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DistortionEffect.js","names":[],"sources":["../../../src/effects/DistortionEffect.ts"],"sourcesContent":["import { AudioEffect } from '@codexo/exojs';\n\n/** Construction options for {@link DistortionEffect}. */\nexport interface DistortionEffectOptions {\n /**\n * Drive amount, 0..1, default 0.4. At 0 the wet path is transparent; higher\n * values blend in a steeper tanh soft-clip, up to a near hard clip at 1.\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\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 this._deferSetup(context => this._setupNodes(context));\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, 0..1: 0 is transparent, 1 a near hard clip. 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 this._teardown();\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 curve for the given drive (0..1): the identity blended\n * with a soft clip `tanh(x * a) / tanh(a)`, `a = drive * 400 + 1`, by `drive`.\n *\n * The blend is what makes drive=0 exactly transparent. A bare soft clip is\n * never linear (at a = 1 its small-signal gain is 1/tanh(1) ≈ 1.31), and\n * special-casing 0 would make the sound jump at the first step above it.\n * Both curves run from -1 to 1 and rise monotonically, so the blend does too.\n */\n private static _buildCurve(drive: number): Float32Array<ArrayBuffer> {\n const n = 256;\n const curve: Float32Array<ArrayBuffer> = new Float32Array(n);\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] = x * (1 - drive) + (Math.tanh(x * amount) / norm) * drive;\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, outputGain, dryGain, wetGain, waveShaper, toneFilter };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,mBAAb,MAAa,yBAAyB,YAAY;CAChD,AAAQ,SAAuC;CAC/C,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAAmC,CAAC,GAAG;EACxD,MAAM;EACN,KAAK,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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":"DuckingEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/DuckingEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI7D,+EAA+E;AAC/E,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,QAAQ,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,aAAa;IAG9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;IAE3B,YAAmB,OAAO,EAAE,oBAAoB,EAU/C;IAED,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;IAED,SAAS,KAAK,cAAc,IAAI,MAAM,CAErC;IAED,cAAuB,eAAe,IAAI,uBAAuB,CAEhE;IAED,UAAmB,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAWnE;IAED,oFAAoF;IACpF,OAAO,CAAC,UAAU;IAKlB,sGAAsG;IACtG,IAAW,SAAS,IAAI,MAAM,CAE7B;IACD,IAAW,SAAS,CAAC,KAAK,EAAE,MAAM,EAGjC;IAED,gGAAgG;IAChG,IAAW,KAAK,IAAI,MAAM,CAEzB;IACD,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAG7B;IAED,gFAAgF;IAChF,IAAW,QAAQ,IAAI,MAAM,CAE5B;IACD,IAAW,QAAQ,CAAC,KAAK,EAAE,MAAM,EAKhC;IAED,qFAAqF;IACrF,IAAW,SAAS,IAAI,MAAM,CAE7B;IACD,IAAW,SAAS,CAAC,KAAK,EAAE,MAAM,EAKjC;CACF"}
|
|
@@ -1,89 +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
|
-
this._connectAuxInput(this._sidechain, 1);
|
|
47
|
-
}
|
|
48
|
-
/** Convert ms time-constant to one-pole filter coefficient at given sample rate. */
|
|
49
|
-
_msToCoeff(ms, sampleRate) {
|
|
50
|
-
const tau = ms * .001 * sampleRate;
|
|
51
|
-
return 1 - Math.exp(-1 / Math.max(1, tau));
|
|
52
|
-
}
|
|
53
|
-
/** Sidechain level above which the main signal is attenuated, in dBFS. Range −100..0, default −20. */
|
|
54
|
-
get threshold() {
|
|
55
|
-
return this._threshold;
|
|
56
|
-
}
|
|
57
|
-
set threshold(value) {
|
|
58
|
-
this._threshold = Math.max(-100, Math.min(0, value));
|
|
59
|
-
this._setAudioParam("threshold", this._threshold);
|
|
60
|
-
}
|
|
61
|
-
/** Compression ratio applied to the main signal above the threshold. Range 1..20, default 4. */
|
|
62
|
-
get ratio() {
|
|
63
|
-
return this._ratio;
|
|
64
|
-
}
|
|
65
|
-
set ratio(value) {
|
|
66
|
-
this._ratio = Math.max(1, Math.min(20, value));
|
|
67
|
-
this._setAudioParam("ratio", this._ratio);
|
|
68
|
-
}
|
|
69
|
-
/** Attack time in milliseconds - how quickly the ducker engages. Default 30. */
|
|
70
|
-
get attackMs() {
|
|
71
|
-
return this._attackMs;
|
|
72
|
-
}
|
|
73
|
-
set attackMs(value) {
|
|
74
|
-
this._attackMs = Math.max(.001, value);
|
|
75
|
-
if (this._workletNode) this._setAudioParam("attack", this._msToCoeff(this._attackMs, this._workletNode.context.sampleRate));
|
|
76
|
-
}
|
|
77
|
-
/** Release time in milliseconds - how quickly the ducker disengages. Default 300. */
|
|
78
|
-
get releaseMs() {
|
|
79
|
-
return this._releaseMs;
|
|
80
|
-
}
|
|
81
|
-
set releaseMs(value) {
|
|
82
|
-
this._releaseMs = Math.max(.001, value);
|
|
83
|
-
if (this._workletNode) this._setAudioParam("release", this._msToCoeff(this._releaseMs, this._workletNode.context.sampleRate));
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
88
|
-
export { DuckingEffect };
|
|
89
|
-
//# 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 this._connectAuxInput(this._sidechain, 1);\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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,aAAa,QAAQ,UAAU,CAAC;CAEzG;AACF"}
|
|
@@ -1,50 +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 _mid;
|
|
22
|
-
private _high;
|
|
23
|
-
private _lowFrequency;
|
|
24
|
-
private _midFrequency;
|
|
25
|
-
private _highFrequency;
|
|
26
|
-
constructor(options?: EqualizerEffectOptions);
|
|
27
|
-
get inputNode(): AudioNode;
|
|
28
|
-
get outputNode(): AudioNode;
|
|
29
|
-
/** Low-shelf gain in dB applied below `lowFrequency`. Range −40..40, default 0. */
|
|
30
|
-
get low(): number;
|
|
31
|
-
set low(value: number);
|
|
32
|
-
/** Peaking mid-band gain in dB centered at `midFrequency`. Range −40..40, default 0. */
|
|
33
|
-
get mid(): number;
|
|
34
|
-
set mid(value: number);
|
|
35
|
-
/** High-shelf gain in dB applied above `highFrequency`. Range −40..40, default 0. */
|
|
36
|
-
get high(): number;
|
|
37
|
-
set high(value: number);
|
|
38
|
-
/** Cutoff frequency in Hz of the low-shelf band. Default 250. */
|
|
39
|
-
get lowFrequency(): number;
|
|
40
|
-
set lowFrequency(value: number);
|
|
41
|
-
/** Center frequency in Hz of the peaking mid band. Default 1500. */
|
|
42
|
-
get midFrequency(): number;
|
|
43
|
-
set midFrequency(value: number);
|
|
44
|
-
/** Cutoff frequency in Hz of the high-shelf band. Default 6000. */
|
|
45
|
-
get highFrequency(): number;
|
|
46
|
-
set highFrequency(value: number);
|
|
47
|
-
destroy(): void;
|
|
48
|
-
private _setupNodes;
|
|
49
|
-
}
|
|
50
|
-
//# 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,EAAE,MAAM,eAAe,CAAC;AAE5C,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,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,EAStD;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,119 +0,0 @@
|
|
|
1
|
-
import { AudioEffect } 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
|
-
_mid;
|
|
15
|
-
_high;
|
|
16
|
-
_lowFrequency;
|
|
17
|
-
_midFrequency;
|
|
18
|
-
_highFrequency;
|
|
19
|
-
constructor(options = {}) {
|
|
20
|
-
super();
|
|
21
|
-
this._low = Math.max(-40, Math.min(40, options.low ?? 0));
|
|
22
|
-
this._mid = Math.max(-40, Math.min(40, options.mid ?? 0));
|
|
23
|
-
this._high = Math.max(-40, Math.min(40, options.high ?? 0));
|
|
24
|
-
this._lowFrequency = options.lowFrequency ?? 250;
|
|
25
|
-
this._midFrequency = options.midFrequency ?? 1500;
|
|
26
|
-
this._highFrequency = options.highFrequency ?? 6e3;
|
|
27
|
-
this._deferSetup((context) => this._setupNodes(context));
|
|
28
|
-
}
|
|
29
|
-
get inputNode() {
|
|
30
|
-
if (!this._setup) throw new Error("EqualizerEffect not yet initialized.");
|
|
31
|
-
return this._setup.lowShelf;
|
|
32
|
-
}
|
|
33
|
-
get outputNode() {
|
|
34
|
-
if (!this._setup) throw new Error("EqualizerEffect not yet initialized.");
|
|
35
|
-
return this._setup.highShelf;
|
|
36
|
-
}
|
|
37
|
-
/** Low-shelf gain in dB applied below `lowFrequency`. Range −40..40, default 0. */
|
|
38
|
-
get low() {
|
|
39
|
-
return this._low;
|
|
40
|
-
}
|
|
41
|
-
set low(value) {
|
|
42
|
-
this._low = Math.max(-40, Math.min(40, value));
|
|
43
|
-
if (this._setup) this._setup.lowShelf.gain.setTargetAtTime(this._low, this._setup.lowShelf.context.currentTime, .01);
|
|
44
|
-
}
|
|
45
|
-
/** Peaking mid-band gain in dB centered at `midFrequency`. Range −40..40, default 0. */
|
|
46
|
-
get mid() {
|
|
47
|
-
return this._mid;
|
|
48
|
-
}
|
|
49
|
-
set mid(value) {
|
|
50
|
-
this._mid = Math.max(-40, Math.min(40, value));
|
|
51
|
-
if (this._setup) this._setup.peaking.gain.setTargetAtTime(this._mid, this._setup.peaking.context.currentTime, .01);
|
|
52
|
-
}
|
|
53
|
-
/** High-shelf gain in dB applied above `highFrequency`. Range −40..40, default 0. */
|
|
54
|
-
get high() {
|
|
55
|
-
return this._high;
|
|
56
|
-
}
|
|
57
|
-
set high(value) {
|
|
58
|
-
this._high = Math.max(-40, Math.min(40, value));
|
|
59
|
-
if (this._setup) this._setup.highShelf.gain.setTargetAtTime(this._high, this._setup.highShelf.context.currentTime, .01);
|
|
60
|
-
}
|
|
61
|
-
/** Cutoff frequency in Hz of the low-shelf band. Default 250. */
|
|
62
|
-
get lowFrequency() {
|
|
63
|
-
return this._lowFrequency;
|
|
64
|
-
}
|
|
65
|
-
set lowFrequency(value) {
|
|
66
|
-
this._lowFrequency = Math.max(0, value);
|
|
67
|
-
if (this._setup) this._setup.lowShelf.frequency.setTargetAtTime(this._lowFrequency, this._setup.lowShelf.context.currentTime, .01);
|
|
68
|
-
}
|
|
69
|
-
/** Center frequency in Hz of the peaking mid band. Default 1500. */
|
|
70
|
-
get midFrequency() {
|
|
71
|
-
return this._midFrequency;
|
|
72
|
-
}
|
|
73
|
-
set midFrequency(value) {
|
|
74
|
-
this._midFrequency = Math.max(0, value);
|
|
75
|
-
if (this._setup) this._setup.peaking.frequency.setTargetAtTime(this._midFrequency, this._setup.peaking.context.currentTime, .01);
|
|
76
|
-
}
|
|
77
|
-
/** Cutoff frequency in Hz of the high-shelf band. Default 6000. */
|
|
78
|
-
get highFrequency() {
|
|
79
|
-
return this._highFrequency;
|
|
80
|
-
}
|
|
81
|
-
set highFrequency(value) {
|
|
82
|
-
this._highFrequency = Math.max(0, value);
|
|
83
|
-
if (this._setup) this._setup.highShelf.frequency.setTargetAtTime(this._highFrequency, this._setup.highShelf.context.currentTime, .01);
|
|
84
|
-
}
|
|
85
|
-
destroy() {
|
|
86
|
-
this._teardown();
|
|
87
|
-
if (this._setup) {
|
|
88
|
-
this._setup.lowShelf.disconnect();
|
|
89
|
-
this._setup.peaking.disconnect();
|
|
90
|
-
this._setup.highShelf.disconnect();
|
|
91
|
-
this._setup = null;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
_setupNodes(ctx) {
|
|
95
|
-
const lowShelf = ctx.createBiquadFilter();
|
|
96
|
-
lowShelf.type = "lowshelf";
|
|
97
|
-
lowShelf.frequency.setValueAtTime(this._lowFrequency, ctx.currentTime);
|
|
98
|
-
lowShelf.gain.setValueAtTime(this._low, ctx.currentTime);
|
|
99
|
-
const peaking = ctx.createBiquadFilter();
|
|
100
|
-
peaking.type = "peaking";
|
|
101
|
-
peaking.frequency.setValueAtTime(this._midFrequency, ctx.currentTime);
|
|
102
|
-
peaking.gain.setValueAtTime(this._mid, ctx.currentTime);
|
|
103
|
-
const highShelf = ctx.createBiquadFilter();
|
|
104
|
-
highShelf.type = "highshelf";
|
|
105
|
-
highShelf.frequency.setValueAtTime(this._highFrequency, ctx.currentTime);
|
|
106
|
-
highShelf.gain.setValueAtTime(this._high, ctx.currentTime);
|
|
107
|
-
lowShelf.connect(peaking);
|
|
108
|
-
peaking.connect(highShelf);
|
|
109
|
-
this._setup = {
|
|
110
|
-
lowShelf,
|
|
111
|
-
peaking,
|
|
112
|
-
highShelf
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
export { EqualizerEffect };
|
|
119
|
-
//# sourceMappingURL=EqualizerEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EqualizerEffect.js","names":[],"sources":["../../../src/effects/EqualizerEffect.ts"],"sourcesContent":["import { AudioEffect } 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 _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 this._deferSetup(context => this._setupNodes(context));\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 this._teardown();\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(highShelf);\n\n this._setup = { lowShelf, peaking, highShelf };\n }\n}\n"],"mappings":";;;;;;;;;;AAyBA,IAAa,kBAAb,cAAqC,YAAY;CAC/C,AAAQ,SAAsC;CAC9C,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAAkC,CAAC,GAAG;EACvD,MAAM;EACN,KAAK,OAAO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eAAe,IAAI,WAAW;EACpE,QAAQ,KAAK,eAAe,KAAK,MAAM,IAAI,WAAW;EAEtD,MAAM,YAAY,IAAI,mBAAmB;EACzC,UAAU,OAAO;EACjB,UAAU,UAAU,eAAe,KAAK,gBAAgB,IAAI,WAAW;EACvE,UAAU,KAAK,eAAe,KAAK,OAAO,IAAI,WAAW;EAGzD,SAAS,QAAQ,OAAO;EACxB,QAAQ,QAAQ,SAAS;EAEzB,KAAK,SAAS;GAAE;GAAU;GAAS;EAAU;CAC/C;AACF"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { AudioEffect } from '@codexo/exojs';
|
|
2
|
-
/** Construction options for {@link FlangerEffect}. */
|
|
3
|
-
export interface FlangerEffectOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Base delay time in milliseconds. The LFO modulates the delay around this
|
|
6
|
-
* centre value. Range 0.5..20, default 3.
|
|
7
|
-
*/
|
|
8
|
-
delayMs?: number;
|
|
9
|
-
/**
|
|
10
|
-
* LFO modulation depth in milliseconds - the peak deviation added to and
|
|
11
|
-
* subtracted from `delayMs` by the sine LFO. Range 0..10 and never above
|
|
12
|
-
* `delayMs`, default 2.
|
|
13
|
-
*/
|
|
14
|
-
depthMs?: number;
|
|
15
|
-
/**
|
|
16
|
-
* LFO oscillation rate in Hz. Lower rates produce a slow, sweeping flange;
|
|
17
|
-
* higher rates create a faster jet-plane effect. Range 0..10, default 0.25.
|
|
18
|
-
*/
|
|
19
|
-
rateHz?: number;
|
|
20
|
-
/**
|
|
21
|
-
* Feedback amount - fraction of the delay output fed back to the delay input.
|
|
22
|
-
* Higher values intensify the comb-filter resonance. Range 0..0.95, default 0.5.
|
|
23
|
-
*/
|
|
24
|
-
feedback?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Dry/wet mix, 0..1. The dry level is automatically `1 - wet`.
|
|
27
|
-
* Default 0.5 (equal mix).
|
|
28
|
-
*/
|
|
29
|
-
wet?: number;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Flanger effect using native WebAudio nodes (no worklet required).
|
|
33
|
-
*
|
|
34
|
-
* A flanger is a very short LFO-modulated delay (1-10 ms) with a feedback
|
|
35
|
-
* loop. Unlike a chorus - which uses longer delays without feedback to produce
|
|
36
|
-
* thickening - the flanger's feedback reinforces phase cancellation, creating
|
|
37
|
-
* the characteristic sweeping comb-filter "jet-plane" sound as notches and
|
|
38
|
-
* peaks slide up and down the spectrum.
|
|
39
|
-
*
|
|
40
|
-
* Node graph:
|
|
41
|
-
* ```
|
|
42
|
-
* inputGain ┬── dryGain ─────────────────────────┐
|
|
43
|
-
* │ ├── outputGain
|
|
44
|
-
* └──▶ delayNode ──▶ wetGain ───────────┘
|
|
45
|
-
* ↑ │
|
|
46
|
-
* feedbackGain ◀─┘
|
|
47
|
-
*
|
|
48
|
-
* lfoOscillator ── lfoGain (depth in seconds) ──▶ delayNode.delayTime
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`;
|
|
52
|
-
* `feedbackGain.gain = feedback`; `lfoGain.gain = depthMs / 1000`.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* const flanger = new FlangerEffect({ delayMs: 3, depthMs: 2, rateHz: 0.25, feedback: 0.5, wet: 0.5 });
|
|
57
|
-
* bus.addEffect(flanger);
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare class FlangerEffect extends AudioEffect {
|
|
61
|
-
private _nodes;
|
|
62
|
-
private _delayMs;
|
|
63
|
-
private _depthMs;
|
|
64
|
-
private _rateHz;
|
|
65
|
-
private _feedback;
|
|
66
|
-
private _wet;
|
|
67
|
-
constructor(options?: FlangerEffectOptions);
|
|
68
|
-
/**
|
|
69
|
-
* The node where audio enters this effect. Throws if the audio context is
|
|
70
|
-
* not yet initialized.
|
|
71
|
-
*/
|
|
72
|
-
get inputNode(): AudioNode;
|
|
73
|
-
/**
|
|
74
|
-
* The node where audio exits this effect. Throws if the audio context is
|
|
75
|
-
* not yet initialized.
|
|
76
|
-
*/
|
|
77
|
-
get outputNode(): AudioNode;
|
|
78
|
-
/**
|
|
79
|
-
* Base delay time in milliseconds. Range 0.5..20; lowering it below
|
|
80
|
-
* {@link FlangerEffect.depthMs} stops at `depthMs`. Default 3.
|
|
81
|
-
*/
|
|
82
|
-
get delayMs(): number;
|
|
83
|
-
set delayMs(value: number);
|
|
84
|
-
/**
|
|
85
|
-
* LFO modulation depth in milliseconds (peak deviation from base delay).
|
|
86
|
-
* Range 0..10 and never above {@link FlangerEffect.delayMs}, so the swept
|
|
87
|
-
* delay never reaches below zero, which would flatten one half of the sweep.
|
|
88
|
-
* Default 2.
|
|
89
|
-
*/
|
|
90
|
-
get depthMs(): number;
|
|
91
|
-
set depthMs(value: number);
|
|
92
|
-
/** LFO oscillation rate in Hz. Range 0..10, default 0.25. */
|
|
93
|
-
get rateHz(): number;
|
|
94
|
-
set rateHz(value: number);
|
|
95
|
-
/**
|
|
96
|
-
* Feedback amount - fraction of delay output fed back to delay input.
|
|
97
|
-
* Range 0..0.95, default 0.5.
|
|
98
|
-
*/
|
|
99
|
-
get feedback(): number;
|
|
100
|
-
set feedback(value: number);
|
|
101
|
-
/** Wet (flanged) mix level, 0..1. The dry level is automatically `1 - wet`. Default 0.5. */
|
|
102
|
-
get wet(): number;
|
|
103
|
-
set wet(value: number);
|
|
104
|
-
destroy(): void;
|
|
105
|
-
private _setupNodes;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=FlangerEffect.d.ts.map
|