@codexo/exojs-audio-fx 0.15.3 → 0.16.1

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.
Files changed (114) hide show
  1. package/dist/esm/AudioAnalyser.d.ts +4 -3
  2. package/dist/esm/AudioAnalyser.d.ts.map +1 -0
  3. package/dist/esm/AudioAnalyser.js +365 -468
  4. package/dist/esm/AudioAnalyser.js.map +1 -1
  5. package/dist/esm/BeatDetector.d.ts +16 -15
  6. package/dist/esm/BeatDetector.d.ts.map +1 -0
  7. package/dist/esm/BeatDetector.js +370 -428
  8. package/dist/esm/BeatDetector.js.map +1 -1
  9. package/dist/esm/dsp/fft.d.ts +5 -5
  10. package/dist/esm/dsp/fft.d.ts.map +1 -0
  11. package/dist/esm/dsp/mel.d.ts +6 -6
  12. package/dist/esm/dsp/mel.d.ts.map +1 -0
  13. package/dist/esm/dsp/mel.js +55 -64
  14. package/dist/esm/dsp/mel.js.map +1 -1
  15. package/dist/esm/dsp/tempogram.d.ts +60 -20
  16. package/dist/esm/dsp/tempogram.d.ts.map +1 -0
  17. package/dist/esm/effects/AutoWahEffect.d.ts +3 -2
  18. package/dist/esm/effects/AutoWahEffect.d.ts.map +1 -0
  19. package/dist/esm/effects/AutoWahEffect.js +210 -237
  20. package/dist/esm/effects/AutoWahEffect.js.map +1 -1
  21. package/dist/esm/effects/BitCrusherEffect.d.ts +3 -2
  22. package/dist/esm/effects/BitCrusherEffect.d.ts.map +1 -0
  23. package/dist/esm/effects/BitCrusherEffect.js +72 -70
  24. package/dist/esm/effects/BitCrusherEffect.js.map +1 -1
  25. package/dist/esm/effects/ChorusEffect.d.ts +2 -1
  26. package/dist/esm/effects/ChorusEffect.d.ts.map +1 -0
  27. package/dist/esm/effects/ChorusEffect.js +132 -150
  28. package/dist/esm/effects/ChorusEffect.js.map +1 -1
  29. package/dist/esm/effects/CompressorEffect.d.ts +2 -1
  30. package/dist/esm/effects/CompressorEffect.d.ts.map +1 -0
  31. package/dist/esm/effects/CompressorEffect.js +104 -118
  32. package/dist/esm/effects/CompressorEffect.js.map +1 -1
  33. package/dist/esm/effects/ConvolutionEffect.d.ts +10 -5
  34. package/dist/esm/effects/ConvolutionEffect.d.ts.map +1 -0
  35. package/dist/esm/effects/ConvolutionEffect.js +208 -189
  36. package/dist/esm/effects/ConvolutionEffect.js.map +1 -1
  37. package/dist/esm/effects/DelayEffect.d.ts +1 -0
  38. package/dist/esm/effects/DelayEffect.d.ts.map +1 -0
  39. package/dist/esm/effects/DelayEffect.js +105 -109
  40. package/dist/esm/effects/DelayEffect.js.map +1 -1
  41. package/dist/esm/effects/DistortionEffect.d.ts +4 -3
  42. package/dist/esm/effects/DistortionEffect.d.ts.map +1 -0
  43. package/dist/esm/effects/DistortionEffect.js +190 -195
  44. package/dist/esm/effects/DistortionEffect.js.map +1 -1
  45. package/dist/esm/effects/DuckingEffect.d.ts +3 -2
  46. package/dist/esm/effects/DuckingEffect.d.ts.map +1 -0
  47. package/dist/esm/effects/DuckingEffect.js +91 -172
  48. package/dist/esm/effects/DuckingEffect.js.map +1 -1
  49. package/dist/esm/effects/EqualizerEffect.d.ts +1 -0
  50. package/dist/esm/effects/EqualizerEffect.d.ts.map +1 -0
  51. package/dist/esm/effects/EqualizerEffect.js +120 -133
  52. package/dist/esm/effects/EqualizerEffect.js.map +1 -1
  53. package/dist/esm/effects/FlangerEffect.d.ts +7 -6
  54. package/dist/esm/effects/FlangerEffect.d.ts.map +1 -0
  55. package/dist/esm/effects/FlangerEffect.js +172 -201
  56. package/dist/esm/effects/FlangerEffect.js.map +1 -1
  57. package/dist/esm/effects/GranularEffect.d.ts +3 -2
  58. package/dist/esm/effects/GranularEffect.d.ts.map +1 -0
  59. package/dist/esm/effects/GranularEffect.js +100 -95
  60. package/dist/esm/effects/GranularEffect.js.map +1 -1
  61. package/dist/esm/effects/LimiterEffect.d.ts +1 -0
  62. package/dist/esm/effects/LimiterEffect.d.ts.map +1 -0
  63. package/dist/esm/effects/LimiterEffect.js +182 -194
  64. package/dist/esm/effects/LimiterEffect.js.map +1 -1
  65. package/dist/esm/effects/PhaserEffect.d.ts +2 -1
  66. package/dist/esm/effects/PhaserEffect.d.ts.map +1 -0
  67. package/dist/esm/effects/PhaserEffect.js +214 -254
  68. package/dist/esm/effects/PhaserEffect.js.map +1 -1
  69. package/dist/esm/effects/PingPongDelayEffect.d.ts +2 -1
  70. package/dist/esm/effects/PingPongDelayEffect.d.ts.map +1 -0
  71. package/dist/esm/effects/PingPongDelayEffect.js +172 -185
  72. package/dist/esm/effects/PingPongDelayEffect.js.map +1 -1
  73. package/dist/esm/effects/PitchShiftEffect.d.ts +3 -2
  74. package/dist/esm/effects/PitchShiftEffect.d.ts.map +1 -0
  75. package/dist/esm/effects/PitchShiftEffect.js +60 -60
  76. package/dist/esm/effects/PitchShiftEffect.js.map +1 -1
  77. package/dist/esm/effects/ReverbEffect.d.ts +2 -1
  78. package/dist/esm/effects/ReverbEffect.d.ts.map +1 -0
  79. package/dist/esm/effects/ReverbEffect.js +113 -117
  80. package/dist/esm/effects/ReverbEffect.js.map +1 -1
  81. package/dist/esm/effects/RingModulatorEffect.d.ts +4 -3
  82. package/dist/esm/effects/RingModulatorEffect.d.ts.map +1 -0
  83. package/dist/esm/effects/RingModulatorEffect.js +153 -161
  84. package/dist/esm/effects/RingModulatorEffect.js.map +1 -1
  85. package/dist/esm/effects/TremoloEffect.d.ts +1 -0
  86. package/dist/esm/effects/TremoloEffect.d.ts.map +1 -0
  87. package/dist/esm/effects/TremoloEffect.js +193 -201
  88. package/dist/esm/effects/TremoloEffect.js.map +1 -1
  89. package/dist/esm/effects/VocoderEffect.d.ts +2 -1
  90. package/dist/esm/effects/VocoderEffect.d.ts.map +1 -0
  91. package/dist/esm/effects/VocoderEffect.js +69 -80
  92. package/dist/esm/effects/VocoderEffect.js.map +1 -1
  93. package/dist/esm/index.d.ts +2 -1
  94. package/dist/esm/index.d.ts.map +1 -0
  95. package/dist/esm/index.js +23 -22
  96. package/dist/esm/worklets/beat-detector.worklet.js +5 -1162
  97. package/dist/esm/worklets/beat-detector.worklet.js.map +1 -1
  98. package/dist/esm/worklets/bit-crusher.worklet.js +5 -44
  99. package/dist/esm/worklets/bit-crusher.worklet.js.map +1 -1
  100. package/dist/esm/worklets/ducking.worklet.js +6 -0
  101. package/dist/esm/worklets/ducking.worklet.js.map +1 -0
  102. package/dist/esm/worklets/granular.worklet.js +5 -97
  103. package/dist/esm/worklets/granular.worklet.js.map +1 -1
  104. package/dist/esm/worklets/pitch-shift.worklet.js +5 -128
  105. package/dist/esm/worklets/pitch-shift.worklet.js.map +1 -1
  106. package/dist/esm/worklets/vocoder.worklet.js +5 -93
  107. package/dist/esm/worklets/vocoder.worklet.js.map +1 -1
  108. package/package.json +6 -6
  109. package/dist/esm/index.js.map +0 -1
  110. package/dist/esm/worklets/beat-detector.worklet.d.ts +0 -1
  111. package/dist/esm/worklets/bit-crusher.worklet.d.ts +0 -1
  112. package/dist/esm/worklets/granular.worklet.d.ts +0 -1
  113. package/dist/esm/worklets/pitch-shift.worklet.d.ts +0 -1
  114. package/dist/esm/worklets/vocoder.worklet.d.ts +0 -1
