@codexo/exojs-audio-fx 0.15.3 → 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.
- package/dist/esm/AudioAnalyser.d.ts +4 -3
- package/dist/esm/AudioAnalyser.d.ts.map +1 -0
- package/dist/esm/AudioAnalyser.js +365 -468
- package/dist/esm/AudioAnalyser.js.map +1 -1
- package/dist/esm/BeatDetector.d.ts +16 -15
- package/dist/esm/BeatDetector.d.ts.map +1 -0
- package/dist/esm/BeatDetector.js +370 -428
- package/dist/esm/BeatDetector.js.map +1 -1
- package/dist/esm/dsp/fft.d.ts +5 -5
- package/dist/esm/dsp/fft.d.ts.map +1 -0
- package/dist/esm/dsp/mel.d.ts +6 -6
- package/dist/esm/dsp/mel.d.ts.map +1 -0
- package/dist/esm/dsp/mel.js +55 -64
- package/dist/esm/dsp/mel.js.map +1 -1
- package/dist/esm/dsp/tempogram.d.ts +60 -20
- package/dist/esm/dsp/tempogram.d.ts.map +1 -0
- package/dist/esm/effects/AutoWahEffect.d.ts +3 -2
- package/dist/esm/effects/AutoWahEffect.d.ts.map +1 -0
- package/dist/esm/effects/AutoWahEffect.js +210 -237
- package/dist/esm/effects/AutoWahEffect.js.map +1 -1
- package/dist/esm/effects/BitCrusherEffect.d.ts +3 -2
- package/dist/esm/effects/BitCrusherEffect.d.ts.map +1 -0
- package/dist/esm/effects/BitCrusherEffect.js +72 -70
- package/dist/esm/effects/BitCrusherEffect.js.map +1 -1
- package/dist/esm/effects/ChorusEffect.d.ts +2 -1
- package/dist/esm/effects/ChorusEffect.d.ts.map +1 -0
- package/dist/esm/effects/ChorusEffect.js +132 -150
- package/dist/esm/effects/ChorusEffect.js.map +1 -1
- package/dist/esm/effects/CompressorEffect.d.ts +2 -1
- package/dist/esm/effects/CompressorEffect.d.ts.map +1 -0
- package/dist/esm/effects/CompressorEffect.js +104 -118
- package/dist/esm/effects/CompressorEffect.js.map +1 -1
- package/dist/esm/effects/ConvolutionEffect.d.ts +10 -5
- package/dist/esm/effects/ConvolutionEffect.d.ts.map +1 -0
- package/dist/esm/effects/ConvolutionEffect.js +208 -189
- package/dist/esm/effects/ConvolutionEffect.js.map +1 -1
- package/dist/esm/effects/DelayEffect.d.ts +1 -0
- package/dist/esm/effects/DelayEffect.d.ts.map +1 -0
- package/dist/esm/effects/DelayEffect.js +105 -109
- package/dist/esm/effects/DelayEffect.js.map +1 -1
- package/dist/esm/effects/DistortionEffect.d.ts +4 -3
- package/dist/esm/effects/DistortionEffect.d.ts.map +1 -0
- package/dist/esm/effects/DistortionEffect.js +190 -195
- package/dist/esm/effects/DistortionEffect.js.map +1 -1
- package/dist/esm/effects/DuckingEffect.d.ts +3 -2
- package/dist/esm/effects/DuckingEffect.d.ts.map +1 -0
- package/dist/esm/effects/DuckingEffect.js +91 -172
- package/dist/esm/effects/DuckingEffect.js.map +1 -1
- package/dist/esm/effects/EqualizerEffect.d.ts +1 -0
- package/dist/esm/effects/EqualizerEffect.d.ts.map +1 -0
- package/dist/esm/effects/EqualizerEffect.js +120 -133
- package/dist/esm/effects/EqualizerEffect.js.map +1 -1
- package/dist/esm/effects/FlangerEffect.d.ts +7 -6
- package/dist/esm/effects/FlangerEffect.d.ts.map +1 -0
- package/dist/esm/effects/FlangerEffect.js +172 -201
- package/dist/esm/effects/FlangerEffect.js.map +1 -1
- package/dist/esm/effects/GranularEffect.d.ts +3 -2
- package/dist/esm/effects/GranularEffect.d.ts.map +1 -0
- package/dist/esm/effects/GranularEffect.js +100 -95
- package/dist/esm/effects/GranularEffect.js.map +1 -1
- package/dist/esm/effects/LimiterEffect.d.ts +1 -0
- package/dist/esm/effects/LimiterEffect.d.ts.map +1 -0
- package/dist/esm/effects/LimiterEffect.js +182 -194
- package/dist/esm/effects/LimiterEffect.js.map +1 -1
- package/dist/esm/effects/PhaserEffect.d.ts +2 -1
- package/dist/esm/effects/PhaserEffect.d.ts.map +1 -0
- package/dist/esm/effects/PhaserEffect.js +214 -254
- package/dist/esm/effects/PhaserEffect.js.map +1 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts +2 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts.map +1 -0
- package/dist/esm/effects/PingPongDelayEffect.js +172 -185
- package/dist/esm/effects/PingPongDelayEffect.js.map +1 -1
- package/dist/esm/effects/PitchShiftEffect.d.ts +3 -2
- package/dist/esm/effects/PitchShiftEffect.d.ts.map +1 -0
- package/dist/esm/effects/PitchShiftEffect.js +60 -60
- package/dist/esm/effects/PitchShiftEffect.js.map +1 -1
- package/dist/esm/effects/ReverbEffect.d.ts +2 -1
- package/dist/esm/effects/ReverbEffect.d.ts.map +1 -0
- package/dist/esm/effects/ReverbEffect.js +113 -117
- package/dist/esm/effects/ReverbEffect.js.map +1 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +4 -3
- package/dist/esm/effects/RingModulatorEffect.d.ts.map +1 -0
- package/dist/esm/effects/RingModulatorEffect.js +153 -161
- package/dist/esm/effects/RingModulatorEffect.js.map +1 -1
- package/dist/esm/effects/TremoloEffect.d.ts +1 -0
- package/dist/esm/effects/TremoloEffect.d.ts.map +1 -0
- package/dist/esm/effects/TremoloEffect.js +193 -201
- package/dist/esm/effects/TremoloEffect.js.map +1 -1
- package/dist/esm/effects/VocoderEffect.d.ts +2 -1
- package/dist/esm/effects/VocoderEffect.d.ts.map +1 -0
- package/dist/esm/effects/VocoderEffect.js +69 -80
- package/dist/esm/effects/VocoderEffect.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +23 -22
- package/dist/esm/worklets/beat-detector.worklet.js +5 -1162
- package/dist/esm/worklets/beat-detector.worklet.js.map +1 -1
- package/dist/esm/worklets/bit-crusher.worklet.js +5 -44
- package/dist/esm/worklets/bit-crusher.worklet.js.map +1 -1
- package/dist/esm/worklets/ducking.worklet.js +6 -0
- package/dist/esm/worklets/ducking.worklet.js.map +1 -0
- package/dist/esm/worklets/granular.worklet.js +5 -97
- package/dist/esm/worklets/granular.worklet.js.map +1 -1
- package/dist/esm/worklets/pitch-shift.worklet.js +5 -128
- package/dist/esm/worklets/pitch-shift.worklet.js.map +1 -1
- package/dist/esm/worklets/vocoder.worklet.js +5 -93
- package/dist/esm/worklets/vocoder.worklet.js.map +1 -1
- package/package.json +7 -7
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/worklets/beat-detector.worklet.d.ts +0 -1
- package/dist/esm/worklets/bit-crusher.worklet.d.ts +0 -1
- package/dist/esm/worklets/granular.worklet.d.ts +0 -1
- package/dist/esm/worklets/pitch-shift.worklet.d.ts +0 -1
- package/dist/esm/worklets/vocoder.worklet.d.ts +0 -1
|
@@ -1,205 +1,197 @@
|
|
|
1
|
-
import { AudioEffect,
|
|
1
|
+
import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
|
|
2
2
|
|
|
3
|
+
//#region src/effects/TremoloEffect.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TremoloEffect.js","sources":["../../../../src/effects/TremoloEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAyCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;AACG,MAAO,aAAc,SAAQ,WAAW,CAAA;IACpC,MAAM,GAA8B,IAAI;AACxC,IAAA,OAAO;AACP,IAAA,MAAM;AACG,IAAA,QAAQ;AACjB,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,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CA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C1B,QAAA,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;QAE3B,IAAI,MAAM,GAA4B,IAAI;QAC1C,IAAI,OAAO,GAAoB,IAAI;AAEnC,QAAA,IAAI,IAAI,CAAC,QAAQ,EAAE;AACjB,YAAA,MAAM,GAAG,GAAG,CAAC,kBAAkB,EAAE;AACjC,YAAA,OAAO,GAAG,GAAG,CAAC,UAAU,EAAE;AAC1B,YAAA,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC;;AAGzD,YAAA,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC;AAC9B,YAAA,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,GAA2B,CAAC;;AAGnD,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":";;;;;;;;;;;;;;;;;;;;;;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,6 +1,6 @@
|
|
|
1
1
|
import { type AudioBus, WorkletEffect } from '@codexo/exojs';
|
|
2
2
|
export interface VocoderEffectOptions {
|
|
3
|
-
/** Modulator AudioBus
|
|
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
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|