@codexo/exojs-audio-fx 0.15.2 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +7 -7
  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,205 +1,197 @@
1
- import { AudioEffect, onAudioContextReady, isAudioContextReady, getAudioContext } from '@codexo/exojs';
1
+ import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
2
2
 
3
+ //#region src/effects/TremoloEffect.ts
3
4
  /**
4
- * Tremolo effect that amplitude-modulates the signal with a sine LFO using native WebAudio nodes.
5
- *
6
- * A sine-wave LFO drives a `GainNode`'s gain to produce the characteristic volume pulsing of
7
- * tremolo. The base gain is `1 - depth` and the LFO peak deviation is `depth`, so the gain
8
- * oscillates between `1 - 2 * depth` and `1`. Optionally the same LFO can drive a
9
- * `StereoPannerNode.pan` for a synchronized auto-pan effect.
10
- *
11
- * Node graph (`autoPan = false`):
12
- * ```
13
- * inputGain ┬── dryGain ──────────────────────────┐
14
- * │ ├── outputGain
15
- * └── tremoloGain ── wetGain ─────────────┘
16
- *
17
- * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
18
- * ```
19
- *
20
- * Node graph (`autoPan = true`):
21
- * ```
22
- * inputGain ┬── dryGain ──────────────────────────────────┐
23
- * │ ├── outputGain
24
- * └── tremoloGain ── panner ── wetGain ──────────┘
25
- *
26
- * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
27
- * lfoOscillator ── panGain (depth) ── panner.pan
28
- * ```
29
- *
30
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth`.
31
- *
32
- * @example
33
- * ```ts
34
- * // Classic tremolo at 5 Hz, 70 % depth, full wet
35
- * const tremolo = new TremoloEffect({ rateHz: 5, depth: 0.7, wet: 1 });
36
- * bus.addEffect(tremolo);
37
- *
38
- * // Slow auto-pan at 0.5 Hz
39
- * const autopan = new TremoloEffect({ rateHz: 0.5, depth: 0.5, autoPan: true });
40
- * bus.addEffect(autopan);
41
- * ```
42
- */
43
- class TremoloEffect extends AudioEffect {
44
- _setup = null;
45
- _rateHz;
46
- _depth;
47
- _autoPan;
48
- _wet;
49
- _onAudioContextReady = (ctx) => {
50
- onAudioContextReady.remove(this._onAudioContextReady);
51
- this._setupNodes(ctx);
52
- };
53
- constructor(options = {}) {
54
- super();
55
- this._rateHz = Math.max(0, Math.min(20, options.rateHz ?? 5));
56
- this._depth = Math.max(0, Math.min(1, options.depth ?? 0.7));
57
- this._autoPan = options.autoPan ?? false;
58
- this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
59
- if (isAudioContextReady()) {
60
- this._setupNodes(getAudioContext());
61
- }
62
- else {
63
- onAudioContextReady.add(this._onAudioContextReady);
64
- }
65
- }
66
- /**
67
- * The node where audio enters this effect. Throws if the audio context is not yet initialized.
68
- */
69
- get inputNode() {
70
- if (!this._setup)
71
- throw new Error('TremoloEffect not yet initialized.');
72
- return this._setup.inputGain;
73
- }
74
- /**
75
- * The node where audio exits this effect. Throws if the audio context is not yet initialized.
76
- */
77
- get outputNode() {
78
- if (!this._setup)
79
- throw new Error('TremoloEffect not yet initialized.');
80
- return this._setup.outputGain;
81
- }
82
- /**
83
- * LFO oscillation rate in Hz. Range 0..20, default 5.
84
- * Ramped via `setTargetAtTime` when changed at runtime.
85
- */
86
- get rateHz() {
87
- return this._rateHz;
88
- }
89
- set rateHz(value) {
90
- this._rateHz = Math.max(0, Math.min(20, value));
91
- if (this._setup) {
92
- this._setup.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._setup.inputGain.context.currentTime, 0.01);
93
- }
94
- }
95
- /**
96
- * Modulation depth, 0..1. At 0 the effect is transparent; at 0.5 the gain briefly
97
- * reaches zero at the trough; at depth>0.5 the gain goes negative (phase inversion).
98
- * Default 0.7. Ramped via `setTargetAtTime`.
99
- */
100
- get depth() {
101
- return this._depth;
102
- }
103
- set depth(value) {
104
- this._depth = Math.max(0, Math.min(1, value));
105
- if (this._setup) {
106
- const t = this._setup.inputGain.context.currentTime;
107
- this._setup.lfoGain.gain.setTargetAtTime(this._depth, t, 0.01);
108
- this._setup.tremoloGain.gain.setTargetAtTime(1 - this._depth, t, 0.01);
109
- if (this._setup.panGain) {
110
- this._setup.panGain.gain.setTargetAtTime(this._depth, t, 0.01);
111
- }
112
- }
113
- }
114
- /**
115
- * Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};
116
- * read-only at runtime. Default `false`.
117
- */
118
- get autoPan() {
119
- return this._autoPan;
120
- }
121
- /**
122
- * Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.
123
- * Ramped via `setTargetAtTime` when changed at runtime.
124
- */
125
- get wet() {
126
- return this._wet;
127
- }
128
- set wet(value) {
129
- this._wet = Math.max(0, Math.min(1, value));
130
- if (this._setup) {
131
- const ctx = this._setup.wetGain.context;
132
- this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, 0.01);
133
- this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, 0.01);
134
- }
135
- }
136
- destroy() {
137
- onAudioContextReady.remove(this._onAudioContextReady);
138
- if (this._setup) {
139
- this._setup.lfoOscillator.stop();
140
- this._setup.lfoOscillator.disconnect();
141
- this._setup.lfoGain.disconnect();
142
- this._setup.tremoloGain.disconnect();
143
- if (this._setup.panner)
144
- this._setup.panner.disconnect();
145
- if (this._setup.panGain)
146
- this._setup.panGain.disconnect();
147
- this._setup.dryGain.disconnect();
148
- this._setup.wetGain.disconnect();
149
- this._setup.inputGain.disconnect();
150
- this._setup.outputGain.disconnect();
151
- this._setup = null;
152
- }
153
- }
154
- _setupNodes(ctx) {
155
- const inputGain = ctx.createGain();
156
- const outputGain = ctx.createGain();
157
- const dryGain = ctx.createGain();
158
- const wetGain = ctx.createGain();
159
- const tremoloGain = ctx.createGain();
160
- const lfoGain = ctx.createGain();
161
- inputGain.gain.setValueAtTime(1, ctx.currentTime);
162
- outputGain.gain.setValueAtTime(1, ctx.currentTime);
163
- dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
164
- wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
165
- // Base gain = 1 - depth; the LFO (amplitude = depth) is added on top via AudioParam
166
- // modulation, making the effective gain oscillate in [1 - 2*depth, 1].
167
- tremoloGain.gain.setValueAtTime(1 - this._depth, ctx.currentTime);
168
- lfoGain.gain.setValueAtTime(this._depth, ctx.currentTime);
169
- const lfoOscillator = ctx.createOscillator();
170
- lfoOscillator.type = 'sine';
171
- lfoOscillator.frequency.value = this._rateHz;
172
- // LFO → lfoGain → tremoloGain.gain (AudioParam modulation)
173
- lfoOscillator.connect(lfoGain);
174
- lfoGain.connect(tremoloGain.gain);
175
- // Dry path: inputGain → dryGain → outputGain
176
- inputGain.connect(dryGain);
177
- dryGain.connect(outputGain);
178
- let panner = null;
179
- let panGain = null;
180
- if (this._autoPan) {
181
- panner = ctx.createStereoPanner();
182
- panGain = ctx.createGain();
183
- panGain.gain.setValueAtTime(this._depth, ctx.currentTime);
184
- // LFO → panGain → panner.pan (AudioParam modulation)
185
- lfoOscillator.connect(panGain);
186
- panGain.connect(panner.pan);
187
- // Wet path: inputGain → tremoloGain → panner → wetGain → outputGain
188
- inputGain.connect(tremoloGain);
189
- tremoloGain.connect(panner);
190
- panner.connect(wetGain);
191
- wetGain.connect(outputGain);
192
- }
193
- else {
194
- // Wet path: inputGain → tremoloGain → wetGain → outputGain
195
- inputGain.connect(tremoloGain);
196
- tremoloGain.connect(wetGain);
197
- wetGain.connect(outputGain);
198
- }
199
- lfoOscillator.start();
200
- this._setup = { inputGain, outputGain, dryGain, wetGain, tremoloGain, lfoOscillator, lfoGain, panner, panGain };
201
- }
202
- }
5
+ * Tremolo effect that amplitude-modulates the signal with a sine LFO using native WebAudio nodes.
6
+ *
7
+ * A sine-wave LFO drives a `GainNode`'s gain to produce the characteristic volume pulsing of
8
+ * tremolo. The base gain is `1 - depth` and the LFO peak deviation is `depth`, so the gain
9
+ * oscillates between `1 - 2 * depth` and `1`. Optionally the same LFO can drive a
10
+ * `StereoPannerNode.pan` for a synchronized auto-pan effect.
11
+ *
12
+ * Node graph (`autoPan = false`):
13
+ * ```
14
+ * inputGain ┬── dryGain ──────────────────────────┐
15
+ * │ ├── outputGain
16
+ * └── tremoloGain ── wetGain ─────────────┘
17
+ *
18
+ * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
19
+ * ```
20
+ *
21
+ * Node graph (`autoPan = true`):
22
+ * ```
23
+ * inputGain ┬── dryGain ──────────────────────────────────┐
24
+ * │ ├── outputGain
25
+ * └── tremoloGain ── panner ── wetGain ──────────┘
26
+ *
27
+ * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
28
+ * lfoOscillator ── panGain (depth) ── panner.pan
29
+ * ```
30
+ *
31
+ * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * // Classic tremolo at 5 Hz, 70 % depth, full wet
36
+ * const tremolo = new TremoloEffect({ rateHz: 5, depth: 0.7, wet: 1 });
37
+ * bus.addEffect(tremolo);
38
+ *
39
+ * // Slow auto-pan at 0.5 Hz
40
+ * const autopan = new TremoloEffect({ rateHz: 0.5, depth: 0.5, autoPan: true });
41
+ * bus.addEffect(autopan);
42
+ * ```
43
+ */
44
+ var TremoloEffect = class extends AudioEffect {
45
+ _setup = null;
46
+ _rateHz;
47
+ _depth;
48
+ _autoPan;
49
+ _wet;
50
+ _onAudioContextReady = (ctx) => {
51
+ onAudioContextReady.remove(this._onAudioContextReady);
52
+ this._setupNodes(ctx);
53
+ };
54
+ constructor(options = {}) {
55
+ super();
56
+ this._rateHz = Math.max(0, Math.min(20, options.rateHz ?? 5));
57
+ this._depth = Math.max(0, Math.min(1, options.depth ?? .7));
58
+ this._autoPan = options.autoPan ?? false;
59
+ this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
60
+ if (isAudioContextReady()) this._setupNodes(getAudioContext());
61
+ else onAudioContextReady.add(this._onAudioContextReady);
62
+ }
63
+ /**
64
+ * The node where audio enters this effect. Throws if the audio context is not yet initialized.
65
+ */
66
+ get inputNode() {
67
+ if (!this._setup) throw new Error("TremoloEffect not yet initialized.");
68
+ return this._setup.inputGain;
69
+ }
70
+ /**
71
+ * The node where audio exits this effect. Throws if the audio context is not yet initialized.
72
+ */
73
+ get outputNode() {
74
+ if (!this._setup) throw new Error("TremoloEffect not yet initialized.");
75
+ return this._setup.outputGain;
76
+ }
77
+ /**
78
+ * LFO oscillation rate in Hz. Range 0..20, default 5.
79
+ * Ramped via `setTargetAtTime` when changed at runtime.
80
+ */
81
+ get rateHz() {
82
+ return this._rateHz;
83
+ }
84
+ set rateHz(value) {
85
+ this._rateHz = Math.max(0, Math.min(20, value));
86
+ if (this._setup) this._setup.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._setup.inputGain.context.currentTime, .01);
87
+ }
88
+ /**
89
+ * Modulation depth, 0..1. At 0 the effect is transparent; at 0.5 the gain briefly
90
+ * reaches zero at the trough; at depth>0.5 the gain goes negative (phase inversion).
91
+ * Default 0.7. Ramped via `setTargetAtTime`.
92
+ */
93
+ get depth() {
94
+ return this._depth;
95
+ }
96
+ set depth(value) {
97
+ this._depth = Math.max(0, Math.min(1, value));
98
+ if (this._setup) {
99
+ const t = this._setup.inputGain.context.currentTime;
100
+ this._setup.lfoGain.gain.setTargetAtTime(this._depth, t, .01);
101
+ this._setup.tremoloGain.gain.setTargetAtTime(1 - this._depth, t, .01);
102
+ if (this._setup.panGain) this._setup.panGain.gain.setTargetAtTime(this._depth, t, .01);
103
+ }
104
+ }
105
+ /**
106
+ * Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};
107
+ * read-only at runtime. Default `false`.
108
+ */
109
+ get autoPan() {
110
+ return this._autoPan;
111
+ }
112
+ /**
113
+ * Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.
114
+ * Ramped via `setTargetAtTime` when changed at runtime.
115
+ */
116
+ get wet() {
117
+ return this._wet;
118
+ }
119
+ set wet(value) {
120
+ this._wet = Math.max(0, Math.min(1, value));
121
+ if (this._setup) {
122
+ const ctx = this._setup.wetGain.context;
123
+ this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
124
+ this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
125
+ }
126
+ }
127
+ destroy() {
128
+ onAudioContextReady.remove(this._onAudioContextReady);
129
+ if (this._setup) {
130
+ this._setup.lfoOscillator.stop();
131
+ this._setup.lfoOscillator.disconnect();
132
+ this._setup.lfoGain.disconnect();
133
+ this._setup.tremoloGain.disconnect();
134
+ if (this._setup.panner) this._setup.panner.disconnect();
135
+ if (this._setup.panGain) this._setup.panGain.disconnect();
136
+ this._setup.dryGain.disconnect();
137
+ this._setup.wetGain.disconnect();
138
+ this._setup.inputGain.disconnect();
139
+ this._setup.outputGain.disconnect();
140
+ this._setup = null;
141
+ }
142
+ }
143
+ _setupNodes(ctx) {
144
+ const inputGain = ctx.createGain();
145
+ const outputGain = ctx.createGain();
146
+ const dryGain = ctx.createGain();
147
+ const wetGain = ctx.createGain();
148
+ const tremoloGain = ctx.createGain();
149
+ const lfoGain = ctx.createGain();
150
+ inputGain.gain.setValueAtTime(1, ctx.currentTime);
151
+ outputGain.gain.setValueAtTime(1, ctx.currentTime);
152
+ dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
153
+ wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
154
+ tremoloGain.gain.setValueAtTime(1 - this._depth, ctx.currentTime);
155
+ lfoGain.gain.setValueAtTime(this._depth, ctx.currentTime);
156
+ const lfoOscillator = ctx.createOscillator();
157
+ lfoOscillator.type = "sine";
158
+ lfoOscillator.frequency.value = this._rateHz;
159
+ lfoOscillator.connect(lfoGain);
160
+ lfoGain.connect(tremoloGain.gain);
161
+ inputGain.connect(dryGain);
162
+ dryGain.connect(outputGain);
163
+ let panner = null;
164
+ let panGain = null;
165
+ if (this._autoPan) {
166
+ panner = ctx.createStereoPanner();
167
+ panGain = ctx.createGain();
168
+ panGain.gain.setValueAtTime(this._depth, ctx.currentTime);
169
+ lfoOscillator.connect(panGain);
170
+ panGain.connect(panner.pan);
171
+ inputGain.connect(tremoloGain);
172
+ tremoloGain.connect(panner);
173
+ panner.connect(wetGain);
174
+ wetGain.connect(outputGain);
175
+ } else {
176
+ inputGain.connect(tremoloGain);
177
+ tremoloGain.connect(wetGain);
178
+ wetGain.connect(outputGain);
179
+ }
180
+ lfoOscillator.start();
181
+ this._setup = {
182
+ inputGain,
183
+ outputGain,
184
+ dryGain,
185
+ wetGain,
186
+ tremoloGain,
187
+ lfoOscillator,
188
+ lfoGain,
189
+ panner,
190
+ panGain
191
+ };
192
+ }
193
+ };
203
194
 
195
+ //#endregion
204
196
  export { TremoloEffect };
205
- //# sourceMappingURL=TremoloEffect.js.map
197
+ //# sourceMappingURL=TremoloEffect.js.map
@@ -1 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,YAAA,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC;AAC9B,YAAA,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;AAC3B,YAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;AACvB,YAAA,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;QAC7B;aAAO;;AAEL,YAAA,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC;AAC9B,YAAA,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC;AAC5B,YAAA,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;QAC7B;QAEA,aAAa,CAAC,KAAK,EAAE;QAErB,IAAI,CAAC,MAAM,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;IACjH;AACD;;;;"}
1
+ {"version":3,"file":"TremoloEffect.js","names":[],"sources":["../../../src/effects/TremoloEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link TremoloEffect}. */\nexport interface TremoloEffectOptions {\n /**\n * LFO oscillation rate in Hz controlling the speed of the tremolo pulse.\n * Range 0..20, default 5.\n */\n rateHz?: number;\n /**\n * Modulation depth, 0..1. Determines the amplitude of the LFO that modulates\n * `tremoloGain.gain`. The base gain is `1 - depth`; adding the LFO (peak = `depth`)\n * makes the gain oscillate between `1 - 2 * depth` and `1`. At depth=0 the effect\n * is transparent; at depth=0.5 the gain briefly reaches zero at the trough; at\n * depth>0.5 the gain goes negative (phase inversion at the trough). Default 0.7.\n */\n depth?: number;\n /**\n * When `true` the same LFO also drives a `StereoPannerNode.pan` (amplitude = `depth`),\n * sweeping the signal left and right in synchrony with the tremolo pulsing. This option\n * is read-only after construction. Default `false`.\n */\n autoPan?: boolean;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.\n */\n wet?: number;\n}\n\ninterface TremoloEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly tremoloGain: GainNode;\n readonly lfoOscillator: OscillatorNode;\n readonly lfoGain: GainNode;\n readonly panner: StereoPannerNode | null;\n readonly panGain: GainNode | null;\n}\n\n/**\n * Tremolo effect that amplitude-modulates the signal with a sine LFO using native WebAudio nodes.\n *\n * A sine-wave LFO drives a `GainNode`'s gain to produce the characteristic volume pulsing of\n * tremolo. The base gain is `1 - depth` and the LFO peak deviation is `depth`, so the gain\n * oscillates between `1 - 2 * depth` and `1`. Optionally the same LFO can drive a\n * `StereoPannerNode.pan` for a synchronized auto-pan effect.\n *\n * Node graph (`autoPan = false`):\n * ```\n * inputGain ┬── dryGain ──────────────────────────┐\n * │ ├── outputGain\n * └── tremoloGain ── wetGain ─────────────┘\n *\n * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain\n * ```\n *\n * Node graph (`autoPan = true`):\n * ```\n * inputGain ┬── dryGain ──────────────────────────────────┐\n * │ ├── outputGain\n * └── tremoloGain ── panner ── wetGain ──────────┘\n *\n * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain\n * lfoOscillator ── panGain (depth) ── panner.pan\n * ```\n *\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth`.\n *\n * @example\n * ```ts\n * // Classic tremolo at 5 Hz, 70 % depth, full wet\n * const tremolo = new TremoloEffect({ rateHz: 5, depth: 0.7, wet: 1 });\n * bus.addEffect(tremolo);\n *\n * // Slow auto-pan at 0.5 Hz\n * const autopan = new TremoloEffect({ rateHz: 0.5, depth: 0.5, autoPan: true });\n * bus.addEffect(autopan);\n * ```\n */\nexport class TremoloEffect extends AudioEffect {\n private _setup: TremoloEffectSetup | null = null;\n private _rateHz: number;\n private _depth: number;\n private readonly _autoPan: boolean;\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: TremoloEffectOptions = {}) {\n super();\n this._rateHz = Math.max(0, Math.min(20, options.rateHz ?? 5));\n this._depth = Math.max(0, Math.min(1, options.depth ?? 0.7));\n this._autoPan = options.autoPan ?? false;\n this._wet = Math.max(0, Math.min(1, options.wet ?? 1));\n if (isAudioContextReady()) {\n this._setupNodes(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\n }\n\n /**\n * The node where audio enters this effect. Throws if the audio context is not yet initialized.\n */\n public get inputNode(): AudioNode {\n if (!this._setup) throw new Error('TremoloEffect 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 not yet initialized.\n */\n public get outputNode(): AudioNode {\n if (!this._setup) throw new Error('TremoloEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n /**\n * LFO oscillation rate in Hz. Range 0..20, default 5.\n * Ramped via `setTargetAtTime` when changed at runtime.\n */\n public get rateHz(): number {\n return this._rateHz;\n }\n\n public set rateHz(value: number) {\n this._rateHz = Math.max(0, Math.min(20, value));\n if (this._setup) {\n this._setup.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._setup.inputGain.context.currentTime, 0.01);\n }\n }\n\n /**\n * Modulation depth, 0..1. At 0 the effect is transparent; at 0.5 the gain briefly\n * reaches zero at the trough; at depth>0.5 the gain goes negative (phase inversion).\n * Default 0.7. Ramped via `setTargetAtTime`.\n */\n public get depth(): number {\n return this._depth;\n }\n\n public set depth(value: number) {\n this._depth = Math.max(0, Math.min(1, value));\n if (this._setup) {\n const t = this._setup.inputGain.context.currentTime;\n this._setup.lfoGain.gain.setTargetAtTime(this._depth, t, 0.01);\n this._setup.tremoloGain.gain.setTargetAtTime(1 - this._depth, t, 0.01);\n if (this._setup.panGain) {\n this._setup.panGain.gain.setTargetAtTime(this._depth, t, 0.01);\n }\n }\n }\n\n /**\n * Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};\n * read-only at runtime. Default `false`.\n */\n public get autoPan(): boolean {\n return this._autoPan;\n }\n\n /**\n * Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.\n * Ramped via `setTargetAtTime` when changed at runtime.\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 public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n if (this._setup) {\n this._setup.lfoOscillator.stop();\n this._setup.lfoOscillator.disconnect();\n this._setup.lfoGain.disconnect();\n this._setup.tremoloGain.disconnect();\n if (this._setup.panner) this._setup.panner.disconnect();\n if (this._setup.panGain) this._setup.panGain.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.inputGain.disconnect();\n this._setup.outputGain.disconnect();\n this._setup = null;\n }\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 tremoloGain = ctx.createGain();\n const lfoGain = ctx.createGain();\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 // Base gain = 1 - depth; the LFO (amplitude = depth) is added on top via AudioParam\n // modulation, making the effective gain oscillate in [1 - 2*depth, 1].\n tremoloGain.gain.setValueAtTime(1 - this._depth, ctx.currentTime);\n lfoGain.gain.setValueAtTime(this._depth, ctx.currentTime);\n\n const lfoOscillator = ctx.createOscillator();\n lfoOscillator.type = 'sine';\n lfoOscillator.frequency.value = this._rateHz;\n\n // LFO → lfoGain → tremoloGain.gain (AudioParam modulation)\n lfoOscillator.connect(lfoGain);\n lfoGain.connect(tremoloGain.gain as unknown as AudioNode);\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n let panner: StereoPannerNode | null = null;\n let panGain: GainNode | null = null;\n\n if (this._autoPan) {\n panner = ctx.createStereoPanner();\n panGain = ctx.createGain();\n panGain.gain.setValueAtTime(this._depth, ctx.currentTime);\n\n // LFO → panGain → panner.pan (AudioParam modulation)\n lfoOscillator.connect(panGain);\n panGain.connect(panner.pan as unknown as AudioNode);\n\n // Wet path: inputGain → tremoloGain → panner → wetGain → outputGain\n inputGain.connect(tremoloGain);\n tremoloGain.connect(panner);\n panner.connect(wetGain);\n wetGain.connect(outputGain);\n } else {\n // Wet path: inputGain → tremoloGain → wetGain → outputGain\n inputGain.connect(tremoloGain);\n tremoloGain.connect(wetGain);\n wetGain.connect(outputGain);\n }\n\n lfoOscillator.start();\n\n this._setup = { inputGain, outputGain, dryGain, wetGain, tremoloGain, lfoOscillator, lfoGain, panner, panGain };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,IAAa,gBAAb,cAAmC,YAAY;CAC7C,AAAQ,SAAoC;CAC5C,AAAQ;CACR,AAAQ;CACR,AAAiB;CACjB,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,UAAU,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,QAAQ,UAAU,CAAC,CAAC;EAC5D,KAAK,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,SAAS,EAAG,CAAC;EAC3D,KAAK,WAAW,QAAQ,WAAW;EACnC,KAAK,OA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,MAAM,gBAAgB,IAAI,iBAAiB;EAC3C,cAAc,OAAO;EACrB,cAAc,UAAU,QAAQ,KAAK;EAGrC,cAAc,QAAQ,OAAO;EAC7B,QAAQ,QAAQ,YAAY,IAA4B;EAGxD,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAE1B,IAAI,SAAkC;EACtC,IAAI,UAA2B;EAE/B,IAAI,KAAK,UAAU;GACjB,SAAS,IAAI,mBAAmB;GAChC,UAAU,IAAI,WAAW;GACzB,QAAQ,KAAK,eAAe,KAAK,QAAQ,IAAI,WAAW;GAGxD,cAAc,QAAQ,OAAO;GAC7B,QAAQ,QAAQ,OAAO,GAA2B;GAGlD,UAAU,QAAQ,WAAW;GAC7B,YAAY,QAAQ,MAAM;GAC1B,OAAO,QAAQ,OAAO;GACtB,QAAQ,QAAQ,UAAU;EAC5B,OAAO;GAEL,UAAU,QAAQ,WAAW;GAC7B,YAAY,QAAQ,OAAO;GAC3B,QAAQ,QAAQ,UAAU;EAC5B;EAEA,cAAc,MAAM;EAEpB,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAa;GAAe;GAAS;GAAQ;EAAQ;CAChH;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { type AudioBus, WorkletEffect } from '@codexo/exojs';
2
2
  export interface VocoderEffectOptions {
3
- /** Modulator AudioBus — its output drives the spectral envelope.
3
+ /** Modulator AudioBus - its output drives the spectral envelope.
4
4
  * Typically routed from a microphone or voice sample. */
5
5
  modulator: AudioBus;
6
6
  /** Number of frequency bands. More bands = better resolution, more CPU. Default 16. */
@@ -42,3 +42,4 @@ export declare class VocoderEffect extends WorkletEffect {
42
42
  get envelopeSmoothing(): number;
43
43
  set envelopeSmoothing(value: number);
44
44
  }
45
+ //# sourceMappingURL=VocoderEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VocoderEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/VocoderEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI7D,MAAM,WAAW,oBAAoB;IACnC;8DAC0D;IAC1D,SAAS,EAAE,QAAQ,CAAC;IACpB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;sDACkD;IAClD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,aAAa;IAG9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,kBAAkB,CAAS;gBAEhB,OAAO,EAAE,oBAAoB;IAchD,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;IACD,SAAS,KAAK,cAAc,IAAI,MAAM,CAErC;IACD,cAAuB,eAAe,IAAI,uBAAuB,CAWhE;cAEkB,eAAe,CAAC,aAAa,EAAE,YAAY,GAAG,IAAI;IAqBrE,2IAA2I;IAC3I,IAAW,iBAAiB,IAAI,MAAM,CAErC;IACD,IAAW,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAGzC;CACF"}
@@ -1,84 +1,73 @@
1
- import { WorkletEffect } from '@codexo/exojs';
2
- import { vocoderWorkletSource } from '../worklets/vocoder.worklet.js';
1
+ import vocoder_worklet_default from "../worklets/vocoder.worklet.js";
2
+ import { WorkletEffect } from "@codexo/exojs";
3
3
 
4
+ //#region src/effects/VocoderEffect.ts
4
5
  /**
5
- * Phase-vocoder-style effect implemented as a {@link WorkletEffect}. Analyzes
6
- * the spectral envelope of a `modulator` {@link AudioBus} across a bank of
7
- * log-spaced bandpass filters and applies that envelope to the carrier signal
8
- * (the main input). The result is the classic "robot voice" or talking-synth
9
- * effect. Band count, frequency range, and Q are compile-time parameters set
10
- * at construction; only `wet` and `envelopeSmoothing` are adjustable at
11
- * runtime.
12
- */
13
- class VocoderEffect extends WorkletEffect {
14
- // Declared nullable because super() may trigger _onWorkletReady before the
15
- // subclass constructor body runs (if construction is aborted by a throw).
16
- _modulator = null;
17
- _numBands;
18
- _minHz;
19
- _maxHz;
20
- _bandQ;
21
- _envelopeSmoothing;
22
- constructor(options) {
23
- super();
24
- if (!options.modulator) {
25
- throw new Error('VocoderEffect requires a modulator AudioBus.');
26
- }
27
- this._modulator = options.modulator;
28
- this._numBands = options.numBands ?? 16;
29
- this._minHz = options.minHz ?? 80;
30
- this._maxHz = options.maxHz ?? 8000;
31
- this._bandQ = options.bandQ ?? 4;
32
- this._envelopeSmoothing = Math.max(0.0001, Math.min(0.1, options.envelopeSmoothing ?? 0.005));
33
- this.wet = options.wet ?? 1;
34
- }
35
- get _workletName() {
36
- return 'exojs-vocoder';
37
- }
38
- get _workletSource() {
39
- return vocoderWorkletSource;
40
- }
41
- get _workletOptions() {
42
- return {
43
- numberOfInputs: 2,
44
- numberOfOutputs: 1,
45
- processorOptions: {
46
- numBands: this._numBands,
47
- minHz: this._minHz,
48
- maxHz: this._maxHz,
49
- bandQ: this._bandQ,
50
- },
51
- };
52
- }
53
- _onWorkletReady(_audioContext) {
54
- // Guard against partially-constructed instances (constructor threw after super()).
55
- if (!this._modulator)
56
- return;
57
- this._setAudioParam('envelopeSmoothing', this._envelopeSmoothing);
58
- // Wire modulator bus output to input 1 of the worklet
59
- const modulator = this._modulator;
60
- const modOutput = modulator._getOutputNode();
61
- if (modOutput && this._workletNode) {
62
- modOutput.connect(this._workletNode, 0, 1);
63
- }
64
- else {
65
- modulator.onceSetup(() => {
66
- const node = modulator._getOutputNode();
67
- if (node && this._workletNode) {
68
- node.connect(this._workletNode, 0, 1);
69
- }
70
- });
71
- }
72
- }
73
- /** One-pole envelope follower coefficient. Smaller values produce slower, smoother envelope tracking. Range 0.0001..0.1, default 0.005. */
74
- get envelopeSmoothing() {
75
- return this._envelopeSmoothing;
76
- }
77
- set envelopeSmoothing(value) {
78
- this._envelopeSmoothing = Math.max(0.0001, Math.min(0.1, value));
79
- this._setAudioParam('envelopeSmoothing', this._envelopeSmoothing);
80
- }
81
- }
6
+ * Phase-vocoder-style effect implemented as a {@link WorkletEffect}. Analyzes
7
+ * the spectral envelope of a `modulator` {@link AudioBus} across a bank of
8
+ * log-spaced bandpass filters and applies that envelope to the carrier signal
9
+ * (the main input). The result is the classic "robot voice" or talking-synth
10
+ * effect. Band count, frequency range, and Q are compile-time parameters set
11
+ * at construction; only `wet` and `envelopeSmoothing` are adjustable at
12
+ * runtime.
13
+ */
14
+ var VocoderEffect = class extends WorkletEffect {
15
+ _modulator = null;
16
+ _numBands;
17
+ _minHz;
18
+ _maxHz;
19
+ _bandQ;
20
+ _envelopeSmoothing;
21
+ constructor(options) {
22
+ super();
23
+ if (!options.modulator) throw new Error("VocoderEffect requires a modulator AudioBus.");
24
+ this._modulator = options.modulator;
25
+ this._numBands = options.numBands ?? 16;
26
+ this._minHz = options.minHz ?? 80;
27
+ this._maxHz = options.maxHz ?? 8e3;
28
+ this._bandQ = options.bandQ ?? 4;
29
+ this._envelopeSmoothing = Math.max(1e-4, Math.min(.1, options.envelopeSmoothing ?? .005));
30
+ this.wet = options.wet ?? 1;
31
+ }
32
+ get _workletName() {
33
+ return "exojs-vocoder";
34
+ }
35
+ get _workletSource() {
36
+ return vocoder_worklet_default;
37
+ }
38
+ get _workletOptions() {
39
+ return {
40
+ numberOfInputs: 2,
41
+ numberOfOutputs: 1,
42
+ processorOptions: {
43
+ numBands: this._numBands,
44
+ minHz: this._minHz,
45
+ maxHz: this._maxHz,
46
+ bandQ: this._bandQ
47
+ }
48
+ };
49
+ }
50
+ _onWorkletReady(_audioContext) {
51
+ if (!this._modulator) return;
52
+ this._setAudioParam("envelopeSmoothing", this._envelopeSmoothing);
53
+ const modulator = this._modulator;
54
+ const modOutput = modulator._getOutputNode();
55
+ if (modOutput && this._workletNode) modOutput.connect(this._workletNode, 0, 1);
56
+ else modulator.onceSetup(() => {
57
+ const node = modulator._getOutputNode();
58
+ if (node && this._workletNode) node.connect(this._workletNode, 0, 1);
59
+ });
60
+ }
61
+ /** One-pole envelope follower coefficient. Smaller values produce slower, smoother envelope tracking. Range 0.0001..0.1, default 0.005. */
62
+ get envelopeSmoothing() {
63
+ return this._envelopeSmoothing;
64
+ }
65
+ set envelopeSmoothing(value) {
66
+ this._envelopeSmoothing = Math.max(1e-4, Math.min(.1, value));
67
+ this._setAudioParam("envelopeSmoothing", this._envelopeSmoothing);
68
+ }
69
+ };
82
70
 
71
+ //#endregion
83
72
  export { VocoderEffect };
84
- //# sourceMappingURL=VocoderEffect.js.map
73
+ //# sourceMappingURL=VocoderEffect.js.map