@@ -1,241 +1,214 @@
1
- import { AudioEffect, onAudioContextReady, isAudioContextReady, getAudioContext } from '@codexo/exojs';
1
+ import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
2
2
 
3
+ //#region src/effects/AutoWahEffect.ts
3
4
  /**
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
- }
5
+ * Auto-wah effect that uses an amplitude envelope follower to modulate a
6
+ * bandpass filter, creating the characteristic "wah" sweep driven by the
7
+ * loudness of the input signal.
8
+ *
9
+ * The envelope follower is built entirely from native Web Audio nodes - no
10
+ * `ScriptProcessor` or `AudioWorklet` required:
11
+ *
12
+ * 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),
13
+ * converting the AC audio signal to a unipolar amplitude proxy.
14
+ * 2. A `BiquadFilterNode` (lowpass) smooths the rectified signal. The cutoff is
15
+ * derived from `responseMs` to control attack/release speed.
16
+ * 3. A `GainNode` scales the smoothed envelope by `sensitivity` (Hz/unit) and
17
+ * connects its output directly to the wah filter's `frequency` `AudioParam`,
18
+ * sweeping the filter centre upward with input loudness.
19
+ *
20
+ * Node graph:
21
+ * ```
22
+ * inputGain ─┬─ dryGain ─────────────────────────────┐
23
+ * │ ├── outputGain
24
+ * └─ wahFilter(bandpass) ─── wetGain ──────┘
25
+ *
26
+ * Envelope (control) path - parallel off inputGain, sums into wahFilter.frequency:
27
+ * inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)
28
+ * → sensitivityGain → wahFilter.frequency (AudioParam)
29
+ * ```
30
+ *
31
+ * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const wah = new AutoWahEffect({ baseFrequency: 300, sensitivity: 2500, wet: 0.8 });
36
+ * bus.addEffect(wah);
37
+ * ```
38
+ */
39
+ var AutoWahEffect = class AutoWahEffect extends AudioEffect {
40
+ _setup = null;
41
+ _baseFrequency;
42
+ _sensitivity;
43
+ _q;
44
+ _responseMs;
45
+ _wet;
46
+ _onAudioContextReady = (ctx) => {
47
+ onAudioContextReady.remove(this._onAudioContextReady);
48
+ this._setupNodes(ctx);
49
+ };
50
+ constructor(options = {}) {
51
+ super();
52
+ this._baseFrequency = Math.max(50, Math.min(2e3, options.baseFrequency ?? 200));
53
+ this._sensitivity = Math.max(0, Math.min(6e3, options.sensitivity ?? 3e3));
54
+ this._q = Math.max(.1, Math.min(20, options.q ?? 4));
55
+ this._responseMs = Math.max(1, Math.min(500, options.responseMs ?? 30));
56
+ this._wet = Math.max(0, Math.min(1, options.wet ?? .7));
57
+ if (isAudioContextReady()) this._setupNodes(getAudioContext());
58
+ else onAudioContextReady.add(this._onAudioContextReady);
59
+ }
60
+ /**
61
+ * The node where audio enters this effect. Throws if the audio context is
62
+ * not yet initialized.
63
+ */
64
+ get inputNode() {
65
+ if (!this._setup) throw new Error("AutoWahEffect not yet initialized.");
66
+ return this._setup.inputGain;
67
+ }
68
+ /**
69
+ * The node where audio exits this effect. Throws if the audio context is
70
+ * not yet initialized.
71
+ */
72
+ get outputNode() {
73
+ if (!this._setup) throw new Error("AutoWahEffect not yet initialized.");
74
+ return this._setup.outputGain;
75
+ }
76
+ /**
77
+ * Centre frequency of the wah filter in Hz. Range 50..2000, default 200.
78
+ * Changes are ramped smoothly via `setTargetAtTime`.
79
+ */
80
+ get baseFrequency() {
81
+ return this._baseFrequency;
82
+ }
83
+ set baseFrequency(value) {
84
+ this._baseFrequency = Math.max(50, Math.min(2e3, value));
85
+ if (this._setup) this._setup.wahFilter.frequency.setTargetAtTime(this._baseFrequency, this._setup.wahFilter.context.currentTime, .01);
86
+ }
87
+ /**
88
+ * Envelope sensitivity in Hz/unit: the maximum filter sweep above
89
+ * `baseFrequency` when input is at full amplitude. Range 0..6000, default 3000.
90
+ * Changes are ramped smoothly via `setTargetAtTime`.
91
+ */
92
+ get sensitivity() {
93
+ return this._sensitivity;
94
+ }
95
+ set sensitivity(value) {
96
+ this._sensitivity = Math.max(0, Math.min(6e3, value));
97
+ if (this._setup) this._setup.sensitivityGain.gain.setTargetAtTime(this._sensitivity, this._setup.sensitivityGain.context.currentTime, .01);
98
+ }
99
+ /**
100
+ * Q (resonance) of the bandpass wah filter. Range 0.1..20, default 4.
101
+ * Changes are ramped smoothly via `setTargetAtTime`.
102
+ */
103
+ get q() {
104
+ return this._q;
105
+ }
106
+ set q(value) {
107
+ this._q = Math.max(.1, Math.min(20, value));
108
+ if (this._setup) this._setup.wahFilter.Q.setTargetAtTime(this._q, this._setup.wahFilter.context.currentTime, .01);
109
+ }
110
+ /**
111
+ * Envelope smoothing time constant in milliseconds. Range 1..500, default 30.
112
+ * Updating this adjusts the smoothing lowpass cutoff immediately via
113
+ * `setTargetAtTime`.
114
+ */
115
+ get responseMs() {
116
+ return this._responseMs;
117
+ }
118
+ set responseMs(value) {
119
+ this._responseMs = Math.max(1, Math.min(500, value));
120
+ if (this._setup) this._setup.smoothingLowpass.frequency.setTargetAtTime(this._smoothingCutoff(), this._setup.smoothingLowpass.context.currentTime, .01);
121
+ }
122
+ /**
123
+ * Wet (wah-filtered) mix level, 0..1. The dry level is automatically
124
+ * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 0.7.
125
+ */
126
+ get wet() {
127
+ return this._wet;
128
+ }
129
+ set wet(value) {
130
+ this._wet = Math.max(0, Math.min(1, value));
131
+ if (this._setup) {
132
+ const ctx = this._setup.wetGain.context;
133
+ this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
134
+ this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
135
+ }
136
+ }
137
+ destroy() {
138
+ onAudioContextReady.remove(this._onAudioContextReady);
139
+ if (this._setup) {
140
+ this._setup.inputGain.disconnect();
141
+ this._setup.dryGain.disconnect();
142
+ this._setup.wetGain.disconnect();
143
+ this._setup.sensitivityGain.disconnect();
144
+ this._setup.wahFilter.disconnect();
145
+ this._setup.smoothingLowpass.disconnect();
146
+ this._setup.rectifier.disconnect();
147
+ this._setup.outputGain.disconnect();
148
+ this._setup = null;
149
+ }
150
+ }
151
+ /** Converts `responseMs` to a lowpass cutoff frequency using f = 1/(2π×τ). */
152
+ _smoothingCutoff() {
153
+ return 1e3 / (2 * Math.PI * this._responseMs);
154
+ }
155
+ /**
156
+ * Builds a 256-point `Float32Array` curve approximating the full-wave
157
+ * rectifier `f(x) = |x|` for use with `WaveShaperNode`.
158
+ */
159
+ static _makeRectifierCurve() {
160
+ const n = 256;
161
+ const curve = new Float32Array(n);
162
+ for (let i = 0; i < n; i++) {
163
+ const x = i * 2 / 255 - 1;
164
+ curve[i] = Math.abs(x);
165
+ }
166
+ return curve;
167
+ }
168
+ _setupNodes(ctx) {
169
+ const inputGain = ctx.createGain();
170
+ const outputGain = ctx.createGain();
171
+ const dryGain = ctx.createGain();
172
+ const wetGain = ctx.createGain();
173
+ const sensitivityGain = ctx.createGain();
174
+ const wahFilter = ctx.createBiquadFilter();
175
+ const smoothingLowpass = ctx.createBiquadFilter();
176
+ const rectifier = ctx.createWaveShaper();
177
+ inputGain.gain.setValueAtTime(1, ctx.currentTime);
178
+ outputGain.gain.setValueAtTime(1, ctx.currentTime);
179
+ dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
180
+ wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
181
+ sensitivityGain.gain.setValueAtTime(this._sensitivity, ctx.currentTime);
182
+ wahFilter.type = "bandpass";
183
+ wahFilter.frequency.setValueAtTime(this._baseFrequency, ctx.currentTime);
184
+ wahFilter.Q.setValueAtTime(this._q, ctx.currentTime);
185
+ rectifier.curve = AutoWahEffect._makeRectifierCurve();
186
+ rectifier.oversample = "4x";
187
+ smoothingLowpass.type = "lowpass";
188
+ smoothingLowpass.frequency.setValueAtTime(this._smoothingCutoff(), ctx.currentTime);
189
+ smoothingLowpass.Q.setValueAtTime(.5, ctx.currentTime);
190
+ inputGain.connect(dryGain);
191
+ dryGain.connect(outputGain);
192
+ inputGain.connect(wahFilter);
193
+ wahFilter.connect(wetGain);
194
+ wetGain.connect(outputGain);
195
+ inputGain.connect(rectifier);
196
+ rectifier.connect(smoothingLowpass);
197
+ smoothingLowpass.connect(sensitivityGain);
198
+ sensitivityGain.connect(wahFilter.frequency);
199
+ this._setup = {
200
+ inputGain,
201
+ outputGain,
202
+ dryGain,
203
+ wetGain,
204
+ sensitivityGain,
205
+ wahFilter,
206
+ smoothingLowpass,
207
+ rectifier
208
+ };
209
+ }
210
+ };
239
211
 
