@codexo/exojs-audio-fx 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/BeatDetector.d.ts +55 -9
- package/dist/esm/BeatDetector.js +19 -9
- package/dist/esm/BeatDetector.js.map +1 -1
- package/dist/esm/dsp/tempogram.d.ts +122 -21
- package/dist/esm/effects/AutoWahEffect.d.ts +127 -0
- package/dist/esm/effects/AutoWahEffect.js +241 -0
- package/dist/esm/effects/AutoWahEffect.js.map +1 -0
- package/dist/esm/effects/BitCrusherEffect.d.ts +63 -0
- package/dist/esm/effects/BitCrusherEffect.js +74 -0
- package/dist/esm/effects/BitCrusherEffect.js.map +1 -0
- package/dist/esm/effects/ConvolutionEffect.d.ts +114 -0
- package/dist/esm/effects/ConvolutionEffect.js +193 -0
- package/dist/esm/effects/ConvolutionEffect.js.map +1 -0
- package/dist/esm/effects/DistortionEffect.d.ts +119 -0
- package/dist/esm/effects/DistortionEffect.js +199 -0
- package/dist/esm/effects/DistortionEffect.js.map +1 -0
- package/dist/esm/effects/DuckingEffect.js +6 -2
- package/dist/esm/effects/DuckingEffect.js.map +1 -1
- package/dist/esm/effects/FlangerEffect.d.ts +98 -0
- package/dist/esm/effects/FlangerEffect.js +205 -0
- package/dist/esm/effects/FlangerEffect.js.map +1 -0
- package/dist/esm/effects/GranularEffect.d.ts +8 -4
- package/dist/esm/effects/GranularEffect.js +4 -12
- package/dist/esm/effects/GranularEffect.js.map +1 -1
- package/dist/esm/effects/LimiterEffect.d.ts +124 -0
- package/dist/esm/effects/LimiterEffect.js +198 -0
- package/dist/esm/effects/LimiterEffect.js.map +1 -0
- package/dist/esm/effects/PhaserEffect.d.ts +126 -0
- package/dist/esm/effects/PhaserEffect.js +258 -0
- package/dist/esm/effects/PhaserEffect.js.map +1 -0
- package/dist/esm/effects/PingPongDelayEffect.d.ts +83 -0
- package/dist/esm/effects/PingPongDelayEffect.js +189 -0
- package/dist/esm/effects/PingPongDelayEffect.js.map +1 -0
- package/dist/esm/effects/PitchShiftEffect.d.ts +14 -13
- package/dist/esm/effects/PitchShiftEffect.js +16 -18
- package/dist/esm/effects/PitchShiftEffect.js.map +1 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +95 -0
- package/dist/esm/effects/RingModulatorEffect.js +165 -0
- package/dist/esm/effects/RingModulatorEffect.js.map +1 -0
- package/dist/esm/effects/TremoloEffect.d.ts +110 -0
- package/dist/esm/effects/TremoloEffect.js +205 -0
- package/dist/esm/effects/TremoloEffect.js.map +1 -0
- package/dist/esm/effects/VocoderEffect.d.ts +0 -4
- package/dist/esm/effects/VocoderEffect.js +1 -11
- package/dist/esm/effects/VocoderEffect.js.map +1 -1
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/worklets/beat-detector.worklet.d.ts +1 -1
- package/dist/esm/worklets/beat-detector.worklet.js +628 -112
- package/dist/esm/worklets/beat-detector.worklet.js.map +1 -1
- package/dist/esm/worklets/bit-crusher.worklet.d.ts +1 -0
- package/dist/esm/worklets/bit-crusher.worklet.js +45 -0
- package/dist/esm/worklets/bit-crusher.worklet.js.map +1 -0
- package/dist/esm/worklets/granular.worklet.d.ts +1 -1
- package/dist/esm/worklets/granular.worklet.js +13 -4
- package/dist/esm/worklets/granular.worklet.js.map +1 -1
- package/dist/esm/worklets/pitch-shift.worklet.d.ts +1 -1
- package/dist/esm/worklets/pitch-shift.worklet.js +87 -32
- package/dist/esm/worklets/pitch-shift.worklet.js.map +1 -1
- package/dist/esm/worklets/vocoder.worklet.d.ts +1 -1
- package/dist/esm/worklets/vocoder.worklet.js +5 -3
- package/dist/esm/worklets/vocoder.worklet.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { AudioEffect, onAudioContextReady, isAudioContextReady, getAudioContext } from '@codexo/exojs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Auto-wah effect that uses an amplitude envelope follower to modulate a
|
|
5
|
+
* bandpass filter, creating the characteristic "wah" sweep driven by the
|
|
6
|
+
* loudness of the input signal.
|
|
7
|
+
*
|
|
8
|
+
* The envelope follower is built entirely from native Web Audio nodes — no
|
|
9
|
+
* `ScriptProcessor` or `AudioWorklet` required:
|
|
10
|
+
*
|
|
11
|
+
* 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),
|
|
12
|
+
* converting the AC audio signal to a unipolar amplitude proxy.
|
|
13
|
+
* 2. A `BiquadFilterNode` (lowpass) smooths the rectified signal. The cutoff is
|
|
14
|
+
* derived from `responseMs` to control attack/release speed.
|
|
15
|
+
* 3. A `GainNode` scales the smoothed envelope by `sensitivity` (Hz/unit) and
|
|
16
|
+
* connects its output directly to the wah filter's `frequency` `AudioParam`,
|
|
17
|
+
* sweeping the filter centre upward with input loudness.
|
|
18
|
+
*
|
|
19
|
+
* Node graph:
|
|
20
|
+
* ```
|
|
21
|
+
* inputGain ─┬─ dryGain ─────────────────────────────┐
|
|
22
|
+
* │ ├── outputGain
|
|
23
|
+
* └─ wahFilter(bandpass) ─── wetGain ──────┘
|
|
24
|
+
*
|
|
25
|
+
* Envelope (control) path — parallel off inputGain, sums into wahFilter.frequency:
|
|
26
|
+
* inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)
|
|
27
|
+
* → sensitivityGain → wahFilter.frequency (AudioParam)
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const wah = new AutoWahEffect({ baseFrequency: 300, sensitivity: 2500, wet: 0.8 });
|
|
35
|
+
* bus.addEffect(wah);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
class AutoWahEffect extends AudioEffect {
|
|
39
|
+
_setup = null;
|
|
40
|
+
_baseFrequency;
|
|
41
|
+
_sensitivity;
|
|
42
|
+
_q;
|
|
43
|
+
_responseMs;
|
|
44
|
+
_wet;
|
|
45
|
+
_onAudioContextReady = (ctx) => {
|
|
46
|
+
onAudioContextReady.remove(this._onAudioContextReady);
|
|
47
|
+
this._setupNodes(ctx);
|
|
48
|
+
};
|
|
49
|
+
constructor(options = {}) {
|
|
50
|
+
super();
|
|
51
|
+
this._baseFrequency = Math.max(50, Math.min(2000, options.baseFrequency ?? 200));
|
|
52
|
+
this._sensitivity = Math.max(0, Math.min(6000, options.sensitivity ?? 3000));
|
|
53
|
+
this._q = Math.max(0.1, Math.min(20, options.q ?? 4));
|
|
54
|
+
this._responseMs = Math.max(1, Math.min(500, options.responseMs ?? 30));
|
|
55
|
+
this._wet = Math.max(0, Math.min(1, options.wet ?? 0.7));
|
|
56
|
+
if (isAudioContextReady()) {
|
|
57
|
+
this._setupNodes(getAudioContext());
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
onAudioContextReady.add(this._onAudioContextReady);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The node where audio enters this effect. Throws if the audio context is
|
|
65
|
+
* not yet initialized.
|
|
66
|
+
*/
|
|
67
|
+
get inputNode() {
|
|
68
|
+
if (!this._setup)
|
|
69
|
+
throw new Error('AutoWahEffect not yet initialized.');
|
|
70
|
+
return this._setup.inputGain;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The node where audio exits this effect. Throws if the audio context is
|
|
74
|
+
* not yet initialized.
|
|
75
|
+
*/
|
|
76
|
+
get outputNode() {
|
|
77
|
+
if (!this._setup)
|
|
78
|
+
throw new Error('AutoWahEffect not yet initialized.');
|
|
79
|
+
return this._setup.outputGain;
|
|
80
|
+
}
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// Getters / setters
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
/**
|
|
85
|
+
* Centre frequency of the wah filter in Hz. Range 50..2000, default 200.
|
|
86
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
87
|
+
*/
|
|
88
|
+
get baseFrequency() {
|
|
89
|
+
return this._baseFrequency;
|
|
90
|
+
}
|
|
91
|
+
set baseFrequency(value) {
|
|
92
|
+
this._baseFrequency = Math.max(50, Math.min(2000, value));
|
|
93
|
+
if (this._setup) {
|
|
94
|
+
this._setup.wahFilter.frequency.setTargetAtTime(this._baseFrequency, this._setup.wahFilter.context.currentTime, 0.01);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Envelope sensitivity in Hz/unit: the maximum filter sweep above
|
|
99
|
+
* `baseFrequency` when input is at full amplitude. Range 0..6000, default 3000.
|
|
100
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
101
|
+
*/
|
|
102
|
+
get sensitivity() {
|
|
103
|
+
return this._sensitivity;
|
|
104
|
+
}
|
|
105
|
+
set sensitivity(value) {
|
|
106
|
+
this._sensitivity = Math.max(0, Math.min(6000, value));
|
|
107
|
+
if (this._setup) {
|
|
108
|
+
this._setup.sensitivityGain.gain.setTargetAtTime(this._sensitivity, this._setup.sensitivityGain.context.currentTime, 0.01);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Q (resonance) of the bandpass wah filter. Range 0.1..20, default 4.
|
|
113
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
114
|
+
*/
|
|
115
|
+
get q() {
|
|
116
|
+
return this._q;
|
|
117
|
+
}
|
|
118
|
+
set q(value) {
|
|
119
|
+
this._q = Math.max(0.1, Math.min(20, value));
|
|
120
|
+
if (this._setup) {
|
|
121
|
+
this._setup.wahFilter.Q.setTargetAtTime(this._q, this._setup.wahFilter.context.currentTime, 0.01);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Envelope smoothing time constant in milliseconds. Range 1..500, default 30.
|
|
126
|
+
* Updating this adjusts the smoothing lowpass cutoff immediately via
|
|
127
|
+
* `setTargetAtTime`.
|
|
128
|
+
*/
|
|
129
|
+
get responseMs() {
|
|
130
|
+
return this._responseMs;
|
|
131
|
+
}
|
|
132
|
+
set responseMs(value) {
|
|
133
|
+
this._responseMs = Math.max(1, Math.min(500, value));
|
|
134
|
+
if (this._setup) {
|
|
135
|
+
this._setup.smoothingLowpass.frequency.setTargetAtTime(this._smoothingCutoff(), this._setup.smoothingLowpass.context.currentTime, 0.01);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Wet (wah-filtered) mix level, 0..1. The dry level is automatically
|
|
140
|
+
* `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 0.7.
|
|
141
|
+
*/
|
|
142
|
+
get wet() {
|
|
143
|
+
return this._wet;
|
|
144
|
+
}
|
|
145
|
+
set wet(value) {
|
|
146
|
+
this._wet = Math.max(0, Math.min(1, value));
|
|
147
|
+
if (this._setup) {
|
|
148
|
+
const ctx = this._setup.wetGain.context;
|
|
149
|
+
this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, 0.01);
|
|
150
|
+
this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, 0.01);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
// Lifecycle
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
destroy() {
|
|
157
|
+
onAudioContextReady.remove(this._onAudioContextReady);
|
|
158
|
+
if (this._setup) {
|
|
159
|
+
this._setup.inputGain.disconnect();
|
|
160
|
+
this._setup.dryGain.disconnect();
|
|
161
|
+
this._setup.wetGain.disconnect();
|
|
162
|
+
this._setup.sensitivityGain.disconnect();
|
|
163
|
+
this._setup.wahFilter.disconnect();
|
|
164
|
+
this._setup.smoothingLowpass.disconnect();
|
|
165
|
+
this._setup.rectifier.disconnect();
|
|
166
|
+
this._setup.outputGain.disconnect();
|
|
167
|
+
this._setup = null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
// Private
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
/** Converts `responseMs` to a lowpass cutoff frequency using f = 1/(2π×τ). */
|
|
174
|
+
_smoothingCutoff() {
|
|
175
|
+
return 1000 / (2 * Math.PI * this._responseMs);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Builds a 256-point `Float32Array` curve approximating the full-wave
|
|
179
|
+
* rectifier `f(x) = |x|` for use with `WaveShaperNode`.
|
|
180
|
+
*/
|
|
181
|
+
static _makeRectifierCurve() {
|
|
182
|
+
const n = 256;
|
|
183
|
+
const curve = new Float32Array(n);
|
|
184
|
+
for (let i = 0; i < n; i++) {
|
|
185
|
+
const x = (i * 2) / (n - 1) - 1; // maps index to -1..1
|
|
186
|
+
curve[i] = Math.abs(x);
|
|
187
|
+
}
|
|
188
|
+
return curve;
|
|
189
|
+
}
|
|
190
|
+
_setupNodes(ctx) {
|
|
191
|
+
// Audio-path gain nodes (createGain order: 0=inputGain, 1=outputGain,
|
|
192
|
+
// 2=dryGain, 3=wetGain, 4=sensitivityGain).
|
|
193
|
+
const inputGain = ctx.createGain();
|
|
194
|
+
const outputGain = ctx.createGain();
|
|
195
|
+
const dryGain = ctx.createGain();
|
|
196
|
+
const wetGain = ctx.createGain();
|
|
197
|
+
const sensitivityGain = ctx.createGain();
|
|
198
|
+
// Wah filter (audio path) and smoothing filter (envelope control path)
|
|
199
|
+
// (createBiquadFilter order: 0=wahFilter, 1=smoothingLowpass).
|
|
200
|
+
const wahFilter = ctx.createBiquadFilter();
|
|
201
|
+
const smoothingLowpass = ctx.createBiquadFilter();
|
|
202
|
+
// Full-wave rectifier for the envelope follower.
|
|
203
|
+
const rectifier = ctx.createWaveShaper();
|
|
204
|
+
// ── Initialize values ────────────────────────────────────────────────────
|
|
205
|
+
inputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
206
|
+
outputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
207
|
+
dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
|
|
208
|
+
wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
|
|
209
|
+
sensitivityGain.gain.setValueAtTime(this._sensitivity, ctx.currentTime);
|
|
210
|
+
// Wah bandpass filter: base frequency and Q; envelope signal adds on top.
|
|
211
|
+
wahFilter.type = 'bandpass';
|
|
212
|
+
wahFilter.frequency.setValueAtTime(this._baseFrequency, ctx.currentTime);
|
|
213
|
+
wahFilter.Q.setValueAtTime(this._q, ctx.currentTime);
|
|
214
|
+
// Rectifier: full-wave |x| curve; 4× oversampling for accuracy.
|
|
215
|
+
rectifier.curve = AutoWahEffect._makeRectifierCurve();
|
|
216
|
+
rectifier.oversample = '4x';
|
|
217
|
+
// Smoothing lowpass: cutoff derived from responseMs; low Q for no ringing.
|
|
218
|
+
smoothingLowpass.type = 'lowpass';
|
|
219
|
+
smoothingLowpass.frequency.setValueAtTime(this._smoothingCutoff(), ctx.currentTime);
|
|
220
|
+
smoothingLowpass.Q.setValueAtTime(0.5, ctx.currentTime);
|
|
221
|
+
// ── Wiring ───────────────────────────────────────────────────────────────
|
|
222
|
+
// Dry path: inputGain → dryGain → outputGain
|
|
223
|
+
inputGain.connect(dryGain);
|
|
224
|
+
dryGain.connect(outputGain);
|
|
225
|
+
// Wet (audio) path: inputGain → wahFilter → wetGain → outputGain
|
|
226
|
+
inputGain.connect(wahFilter);
|
|
227
|
+
wahFilter.connect(wetGain);
|
|
228
|
+
wetGain.connect(outputGain);
|
|
229
|
+
// Envelope (control) path — parallel off inputGain, drives wahFilter.frequency.
|
|
230
|
+
// The rectified+smoothed signal is scaled by sensitivityGain and summed into
|
|
231
|
+
// the wahFilter frequency AudioParam, sweeping the filter with input loudness.
|
|
232
|
+
inputGain.connect(rectifier);
|
|
233
|
+
rectifier.connect(smoothingLowpass);
|
|
234
|
+
smoothingLowpass.connect(sensitivityGain);
|
|
235
|
+
sensitivityGain.connect(wahFilter.frequency);
|
|
236
|
+
this._setup = { inputGain, outputGain, dryGain, wetGain, sensitivityGain, wahFilter, smoothingLowpass, rectifier };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export { AutoWahEffect };
|
|
241
|
+
//# sourceMappingURL=AutoWahEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoWahEffect.js","sources":["../../../../src/effects/AutoWahEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA4CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AACG,MAAO,aAAc,SAAQ,WAAW,CAAA;IACpC,MAAM,GAA8B,IAAI;AACxC,IAAA,cAAc;AACd,IAAA,YAAY;AACZ,IAAA,EAAE;AACF,IAAA,WAAW;AACX,IAAA,IAAI;AACK,IAAA,oBAAoB,GAAG,CAAC,GAAiB,KAAU;AAClE,QAAA,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;AACrD,QAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;AACvB,IAAA,CAAC;AAED,IAAA,WAAA,CAAmB,UAAgC,EAAE,EAAA;AACnD,QAAA,KAAK,EAAE;QACP,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,IAAI,GAAG,CAAC,CAAC;QAChF,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC;QAC5E,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,C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CAAC,UAAU,CAAC;;AAG3B,QAAA,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;AAC5B,QAAA,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;AAC1B,QAAA,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;;;;AAK3B,QAAA,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;AAC5B,QAAA,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC;AACnC,QAAA,gBAAgB,CAAC,OAAO,CAAC,eAAe,CAAC;AACzC,QAAA,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,SAAiC,CAAC;QAEpE,IAAI,CAAC,MAAM,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE;IACpH;AACD;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { WorkletEffect } from '@codexo/exojs';
|
|
2
|
+
export interface BitCrusherEffectOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Bit depth for sample quantization. Lower values produce coarser steps and
|
|
5
|
+
* more distortion. Range 1..16, default 8.
|
|
6
|
+
*/
|
|
7
|
+
bits?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Fraction of the sample rate retained (sample-and-hold). A value of 1 means
|
|
10
|
+
* every sample is re-latched (no rate reduction). A value of 0.5 halves the
|
|
11
|
+
* effective sample rate, introducing aliasing. Range 0..1, default 0.5.
|
|
12
|
+
* Maps directly to the worklet `normFreq` AudioParam.
|
|
13
|
+
*/
|
|
14
|
+
frequencyReduction?: number;
|
|
15
|
+
/** Dry/wet mix, 0..1. Default 1. */
|
|
16
|
+
wet?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Lo-fi bit-crusher effect implemented as a {@link WorkletEffect}. Applies two
|
|
20
|
+
* classic degradation stages in series:
|
|
21
|
+
*
|
|
22
|
+
* 1. **Bit-depth reduction** — each sample is quantized to `2^bits` discrete
|
|
23
|
+
* levels, adding harmonic distortion characteristic of low-resolution audio.
|
|
24
|
+
* 2. **Sample-rate reduction** — a phase-accumulator sample-and-hold circuit
|
|
25
|
+
* re-latches the (quantized) input only `normFreq` times per input sample on
|
|
26
|
+
* average, producing aliasing artefacts reminiscent of early digital hardware.
|
|
27
|
+
*
|
|
28
|
+
* The worklet emits a pure wet signal; dry/wet mixing is handled by the base
|
|
29
|
+
* class.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const bus = engine.createBus();
|
|
34
|
+
* const crusher = new BitCrusherEffect({ bits: 4, frequencyReduction: 0.3, wet: 0.8 });
|
|
35
|
+
* bus.addEffect(crusher);
|
|
36
|
+
*
|
|
37
|
+
* // Adjust at runtime:
|
|
38
|
+
* crusher.bits = 2; // extreme quantization crunch
|
|
39
|
+
* crusher.frequencyReduction = 0.1; // heavy downsampling aliasing
|
|
40
|
+
* crusher.wet = 0.5; // blend with dry signal
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class BitCrusherEffect extends WorkletEffect {
|
|
44
|
+
private _bits;
|
|
45
|
+
private _frequencyReduction;
|
|
46
|
+
constructor(options?: BitCrusherEffectOptions);
|
|
47
|
+
protected get _workletName(): string;
|
|
48
|
+
protected get _workletSource(): string;
|
|
49
|
+
protected _onWorkletReady(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Bit depth for sample quantization. Lower values produce more distortion.
|
|
52
|
+
* Range 1..16, default 8.
|
|
53
|
+
*/
|
|
54
|
+
get bits(): number;
|
|
55
|
+
set bits(value: number);
|
|
56
|
+
/**
|
|
57
|
+
* Fraction of the sample rate retained (0 = never re-latch, 1 = every sample).
|
|
58
|
+
* Lower values create more aliasing artefacts. Maps to the worklet `normFreq`
|
|
59
|
+
* AudioParam. Range 0..1, default 0.5.
|
|
60
|
+
*/
|
|
61
|
+
get frequencyReduction(): number;
|
|
62
|
+
set frequencyReduction(value: number);
|
|
63
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { WorkletEffect } from '@codexo/exojs';
|
|
2
|
+
import { bitCrusherWorkletSource } from '../worklets/bit-crusher.worklet.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Lo-fi bit-crusher effect implemented as a {@link WorkletEffect}. Applies two
|
|
6
|
+
* classic degradation stages in series:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Bit-depth reduction** — each sample is quantized to `2^bits` discrete
|
|
9
|
+
* levels, adding harmonic distortion characteristic of low-resolution audio.
|
|
10
|
+
* 2. **Sample-rate reduction** — a phase-accumulator sample-and-hold circuit
|
|
11
|
+
* re-latches the (quantized) input only `normFreq` times per input sample on
|
|
12
|
+
* average, producing aliasing artefacts reminiscent of early digital hardware.
|
|
13
|
+
*
|
|
14
|
+
* The worklet emits a pure wet signal; dry/wet mixing is handled by the base
|
|
15
|
+
* class.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const bus = engine.createBus();
|
|
20
|
+
* const crusher = new BitCrusherEffect({ bits: 4, frequencyReduction: 0.3, wet: 0.8 });
|
|
21
|
+
* bus.addEffect(crusher);
|
|
22
|
+
*
|
|
23
|
+
* // Adjust at runtime:
|
|
24
|
+
* crusher.bits = 2; // extreme quantization crunch
|
|
25
|
+
* crusher.frequencyReduction = 0.1; // heavy downsampling aliasing
|
|
26
|
+
* crusher.wet = 0.5; // blend with dry signal
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
class BitCrusherEffect extends WorkletEffect {
|
|
30
|
+
_bits;
|
|
31
|
+
_frequencyReduction;
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
super();
|
|
34
|
+
this._bits = Math.round(Math.max(1, Math.min(16, options.bits ?? 8)));
|
|
35
|
+
this._frequencyReduction = Math.max(0, Math.min(1, options.frequencyReduction ?? 0.5));
|
|
36
|
+
this.wet = options.wet ?? 1;
|
|
37
|
+
}
|
|
38
|
+
get _workletName() {
|
|
39
|
+
return 'exojs-bit-crusher';
|
|
40
|
+
}
|
|
41
|
+
get _workletSource() {
|
|
42
|
+
return bitCrusherWorkletSource;
|
|
43
|
+
}
|
|
44
|
+
_onWorkletReady() {
|
|
45
|
+
this._setAudioParam('bits', this._bits);
|
|
46
|
+
this._setAudioParam('normFreq', this._frequencyReduction);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Bit depth for sample quantization. Lower values produce more distortion.
|
|
50
|
+
* Range 1..16, default 8.
|
|
51
|
+
*/
|
|
52
|
+
get bits() {
|
|
53
|
+
return this._bits;
|
|
54
|
+
}
|
|
55
|
+
set bits(value) {
|
|
56
|
+
this._bits = Math.round(Math.max(1, Math.min(16, value)));
|
|
57
|
+
this._setAudioParam('bits', this._bits);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Fraction of the sample rate retained (0 = never re-latch, 1 = every sample).
|
|
61
|
+
* Lower values create more aliasing artefacts. Maps to the worklet `normFreq`
|
|
62
|
+
* AudioParam. Range 0..1, default 0.5.
|
|
63
|
+
*/
|
|
64
|
+
get frequencyReduction() {
|
|
65
|
+
return this._frequencyReduction;
|
|
66
|
+
}
|
|
67
|
+
set frequencyReduction(value) {
|
|
68
|
+
this._frequencyReduction = Math.max(0, Math.min(1, value));
|
|
69
|
+
this._setAudioParam('normFreq', this._frequencyReduction);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { BitCrusherEffect };
|
|
74
|
+
//# sourceMappingURL=BitCrusherEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitCrusherEffect.js","sources":["../../../../src/effects/BitCrusherEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAqBA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG,MAAO,gBAAiB,SAAQ,aAAa,CAAA;AACzC,IAAA,KAAK;AACL,IAAA,mBAAmB;AAE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AmB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAC1D,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAAC;IAC3D;AACD;;;;"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { AudioEffect, Sound } from '@codexo/exojs';
|
|
2
|
+
/** Construction options for {@link ConvolutionEffect}. */
|
|
3
|
+
export interface ConvolutionEffectOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Impulse response. Accepts a decoded `AudioBuffer` or a `Sound` (its
|
|
6
|
+
* `audioBuffer` is used). If omitted the effect runs dry (passthrough) until
|
|
7
|
+
* {@link ConvolutionEffect.setImpulse} is called.
|
|
8
|
+
*/
|
|
9
|
+
impulse?: AudioBuffer | Sound;
|
|
10
|
+
/**
|
|
11
|
+
* Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.0.
|
|
12
|
+
*/
|
|
13
|
+
wet?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Maps to `ConvolverNode.normalize`. When `true` the browser applies an
|
|
16
|
+
* equal-power normalization pass on the IR so different IRs play at a
|
|
17
|
+
* consistent perceived loudness. Default `true` (the Web Audio spec default).
|
|
18
|
+
*
|
|
19
|
+
* **Note:** the Web Audio spec only respects `normalize` if it is set
|
|
20
|
+
* *before* `buffer` is assigned. This class always writes `normalize` first.
|
|
21
|
+
* Changing `normalize` at runtime while an IR is loaded re-assigns the
|
|
22
|
+
* buffer so the new value takes effect.
|
|
23
|
+
*/
|
|
24
|
+
normalize?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Optional makeup gain multiplier applied to the wet path. Useful when the
|
|
27
|
+
* IR is very quiet or very loud and `normalize` is off. Range 0..4,
|
|
28
|
+
* default 1.
|
|
29
|
+
*/
|
|
30
|
+
gain?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convolution effect that convolves the input signal with a user-supplied
|
|
34
|
+
* impulse response (IR). Unlike {@link ReverbEffect}, which generates a
|
|
35
|
+
* procedural noise-based IR, `ConvolutionEffect` accepts a *real* decoded IR —
|
|
36
|
+
* enabling convolution reverb from acoustic-space captures, cabinet/speaker
|
|
37
|
+
* simulations, telephone/pipe character filtering, and any other linear
|
|
38
|
+
* time-invariant transformation.
|
|
39
|
+
*
|
|
40
|
+
* Pass the IR as an `AudioBuffer` (typically decoded via
|
|
41
|
+
* `AudioContext.decodeAudioData`) or as a `Sound` (its `audioBuffer` is used).
|
|
42
|
+
* Omitting the IR leaves `convolver.buffer` as `null`, making the wet path
|
|
43
|
+
* silent and the effect act as a passthrough until {@link setImpulse} is
|
|
44
|
+
* called — safe to add to a bus before an IR is available.
|
|
45
|
+
*
|
|
46
|
+
* Node graph:
|
|
47
|
+
* ```
|
|
48
|
+
* input(GainNode) → dryGain → output(GainNode)
|
|
49
|
+
* input → convolver → wetGain → output
|
|
50
|
+
* ```
|
|
51
|
+
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet × gain`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* await loader.load(Sound, { hall: 'hall.wav' });
|
|
56
|
+
* const reverb = new ConvolutionEffect({ impulse: loader.get(Sound, 'hall'), wet: 0.6 });
|
|
57
|
+
* bus.addEffect(reverb);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare class ConvolutionEffect extends AudioEffect {
|
|
61
|
+
private _setup;
|
|
62
|
+
private _wet;
|
|
63
|
+
private _normalize;
|
|
64
|
+
private _gain;
|
|
65
|
+
private _pendingImpulse;
|
|
66
|
+
private readonly _onAudioContextReady;
|
|
67
|
+
constructor(options?: ConvolutionEffectOptions);
|
|
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
|
+
* Wet (convolved) mix level, 0..1. The dry level is automatically `1 - wet`.
|
|
80
|
+
* Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
|
|
81
|
+
*/
|
|
82
|
+
get wet(): number;
|
|
83
|
+
set wet(value: number);
|
|
84
|
+
/**
|
|
85
|
+
* Whether the browser normalizes the IR for equal-power loudness. Mirrors
|
|
86
|
+
* `ConvolverNode.normalize`. Default `true`.
|
|
87
|
+
*
|
|
88
|
+
* Changing this at runtime re-assigns the current buffer so the new value
|
|
89
|
+
* takes effect (a Web Audio requirement: `normalize` is only applied on
|
|
90
|
+
* buffer assignment).
|
|
91
|
+
*/
|
|
92
|
+
get normalize(): boolean;
|
|
93
|
+
set normalize(value: boolean);
|
|
94
|
+
/**
|
|
95
|
+
* Makeup gain multiplier applied to the wet path. Range 0..4, default 1.
|
|
96
|
+
* Adjusting this changes the wet-path amplitude without altering the
|
|
97
|
+
* dry/wet balance ratio.
|
|
98
|
+
*/
|
|
99
|
+
get gain(): number;
|
|
100
|
+
set gain(value: number);
|
|
101
|
+
/**
|
|
102
|
+
* Set or replace the impulse response. Accepts a decoded `AudioBuffer`, a
|
|
103
|
+
* `Sound` (its `audioBuffer` is used), or `null` to clear the IR (wet path
|
|
104
|
+
* goes silent). Safe to call before the audio context is ready — the impulse
|
|
105
|
+
* is stored and applied once nodes are created.
|
|
106
|
+
*
|
|
107
|
+
* **Web Audio note:** `normalize` is written to the convolver *before*
|
|
108
|
+
* `buffer` is assigned, as required by the spec for the value to take effect.
|
|
109
|
+
*/
|
|
110
|
+
setImpulse(ir: AudioBuffer | Sound | null): void;
|
|
111
|
+
destroy(): void;
|
|
112
|
+
private _resolveBuffer;
|
|
113
|
+
private _setupNodes;
|
|
114
|
+
}
|