@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,189 +1,176 @@
|
|
|
1
|
-
import { AudioEffect,
|
|
1
|
+
import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
|
|
2
2
|
|
|
3
|
+
//#region src/effects/PingPongDelayEffect.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
|
-
wetGain.connect(outputGain);
|
|
173
|
-
this._setup = {
|
|
174
|
-
inputGain,
|
|
175
|
-
outputGain,
|
|
176
|
-
dryGain,
|
|
177
|
-
wetGain,
|
|
178
|
-
feedbackGainA,
|
|
179
|
-
feedbackGainB,
|
|
180
|
-
delayL,
|
|
181
|
-
delayR,
|
|
182
|
-
pannerL,
|
|
183
|
-
pannerR,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
}
|
|
5
|
+
* Stereo ping-pong delay effect using two cross-fed {@link DelayNode}s that
|
|
6
|
+
* bounce the signal alternately between left and right channels. The input
|
|
7
|
+
* feeds only the left delay; cross-feedback (L→R and R→L) then causes the
|
|
8
|
+
* signal to alternate channels on every tap, producing the characteristic L↔R
|
|
9
|
+
* slapback cascade. Each tap is routed through a {@link StereoPannerNode}
|
|
10
|
+
* panned hard left or right, maintaining hard-left / hard-right stereo
|
|
11
|
+
* separation throughout the feedback tail.
|
|
12
|
+
*
|
|
13
|
+
* Node graph:
|
|
14
|
+
* ```
|
|
15
|
+
* input(GainNode) → dryGain ────────────────────────────────── output(GainNode)
|
|
16
|
+
* input → delayL → feedbackGainA → delayR ↑
|
|
17
|
+
* delayR → feedbackGainB → delayL │
|
|
18
|
+
* delayL → pannerL (pan = -1, hard left) → wetGain ─────────┘
|
|
19
|
+
* delayR → pannerR (pan = +1, hard right) → wetGain
|
|
20
|
+
* ```
|
|
21
|
+
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const pingPong = new PingPongDelayEffect({ delayTime: 0.3, feedback: 0.5, wet: 0.5 });
|
|
26
|
+
* bus.addEffect(pingPong);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
var PingPongDelayEffect = class extends AudioEffect {
|
|
30
|
+
_setup = null;
|
|
31
|
+
_delayTime;
|
|
32
|
+
_feedback;
|
|
33
|
+
_wet;
|
|
34
|
+
_onAudioContextReady = (ctx) => {
|
|
35
|
+
onAudioContextReady.remove(this._onAudioContextReady);
|
|
36
|
+
this._setupNodes(ctx);
|
|
37
|
+
};
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
super();
|
|
40
|
+
this._delayTime = Math.max(.01, Math.min(2, options.delayTime ?? .25));
|
|
41
|
+
this._feedback = Math.max(0, Math.min(.9, options.feedback ?? .4));
|
|
42
|
+
this._wet = Math.max(0, Math.min(1, options.wet ?? .4));
|
|
43
|
+
if (isAudioContextReady()) this._setupNodes(getAudioContext());
|
|
44
|
+
else onAudioContextReady.add(this._onAudioContextReady);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The node where audio enters this effect. Throws if the audio context is
|
|
48
|
+
* not yet initialized.
|
|
49
|
+
*/
|
|
50
|
+
get inputNode() {
|
|
51
|
+
if (!this._setup) throw new Error("PingPongDelayEffect not yet initialized.");
|
|
52
|
+
return this._setup.inputGain;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The node where audio exits this effect. Throws if the audio context is
|
|
56
|
+
* not yet initialized.
|
|
57
|
+
*/
|
|
58
|
+
get outputNode() {
|
|
59
|
+
if (!this._setup) throw new Error("PingPongDelayEffect not yet initialized.");
|
|
60
|
+
return this._setup.outputGain;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Delay time per tap in seconds. Both the left and right delay nodes share
|
|
64
|
+
* the same delay time. Range 0.01..2, default 0.25.
|
|
65
|
+
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
66
|
+
*/
|
|
67
|
+
get delayTime() {
|
|
68
|
+
return this._delayTime;
|
|
69
|
+
}
|
|
70
|
+
set delayTime(value) {
|
|
71
|
+
this._delayTime = Math.max(.01, Math.min(2, value));
|
|
72
|
+
if (this._setup) {
|
|
73
|
+
const time = this._setup.delayL.context.currentTime;
|
|
74
|
+
this._setup.delayL.delayTime.setTargetAtTime(this._delayTime, time, .01);
|
|
75
|
+
this._setup.delayR.delayTime.setTargetAtTime(this._delayTime, time, .01);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Cross-channel feedback fraction. Each delayed tap feeds this fraction of
|
|
80
|
+
* its signal into the opposite channel's delay, sustaining the L↔R bounce.
|
|
81
|
+
* Range 0..0.9, default 0.4. Changes are ramped smoothly via
|
|
82
|
+
* `setTargetAtTime`.
|
|
83
|
+
*/
|
|
84
|
+
get feedback() {
|
|
85
|
+
return this._feedback;
|
|
86
|
+
}
|
|
87
|
+
set feedback(value) {
|
|
88
|
+
this._feedback = Math.max(0, Math.min(.9, value));
|
|
89
|
+
if (this._setup) {
|
|
90
|
+
const time = this._setup.feedbackGainA.context.currentTime;
|
|
91
|
+
this._setup.feedbackGainA.gain.setTargetAtTime(this._feedback, time, .01);
|
|
92
|
+
this._setup.feedbackGainB.gain.setTargetAtTime(this._feedback, time, .01);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wet (ping-pong) mix level, 0..1. The dry level is automatically `1 - wet`.
|
|
97
|
+
* Changes are ramped smoothly via `setTargetAtTime`. Default 0.4.
|
|
98
|
+
*/
|
|
99
|
+
get wet() {
|
|
100
|
+
return this._wet;
|
|
101
|
+
}
|
|
102
|
+
set wet(value) {
|
|
103
|
+
this._wet = Math.max(0, Math.min(1, value));
|
|
104
|
+
if (this._setup) {
|
|
105
|
+
const ctx = this._setup.wetGain.context;
|
|
106
|
+
this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
|
|
107
|
+
this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
destroy() {
|
|
111
|
+
onAudioContextReady.remove(this._onAudioContextReady);
|
|
112
|
+
if (this._setup) {
|
|
113
|
+
this._setup.inputGain.disconnect();
|
|
114
|
+
this._setup.outputGain.disconnect();
|
|
115
|
+
this._setup.dryGain.disconnect();
|
|
116
|
+
this._setup.wetGain.disconnect();
|
|
117
|
+
this._setup.feedbackGainA.disconnect();
|
|
118
|
+
this._setup.feedbackGainB.disconnect();
|
|
119
|
+
this._setup.delayL.disconnect();
|
|
120
|
+
this._setup.delayR.disconnect();
|
|
121
|
+
this._setup.pannerL.disconnect();
|
|
122
|
+
this._setup.pannerR.disconnect();
|
|
123
|
+
this._setup = null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
_setupNodes(ctx) {
|
|
127
|
+
const inputGain = ctx.createGain();
|
|
128
|
+
const outputGain = ctx.createGain();
|
|
129
|
+
const dryGain = ctx.createGain();
|
|
130
|
+
const wetGain = ctx.createGain();
|
|
131
|
+
const feedbackGainA = ctx.createGain();
|
|
132
|
+
const feedbackGainB = ctx.createGain();
|
|
133
|
+
const delayL = ctx.createDelay(2);
|
|
134
|
+
const delayR = ctx.createDelay(2);
|
|
135
|
+
const pannerL = ctx.createStereoPanner();
|
|
136
|
+
const pannerR = ctx.createStereoPanner();
|
|
137
|
+
inputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
138
|
+
outputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
139
|
+
dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
|
|
140
|
+
wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
|
|
141
|
+
feedbackGainA.gain.setValueAtTime(this._feedback, ctx.currentTime);
|
|
142
|
+
feedbackGainB.gain.setValueAtTime(this._feedback, ctx.currentTime);
|
|
143
|
+
delayL.delayTime.setValueAtTime(this._delayTime, ctx.currentTime);
|
|
144
|
+
delayR.delayTime.setValueAtTime(this._delayTime, ctx.currentTime);
|
|
145
|
+
pannerL.pan.value = -1;
|
|
146
|
+
pannerR.pan.value = 1;
|
|
147
|
+
inputGain.connect(dryGain);
|
|
148
|
+
dryGain.connect(outputGain);
|
|
149
|
+
inputGain.connect(delayL);
|
|
150
|
+
delayL.connect(feedbackGainA);
|
|
151
|
+
feedbackGainA.connect(delayR);
|
|
152
|
+
delayR.connect(feedbackGainB);
|
|
153
|
+
feedbackGainB.connect(delayL);
|
|
154
|
+
delayL.connect(pannerL);
|
|
155
|
+
delayR.connect(pannerR);
|
|
156
|
+
pannerL.connect(wetGain);
|
|
157
|
+
pannerR.connect(wetGain);
|
|
158
|
+
wetGain.connect(outputGain);
|
|
159
|
+
this._setup = {
|
|
160
|
+
inputGain,
|
|
161
|
+
outputGain,
|
|
162
|
+
dryGain,
|
|
163
|
+
wetGain,
|
|
164
|
+
feedbackGainA,
|
|
165
|
+
feedbackGainB,
|
|
166
|
+
delayL,
|
|
167
|
+
delayR,
|
|
168
|
+
pannerL,
|
|
169
|
+
pannerR
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
187
173
|
|
|
174
|
+
//#endregion
|
|
188
175
|
export { PingPongDelayEffect };
|
|
189
|
-
//# sourceMappingURL=PingPongDelayEffect.js.map
|
|
176
|
+
//# sourceMappingURL=PingPongDelayEffect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PingPongDelayEffect.js","sources":["../../../../src/effects/PingPongDelayEffect.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG,MAAO,mBAAoB,SAAQ,WAAW,CAAA;IAC1C,MAAM,GAAoC,IAAI;AAC9C,IAAA,UAAU;AACV,IAAA,SAAS;AACT,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,C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CAAC,UAAU,EAAE,GAAG,CAAC,WAAW,CAAC;AACjE,QAAA,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,WAAW,CAAC;;AAGjE,QAAA,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE;AACtB,QAAA,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;;AAGrB,QAAA,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;AAC1B,QAAA,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;;;;;AAM3B,QAAA,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC;;AAGzB,QAAA,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC;AAC7B,QAAA,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;AAC7B,QAAA,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC;AAC7B,QAAA,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;;AAG7B,QAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;AACvB,QAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;;AAGvB,QAAA,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;AACxB,QAAA,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;AACxB,QAAA,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;QAE3B,IAAI,CAAC,MAAM,GAAG;YACZ,SAAS;YACT,UAAU;YACV,OAAO;YACP,OAAO;YACP,aAAa;YACb,aAAa;YACb,MAAM;YACN,MAAM;YACN,OAAO;YACP,OAAO;SACR;IACH;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"PingPongDelayEffect.js","names":[],"sources":["../../../src/effects/PingPongDelayEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link PingPongDelayEffect}. */\nexport interface PingPongDelayEffectOptions {\n /**\n * Delay time per tap in seconds. Range 0.01..2, default 0.25.\n */\n delayTime?: number;\n /**\n * Cross-channel feedback fraction - the portion of each delayed tap routed\n * into the opposite channel's delay input. Range 0..0.9, default 0.4.\n */\n feedback?: number;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 0.4.\n */\n wet?: number;\n}\n\ninterface PingPongDelayEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly feedbackGainA: GainNode;\n readonly feedbackGainB: GainNode;\n readonly delayL: DelayNode;\n readonly delayR: DelayNode;\n readonly pannerL: StereoPannerNode;\n readonly pannerR: StereoPannerNode;\n}\n\n/**\n * Stereo ping-pong delay effect using two cross-fed {@link DelayNode}s that\n * bounce the signal alternately between left and right channels. The input\n * feeds only the left delay; cross-feedback (L→R and R→L) then causes the\n * signal to alternate channels on every tap, producing the characteristic L↔R\n * slapback cascade. Each tap is routed through a {@link StereoPannerNode}\n * panned hard left or right, maintaining hard-left / hard-right stereo\n * separation throughout the feedback tail.\n *\n * Node graph:\n * ```\n * input(GainNode) → dryGain ────────────────────────────────── output(GainNode)\n * input → delayL → feedbackGainA → delayR ↑\n * delayR → feedbackGainB → delayL │\n * delayL → pannerL (pan = -1, hard left) → wetGain ─────────┘\n * delayR → pannerR (pan = +1, hard right) → wetGain\n * ```\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.\n *\n * @example\n * ```ts\n * const pingPong = new PingPongDelayEffect({ delayTime: 0.3, feedback: 0.5, wet: 0.5 });\n * bus.addEffect(pingPong);\n * ```\n */\nexport class PingPongDelayEffect extends AudioEffect {\n private _setup: PingPongDelayEffectSetup | null = null;\n private _delayTime: number;\n private _feedback: 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: PingPongDelayEffectOptions = {}) {\n super();\n this._delayTime = Math.max(0.01, Math.min(2, options.delayTime ?? 0.25));\n this._feedback = Math.max(0, Math.min(0.9, options.feedback ?? 0.4));\n this._wet = Math.max(0, Math.min(1, options.wet ?? 0.4));\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('PingPongDelayEffect 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('PingPongDelayEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n /**\n * Delay time per tap in seconds. Both the left and right delay nodes share\n * the same delay time. Range 0.01..2, default 0.25.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get delayTime(): number {\n return this._delayTime;\n }\n\n public set delayTime(value: number) {\n this._delayTime = Math.max(0.01, Math.min(2, value));\n if (this._setup) {\n const time = this._setup.delayL.context.currentTime;\n this._setup.delayL.delayTime.setTargetAtTime(this._delayTime, time, 0.01);\n this._setup.delayR.delayTime.setTargetAtTime(this._delayTime, time, 0.01);\n }\n }\n\n /**\n * Cross-channel feedback fraction. Each delayed tap feeds this fraction of\n * its signal into the opposite channel's delay, sustaining the L↔R bounce.\n * Range 0..0.9, default 0.4. Changes are ramped smoothly via\n * `setTargetAtTime`.\n */\n public get feedback(): number {\n return this._feedback;\n }\n\n public set feedback(value: number) {\n this._feedback = Math.max(0, Math.min(0.9, value));\n if (this._setup) {\n const time = this._setup.feedbackGainA.context.currentTime;\n this._setup.feedbackGainA.gain.setTargetAtTime(this._feedback, time, 0.01);\n this._setup.feedbackGainB.gain.setTargetAtTime(this._feedback, time, 0.01);\n }\n }\n\n /**\n * Wet (ping-pong) mix level, 0..1. The dry level is automatically `1 - wet`.\n * Changes are ramped smoothly via `setTargetAtTime`. Default 0.4.\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.inputGain.disconnect();\n this._setup.outputGain.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.feedbackGainA.disconnect();\n this._setup.feedbackGainB.disconnect();\n this._setup.delayL.disconnect();\n this._setup.delayR.disconnect();\n this._setup.pannerL.disconnect();\n this._setup.pannerR.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 feedbackGainA = ctx.createGain();\n const feedbackGainB = ctx.createGain();\n const delayL = ctx.createDelay(2);\n const delayR = ctx.createDelay(2);\n const pannerL = ctx.createStereoPanner();\n const pannerR = ctx.createStereoPanner();\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 feedbackGainA.gain.setValueAtTime(this._feedback, ctx.currentTime);\n feedbackGainB.gain.setValueAtTime(this._feedback, ctx.currentTime);\n delayL.delayTime.setValueAtTime(this._delayTime, ctx.currentTime);\n delayR.delayTime.setValueAtTime(this._delayTime, ctx.currentTime);\n\n // Hard-pan each tap to its respective stereo channel.\n pannerL.pan.value = -1;\n pannerR.pan.value = 1;\n\n // Dry path: input → dryGain → output\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet path: input feeds only the left delay.\n // Feeding both delays symmetrically would produce identical L/R evolution\n // (no ping-pong). The cross-feedback edges below route each tap into the\n // opposite channel's delay, creating the alternating L↔R slapback.\n inputGain.connect(delayL);\n\n // Cross-feedback: L → R and R → L\n delayL.connect(feedbackGainA);\n feedbackGainA.connect(delayR);\n delayR.connect(feedbackGainB);\n feedbackGainB.connect(delayL);\n\n // Pan taps: delayL → pannerL (hard left), delayR → pannerR (hard right)\n delayL.connect(pannerL);\n delayR.connect(pannerR);\n\n // Wet output: panned taps sum into wetGain → output\n pannerL.connect(wetGain);\n pannerR.connect(wetGain);\n wetGain.connect(outputGain);\n\n this._setup = {\n inputGain,\n outputGain,\n dryGain,\n wetGain,\n feedbackGainA,\n feedbackGainB,\n delayL,\n delayR,\n pannerL,\n pannerR,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,IAAa,sBAAb,cAAyC,YAAY;CACnD,AAAQ,SAA0C;CAClD,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAiB,wBAAwB,QAA4B;EACnE,oBAAoB,OAAO,KAAK,oBAAoB;EACpD,KAAK,YAAY,GAAG;CACtB;CAEA,AAAO,YAAY,UAAsC,CAAC,GAAG;EAC3D,MAAM;EACN,KAAK,aAAa,KAAK,IAAI,KAAM,KAAK,IAAI,GAAG,QAAQ,aAAa,GAAI,CAAC;EACvE,KAAK,YAAY,KAAK,IAAI,GAAG,KAAK,IAAI,IAAK,QAAQ,YAAY,EAAG,CAAC;EACnE,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,OAAO,EAAG,CAAC;EACvD,IAAI,oBAAoB,GACtB,KAAK,YAAY,gBAAgB,CAAC;OAElC,oBAAoB,IAAI,KAAK,oBAAoB;CAErD;;;;;CAMA,IAAW,YAAuB;EAChC,IAAI,CAAC,KAAK,QAAQ,MAAM,IAAI,MAAM,0CAA0C;EAC5E,OAAO,KAAK,OAAO;CACrB;;;;;CAMA,IAAW,aAAwB;EACjC,IAAI,C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AAM;EAC5B,OAAO,QAAQ,aAAa;EAC5B,cAAc,QAAQ,MAAM;EAG5B,OAAO,QAAQ,OAAO;EACtB,OAAO,QAAQ,OAAO;EAGtB,QAAQ,QAAQ,OAAO;EACvB,QAAQ,QAAQ,OAAO;EACvB,QAAQ,QAAQ,UAAU;EAE1B,KAAK,SAAS;GACZ;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF;CACF;AACF"}
|
|
@@ -12,10 +12,10 @@ export interface PitchShiftEffectOptions {
|
|
|
12
12
|
grainSize?: number;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Real-time pitch shifter (WorkletEffect) using SOLA
|
|
15
|
+
* Real-time pitch shifter (WorkletEffect) using SOLA - synchronized
|
|
16
16
|
* overlap-add. Each synthesis grain is realigned by waveform cross-correlation,
|
|
17
17
|
* so grain restarts stay phase coherent and the output pitch tracks the `pitch`
|
|
18
|
-
* ratio exactly across the whole 0.25x
|
|
18
|
+
* ratio exactly across the whole 0.25x-4.0x range (a naive granular delay drifts
|
|
19
19
|
* the pitch instead).
|
|
20
20
|
*
|
|
21
21
|
* Quality: clean, in-tune shifting for tonal material. As with any time-domain
|
|
@@ -43,3 +43,4 @@ export declare class PitchShiftEffect extends WorkletEffect {
|
|
|
43
43
|
get pitch(): number;
|
|
44
44
|
set pitch(value: number);
|
|
45
45
|
}
|
|
46
|
+
//# sourceMappingURL=PitchShiftEffect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PitchShiftEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/PitchShiftEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,MAAM,WAAW,uBAAuB;IACtC,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAEjB,OAAO,GAAE,uBAA4B;IAOxD,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;IAED,SAAS,KAAK,cAAc,IAAI,MAAM,CAErC;IAED,cAAuB,kBAAkB,IAAI,MAAM,CAIlD;IAED,cAAuB,eAAe,IAAI,uBAAuB,CAMhE;cAEkB,eAAe,IAAI,IAAI;IAI1C,uIAAuI;IACvI,IAAW,KAAK,IAAI,MAAM,CAEzB;IACD,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAG7B;CACF"}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import pitch_shift_worklet_default from "../worklets/pitch-shift.worklet.js";
|
|
2
|
+
import { WorkletEffect } from "@codexo/exojs";
|
|
3
3
|
|
|
4
|
+
//#region src/effects/PitchShiftEffect.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
|
-
}
|
|
6
|
+
* Real-time pitch shifter (WorkletEffect) using SOLA - synchronized
|
|
7
|
+
* overlap-add. Each synthesis grain is realigned by waveform cross-correlation,
|
|
8
|
+
* so grain restarts stay phase coherent and the output pitch tracks the `pitch`
|
|
9
|
+
* ratio exactly across the whole 0.25x-4.0x range (a naive granular delay drifts
|
|
10
|
+
* the pitch instead).
|
|
11
|
+
*
|
|
12
|
+
* Quality: clean, in-tune shifting for tonal material. As with any time-domain
|
|
13
|
+
* method, sharp transients can smear or double slightly; for those a phase
|
|
14
|
+
* vocoder would do better at the cost of much more CPU and latency.
|
|
15
|
+
*
|
|
16
|
+
* Latency: ~one frame + search ≈ 30ms at the default 1024-sample grain
|
|
17
|
+
* (at 48kHz). Not suitable for live monitoring; fine for games / playback.
|
|
18
|
+
*
|
|
19
|
+
* Use cases:
|
|
20
|
+
* - Sound variation: random ±200 cent pitch on each footstep / bullet
|
|
21
|
+
* - Voice effects: chipmunk (1.5x) or demon (0.7x) for game NPCs
|
|
22
|
+
* - Detune layering: stack 0.99x and 1.01x for thick chorused sound
|
|
23
|
+
*/
|
|
24
|
+
var PitchShiftEffect = class extends WorkletEffect {
|
|
25
|
+
_pitch;
|
|
26
|
+
_grainSize;
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
super();
|
|
29
|
+
this._pitch = Math.max(.25, Math.min(4, options.pitch ?? 1));
|
|
30
|
+
this._grainSize = options.grainSize ?? 1024;
|
|
31
|
+
this.wet = options.wet ?? 1;
|
|
32
|
+
}
|
|
33
|
+
get _workletName() {
|
|
34
|
+
return "exojs-pitch-shift";
|
|
35
|
+
}
|
|
36
|
+
get _workletSource() {
|
|
37
|
+
return pitch_shift_worklet_default;
|
|
38
|
+
}
|
|
39
|
+
get _dryLatencySeconds() {
|
|
40
|
+
return (this._grainSize + (this._grainSize >> 2)) / this._sampleRate;
|
|
41
|
+
}
|
|
42
|
+
get _workletOptions() {
|
|
43
|
+
return {
|
|
44
|
+
numberOfInputs: 1,
|
|
45
|
+
numberOfOutputs: 1,
|
|
46
|
+
processorOptions: { grainSize: this._grainSize }
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
_onWorkletReady() {
|
|
50
|
+
this._setAudioParam("pitch", this._pitch);
|
|
51
|
+
}
|
|
52
|
+
/** Pitch ratio relative to the original. 1.0 = no change, 0.5 = one octave down, 2.0 = one octave up. Range 0.25..4.0, default 1.0. */
|
|
53
|
+
get pitch() {
|
|
54
|
+
return this._pitch;
|
|
55
|
+
}
|
|
56
|
+
set pitch(value) {
|
|
57
|
+
this._pitch = Math.max(.25, Math.min(4, value));
|
|
58
|
+
this._setAudioParam("pitch", this._pitch);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
62
61
|
|
|
62
|
+
//#endregion
|
|
63
63
|
export { PitchShiftEffect };
|
|
64
|
-
//# sourceMappingURL=PitchShiftEffect.js.map
|
|
64
|
+
//# sourceMappingURL=PitchShiftEffect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PitchShiftEffect.js","sources":["
|
|
1
|
+
{"version":3,"file":"PitchShiftEffect.js","names":["pitchShiftWorkletSource"],"sources":["../../../src/effects/PitchShiftEffect.ts"],"sourcesContent":["import { WorkletEffect } from '@codexo/exojs';\n\nimport pitchShiftWorkletSource from '../worklets/pitch-shift.worklet.ts?worklet';\n\nexport interface PitchShiftEffectOptions {\n /** Pitch ratio. 1.0 = no change, 0.5 = octave down, 2.0 = octave up. Default 1.0. */\n pitch?: number;\n /** Dry/wet mix, 0..1. Default 1.0 (full wet). */\n wet?: number;\n /**\n * Internal SOLA frame size in samples. Default 1024 (~21ms at 48kHz).\n * Larger = more latency but better low-frequency alignment; smaller = lower\n * latency but coarser correlation. The correlation search radius scales with it.\n */\n grainSize?: number;\n}\n\n/**\n * Real-time pitch shifter (WorkletEffect) using SOLA - synchronized\n * overlap-add. Each synthesis grain is realigned by waveform cross-correlation,\n * so grain restarts stay phase coherent and the output pitch tracks the `pitch`\n * ratio exactly across the whole 0.25x-4.0x range (a naive granular delay drifts\n * the pitch instead).\n *\n * Quality: clean, in-tune shifting for tonal material. As with any time-domain\n * method, sharp transients can smear or double slightly; for those a phase\n * vocoder would do better at the cost of much more CPU and latency.\n *\n * Latency: ~one frame + search ≈ 30ms at the default 1024-sample grain\n * (at 48kHz). Not suitable for live monitoring; fine for games / playback.\n *\n * Use cases:\n * - Sound variation: random ±200 cent pitch on each footstep / bullet\n * - Voice effects: chipmunk (1.5x) or demon (0.7x) for game NPCs\n * - Detune layering: stack 0.99x and 1.01x for thick chorused sound\n */\nexport class PitchShiftEffect extends WorkletEffect {\n private _pitch: number;\n private readonly _grainSize: number;\n\n public constructor(options: PitchShiftEffectOptions = {}) {\n super();\n this._pitch = Math.max(0.25, Math.min(4, options.pitch ?? 1));\n this._grainSize = options.grainSize ?? 1024;\n this.wet = options.wet ?? 1;\n }\n\n protected get _workletName(): string {\n return 'exojs-pitch-shift';\n }\n\n protected get _workletSource(): string {\n return pitchShiftWorkletSource;\n }\n\n protected override get _dryLatencySeconds(): number {\n // SOLA algorithmic latency ≈ one analysis frame + the correlation search\n // radius (grainSize/4). Tuned against the wet=0.5 comb-filter test below.\n return (this._grainSize + (this._grainSize >> 2)) / this._sampleRate;\n }\n\n protected override get _workletOptions(): AudioWorkletNodeOptions {\n return {\n numberOfInputs: 1,\n numberOfOutputs: 1,\n processorOptions: { grainSize: this._grainSize },\n };\n }\n\n protected override _onWorkletReady(): void {\n this._setAudioParam('pitch', this._pitch);\n }\n\n /** Pitch ratio relative to the original. 1.0 = no change, 0.5 = one octave down, 2.0 = one octave up. Range 0.25..4.0, default 1.0. */\n public get pitch(): number {\n return this._pitch;\n }\n public set pitch(value: number) {\n this._pitch = Math.max(0.25, Math.min(4, value));\n this._setAudioParam('pitch', this._pitch);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,mBAAb,cAAsC,cAAc;CAClD,AAAQ;CACR,AAAiB;CAEjB,AAAO,YAAY,UAAmC,CAAC,GAAG;EACxD,MAAM;EACN,KAAK,SAAS,KAAK,IAAI,KAAM,KAAK,IAAI,GAAG,QAAQ,SAAS,CAAC,CAAC;EAC5D,KAAK,aAAa,QAAQ,aAAa;EACvC,KAAK,MAAM,QAAQ,OAAO;CAC5B;CAEA,IAAc,eAAuB;EACnC,OAAO;CACT;CAEA,IAAc,iBAAyB;EACrC,OAAOA;CACT;CAEA,IAAuB,qBAA6B;EAGlD,QAAQ,KAAK,cAAc,KAAK,cAAc,MAAM,KAAK;CAC3D;CAEA,IAAuB,kBAA2C;EAChE,OAAO;GACL,gBAAgB;GAChB,iBAAiB;GACjB,kBAAkB,EAAE,WAAW,KAAK,WAAW;EACjD;CACF;CAEA,AAAmB,kBAAwB;EACzC,KAAK,eAAe,SAAS,KAAK,MAAM;CAC1C;;CAGA,IAAW,QAAgB;EACzB,OAAO,KAAK;CACd;CACA,IAAW,MAAM,OAAe;EAC9B,KAAK,SAAS,KAAK,IAAI,KAAM,KAAK,IAAI,GAAG,KAAK,CAAC;EAC/C,KAAK,eAAe,SAAS,KAAK,MAAM;CAC1C;AACF"}
|
|
@@ -10,7 +10,7 @@ export interface ReverbEffectOptions {
|
|
|
10
10
|
* into a `ConvolverNode`. The impulse response is a stereo noise burst whose
|
|
11
11
|
* amplitude decays exponentially, simulating room reflections. Adjusting
|
|
12
12
|
* `durationSeconds` or `decay` rebuilds the impulse response immediately, so
|
|
13
|
-
* avoid animating these properties at audio rate
|
|
13
|
+
* avoid animating these properties at audio rate - use `wet` for real-time
|
|
14
14
|
* mix control instead.
|
|
15
15
|
*/
|
|
16
16
|
export declare class ReverbEffect extends AudioEffect {
|
|
@@ -35,3 +35,4 @@ export declare class ReverbEffect extends AudioEffect {
|
|
|
35
35
|
private _generateImpulseResponse;
|
|
36
36
|
private _setupNodes;
|
|
37
37
|
}
|
|
38
|
+
//# sourceMappingURL=ReverbEffect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReverbEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/ReverbEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6D,MAAM,eAAe,CAAC;AAEvG,qDAAqD;AACrD,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAUD;;;;;;;GAOG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IACF,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,IAAI,CAAS;gBAEF,OAAO,GAAE,mBAAwB;IAYpD,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED,IAAW,UAAU,IAAI,SAAS,CAGjC;IAED,0HAA0H;IAC1H,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED,IAAW,eAAe,CAAC,KAAK,EAAE,MAAM,EAKvC;IAED,0KAA0K;IAC1K,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAK7B;IAED,iGAAiG;IACjG,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAO3B;IAEe,OAAO,IAAI,IAAI;IAY/B,OAAO,CAAC,wBAAwB;IAchC,OAAO,CAAC,WAAW;CAyBpB"}
|