212
+ //#endregion
240
213
  export { AutoWahEffect };
241
- //# sourceMappingURL=AutoWahEffect.js.map
214
+ //# sourceMappingURL=AutoWahEffect.js.map
@@ -1 +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,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AAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;QACnF,gBAAgB,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,WAAW,CAAC;;;AAKvD,QAAA,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;AAC1B,QAAA,OAAO,CAAC,OAAO,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;;;;"}
1
+ {"version":3,"file":"AutoWahEffect.js","names":[],"sources":["../../../src/effects/AutoWahEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link AutoWahEffect}. */\nexport interface AutoWahEffectOptions {\n /**\n * Centre frequency of the wah bandpass filter in Hz. The envelope control\n * signal sweeps the filter upward from this base. Range 50..2000, default 200.\n */\n baseFrequency?: number;\n /**\n * Envelope sensitivity: Hz of filter-frequency sweep added per unit of\n * rectified envelope amplitude. At full signal amplitude the filter shifts up\n * by this amount above `baseFrequency`. Range 0..6000, default 3000.\n */\n sensitivity?: number;\n /**\n * Q (resonance) of the bandpass wah filter. Higher values produce a narrower,\n * more pronounced peak. Range 0.1..20, default 4.\n */\n q?: number;\n /**\n * Envelope smoothing time constant in milliseconds. Longer values make the\n * wah react slowly (legato); shorter values produce a snappier attack\n * (percussive). Translated to the smoothing lowpass cutoff as\n * `1000 / (2π × responseMs)` Hz. Range 1..500, default 30.\n */\n responseMs?: number;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 0.7.\n */\n wet?: number;\n}\n\ninterface AutoWahEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly sensitivityGain: GainNode;\n readonly wahFilter: BiquadFilterNode;\n readonly smoothingLowpass: BiquadFilterNode;\n readonly rectifier: WaveShaperNode;\n}\n\n/**\n * Auto-wah effect that uses an amplitude envelope follower to modulate a\n * bandpass filter, creating the characteristic \"wah\" sweep driven by the\n * loudness of the input signal.\n *\n * The envelope follower is built entirely from native Web Audio nodes - no\n * `ScriptProcessor` or `AudioWorklet` required:\n *\n * 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),\n * converting the AC audio signal to a unipolar amplitude proxy.\n * 2. A `BiquadFilterNode` (lowpass) smooths the rectified signal. The cutoff is\n * derived from `responseMs` to control attack/release speed.\n * 3. A `GainNode` scales the smoothed envelope by `sensitivity` (Hz/unit) and\n * connects its output directly to the wah filter's `frequency` `AudioParam`,\n * sweeping the filter centre upward with input loudness.\n *\n * Node graph:\n * ```\n * inputGain ─┬─ dryGain ─────────────────────────────┐\n * │ ├── outputGain\n * └─ wahFilter(bandpass) ─── wetGain ──────┘\n *\n * Envelope (control) path - parallel off inputGain, sums into wahFilter.frequency:\n * inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)\n * → sensitivityGain → wahFilter.frequency (AudioParam)\n * ```\n *\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.\n *\n * @example\n * ```ts\n * const wah = new AutoWahEffect({ baseFrequency: 300, sensitivity: 2500, wet: 0.8 });\n * bus.addEffect(wah);\n * ```\n */\nexport class AutoWahEffect extends AudioEffect {\n private _setup: AutoWahEffectSetup | null = null;\n private _baseFrequency: number;\n private _sensitivity: number;\n private _q: number;\n private _responseMs: number;\n private _wet: number;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\n\n public constructor(options: AutoWahEffectOptions = {}) {\n super();\n this._baseFrequency = Math.max(50, Math.min(2000, options.baseFrequency ?? 200));\n this._sensitivity = Math.max(0, Math.min(6000, options.sensitivity ?? 3000));\n this._q = Math.max(0.1, Math.min(20, options.q ?? 4));\n this._responseMs = Math.max(1, Math.min(500, options.responseMs ?? 30));\n this._wet = Math.max(0, Math.min(1, options.wet ?? 0.7));\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('AutoWahEffect 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('AutoWahEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n // ---------------------------------------------------------------------------\n // Getters / setters\n // ---------------------------------------------------------------------------\n\n /**\n * Centre frequency of the wah filter in Hz. Range 50..2000, default 200.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get baseFrequency(): number {\n return this._baseFrequency;\n }\n\n public set baseFrequency(value: number) {\n this._baseFrequency = Math.max(50, Math.min(2000, value));\n if (this._setup) {\n this._setup.wahFilter.frequency.setTargetAtTime(this._baseFrequency, this._setup.wahFilter.context.currentTime, 0.01);\n }\n }\n\n /**\n * Envelope sensitivity in Hz/unit: the maximum filter sweep above\n * `baseFrequency` when input is at full amplitude. Range 0..6000, default 3000.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get sensitivity(): number {\n return this._sensitivity;\n }\n\n public set sensitivity(value: number) {\n this._sensitivity = Math.max(0, Math.min(6000, value));\n if (this._setup) {\n this._setup.sensitivityGain.gain.setTargetAtTime(this._sensitivity, this._setup.sensitivityGain.context.currentTime, 0.01);\n }\n }\n\n /**\n * Q (resonance) of the bandpass wah filter. Range 0.1..20, default 4.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get q(): number {\n return this._q;\n }\n\n public set q(value: number) {\n this._q = Math.max(0.1, Math.min(20, value));\n if (this._setup) {\n this._setup.wahFilter.Q.setTargetAtTime(this._q, this._setup.wahFilter.context.currentTime, 0.01);\n }\n }\n\n /**\n * Envelope smoothing time constant in milliseconds. Range 1..500, default 30.\n * Updating this adjusts the smoothing lowpass cutoff immediately via\n * `setTargetAtTime`.\n */\n public get responseMs(): number {\n return this._responseMs;\n }\n\n public set responseMs(value: number) {\n this._responseMs = Math.max(1, Math.min(500, value));\n if (this._setup) {\n this._setup.smoothingLowpass.frequency.setTargetAtTime(this._smoothingCutoff(), this._setup.smoothingLowpass.context.currentTime, 0.01);\n }\n }\n\n /**\n * Wet (wah-filtered) mix level, 0..1. The dry level is automatically\n * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 0.7.\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 // Lifecycle\n // ---------------------------------------------------------------------------\n\n public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n if (this._setup) {\n this._setup.inputGain.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.sensitivityGain.disconnect();\n this._setup.wahFilter.disconnect();\n this._setup.smoothingLowpass.disconnect();\n this._setup.rectifier.disconnect();\n this._setup.outputGain.disconnect();\n this._setup = null;\n }\n }\n\n // ---------------------------------------------------------------------------\n // Private\n // ---------------------------------------------------------------------------\n\n /** Converts `responseMs` to a lowpass cutoff frequency using f = 1/(2π×τ). */\n private _smoothingCutoff(): number {\n return 1000 / (2 * Math.PI * this._responseMs);\n }\n\n /**\n * Builds a 256-point `Float32Array` curve approximating the full-wave\n * rectifier `f(x) = |x|` for use with `WaveShaperNode`.\n */\n private static _makeRectifierCurve(): Float32Array<ArrayBuffer> {\n const n = 256;\n const curve = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const x = (i * 2) / (n - 1) - 1; // maps index to -1..1\n curve[i] = Math.abs(x);\n }\n return curve;\n }\n\n private _setupNodes(ctx: AudioContext): void {\n // Audio-path gain nodes (createGain order: 0=inputGain, 1=outputGain,\n // 2=dryGain, 3=wetGain, 4=sensitivityGain).\n const inputGain = ctx.createGain();\n const outputGain = ctx.createGain();\n const dryGain = ctx.createGain();\n const wetGain = ctx.createGain();\n const sensitivityGain = ctx.createGain();\n\n // Wah filter (audio path) and smoothing filter (envelope control path)\n // (createBiquadFilter order: 0=wahFilter, 1=smoothingLowpass).\n const wahFilter = ctx.createBiquadFilter();\n const smoothingLowpass = ctx.createBiquadFilter();\n\n // Full-wave rectifier for the envelope follower.\n const rectifier = ctx.createWaveShaper();\n\n // ── Initialize values ────────────────────────────────────────────────────\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 sensitivityGain.gain.setValueAtTime(this._sensitivity, ctx.currentTime);\n\n // Wah bandpass filter: base frequency and Q; envelope signal adds on top.\n wahFilter.type = 'bandpass';\n wahFilter.frequency.setValueAtTime(this._baseFrequency, ctx.currentTime);\n wahFilter.Q.setValueAtTime(this._q, ctx.currentTime);\n\n // Rectifier: full-wave |x| curve; 4× oversampling for accuracy.\n rectifier.curve = AutoWahEffect._makeRectifierCurve();\n rectifier.oversample = '4x';\n\n // Smoothing lowpass: cutoff derived from responseMs; low Q for no ringing.\n smoothingLowpass.type = 'lowpass';\n smoothingLowpass.frequency.setValueAtTime(this._smoothingCutoff(), ctx.currentTime);\n smoothingLowpass.Q.setValueAtTime(0.5, ctx.currentTime);\n\n // ── Wiring ───────────────────────────────────────────────────────────────\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet (audio) path: inputGain → wahFilter → wetGain → outputGain\n inputGain.connect(wahFilter);\n wahFilter.connect(wetGain);\n wetGain.connect(outputGain);\n\n // Envelope (control) path - parallel off inputGain, drives wahFilter.frequency.\n // The rectified+smoothed signal is scaled by sensitivityGain and summed into\n // the wahFilter frequency AudioParam, sweeping the filter with input loudness.\n inputGain.connect(rectifier);\n rectifier.connect(smoothingLowpass);\n smoothingLowpass.connect(sensitivityGain);\n sensitivityGain.connect(wahFilter.frequency as unknown as AudioNode);\n\n this._setup = { inputGain, outputGain, dryGain, wetGain, sensitivityGain, wahFilter, smoothingLowpass, rectifier };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,IAAa,gBAAb,MAAa,sBAAsB,YAAY;CAC7C,AAAQ,SAAoC;CAC5C,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAiB,wBAAwB,QAA4B;EACnE,oBAAoB,OAAO,KAAK,oBAAoB;EACpD,KAAK,YAAY,GAAG;CACtB;CAEA,AAAO,YAAY,UAAgC,CAAC,GAAG;EACrD,MAAM;EACN,KAAK,iBAAiB,KAAK,IAAI,IAAI,KAAK,IAAI,KAAM,QAAQ,iBAAiB,GAAG,CAAC;EAC/E,KAAK,eAAe,KAAK,IAAI,G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,QAAQ,UAAU,SAAiC;EAEnE,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAiB;GAAW;GAAkB;EAAU;CACnH;AACF"}
@@ -19,9 +19,9 @@ export interface BitCrusherEffectOptions {
19
19
  * Lo-fi bit-crusher effect implemented as a {@link WorkletEffect}. Applies two
20
20
  * classic degradation stages in series:
21
21
  *
22
- * 1. **Bit-depth reduction** — each sample is quantized to `2^bits` discrete
22
+ * 1. **Bit-depth reduction** - each sample is quantized to `2^bits` discrete
23
23
  * levels, adding harmonic distortion characteristic of low-resolution audio.
24
- * 2. **Sample-rate reduction** — a phase-accumulator sample-and-hold circuit
24
+ * 2. **Sample-rate reduction** - a phase-accumulator sample-and-hold circuit
25
25
  * re-latches the (quantized) input only `normFreq` times per input sample on
26
26
  * average, producing aliasing artefacts reminiscent of early digital hardware.
27
27
  *
@@ -61,3 +61,4 @@ export declare class BitCrusherEffect extends WorkletEffect {
61
61
  get frequencyReduction(): number;
62
62
  set frequencyReduction(value: number);
63
63
  }
64
+ //# sourceMappingURL=BitCrusherEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitCrusherEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/BitCrusherEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,mBAAmB,CAAS;gBAEjB,OAAO,GAAE,uBAA4B;IAOxD,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;IACD,SAAS,KAAK,cAAc,IAAI,MAAM,CAErC;cAEkB,eAAe,IAAI,IAAI;IAK1C;;;OAGG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IACD,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAG5B;IAED;;;;OAIG;IACH,IAAW,kBAAkB,IAAI,MAAM,CAEtC;IACD,IAAW,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAG1C;CACF"}