@codexo/exojs-audio-fx 0.19.1 → 0.20.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/README.md +7 -53
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +12 -20
- package/dist/esm/AudioAnalyser.d.ts +0 -123
- package/dist/esm/AudioAnalyser.d.ts.map +0 -1
- package/dist/esm/AudioAnalyser.js +0 -295
- package/dist/esm/AudioAnalyser.js.map +0 -1
- package/dist/esm/AudioTap.d.ts +0 -33
- package/dist/esm/AudioTap.d.ts.map +0 -1
- package/dist/esm/AudioTap.js +0 -126
- package/dist/esm/AudioTap.js.map +0 -1
- package/dist/esm/BeatDetector.d.ts +0 -291
- package/dist/esm/BeatDetector.d.ts.map +0 -1
- package/dist/esm/BeatDetector.js +0 -365
- package/dist/esm/BeatDetector.js.map +0 -1
- package/dist/esm/PcmStreamSource.d.ts +0 -132
- package/dist/esm/PcmStreamSource.d.ts.map +0 -1
- package/dist/esm/PcmStreamSource.js +0 -313
- package/dist/esm/PcmStreamSource.js.map +0 -1
- package/dist/esm/ReadyGate.d.ts +0 -25
- package/dist/esm/ReadyGate.d.ts.map +0 -1
- package/dist/esm/ReadyGate.js +0 -69
- package/dist/esm/ReadyGate.js.map +0 -1
- package/dist/esm/dsp/fft.d.ts +0 -22
- package/dist/esm/dsp/fft.d.ts.map +0 -1
- package/dist/esm/dsp/mel.d.ts +0 -43
- package/dist/esm/dsp/mel.d.ts.map +0 -1
- package/dist/esm/dsp/mel.js +0 -61
- package/dist/esm/dsp/mel.js.map +0 -1
- package/dist/esm/dsp/tempogram.d.ts +0 -192
- package/dist/esm/dsp/tempogram.d.ts.map +0 -1
- package/dist/esm/effects/AutoWahEffect.d.ts +0 -127
- package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
- package/dist/esm/effects/AutoWahEffect.js +0 -209
- package/dist/esm/effects/AutoWahEffect.js.map +0 -1
- package/dist/esm/effects/BitCrusherEffect.d.ts +0 -64
- package/dist/esm/effects/BitCrusherEffect.d.ts.map +0 -1
- package/dist/esm/effects/BitCrusherEffect.js +0 -76
- package/dist/esm/effects/BitCrusherEffect.js.map +0 -1
- package/dist/esm/effects/ChorusEffect.d.ts +0 -60
- package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
- package/dist/esm/effects/ChorusEffect.js +0 -139
- package/dist/esm/effects/ChorusEffect.js.map +0 -1
- package/dist/esm/effects/CompressorEffect.d.ts +0 -55
- package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
- package/dist/esm/effects/CompressorEffect.js +0 -103
- package/dist/esm/effects/CompressorEffect.js.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.d.ts +0 -118
- package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.js +0 -207
- package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
- package/dist/esm/effects/DelayEffect.d.ts +0 -35
- package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/DelayEffect.js +0 -104
- package/dist/esm/effects/DelayEffect.js.map +0 -1
- package/dist/esm/effects/DistortionEffect.d.ts +0 -116
- package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
- package/dist/esm/effects/DistortionEffect.js +0 -189
- package/dist/esm/effects/DistortionEffect.js.map +0 -1
- package/dist/esm/effects/DuckingEffect.d.ts +0 -44
- package/dist/esm/effects/DuckingEffect.d.ts.map +0 -1
- package/dist/esm/effects/DuckingEffect.js +0 -89
- package/dist/esm/effects/DuckingEffect.js.map +0 -1
- package/dist/esm/effects/EqualizerEffect.d.ts +0 -50
- package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
- package/dist/esm/effects/EqualizerEffect.js +0 -119
- package/dist/esm/effects/EqualizerEffect.js.map +0 -1
- package/dist/esm/effects/FlangerEffect.d.ts +0 -107
- package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
- package/dist/esm/effects/FlangerEffect.js +0 -178
- package/dist/esm/effects/FlangerEffect.js.map +0 -1
- package/dist/esm/effects/GranularEffect.d.ts +0 -67
- package/dist/esm/effects/GranularEffect.d.ts.map +0 -1
- package/dist/esm/effects/GranularEffect.js +0 -104
- package/dist/esm/effects/GranularEffect.js.map +0 -1
- package/dist/esm/effects/LimiterEffect.d.ts +0 -129
- package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
- package/dist/esm/effects/LimiterEffect.js +0 -185
- package/dist/esm/effects/LimiterEffect.js.map +0 -1
- package/dist/esm/effects/PhaserEffect.d.ts +0 -126
- package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
- package/dist/esm/effects/PhaserEffect.js +0 -213
- package/dist/esm/effects/PhaserEffect.js.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -83
- package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.js +0 -171
- package/dist/esm/effects/PingPongDelayEffect.js.map +0 -1
- package/dist/esm/effects/PitchShiftEffect.d.ts +0 -46
- package/dist/esm/effects/PitchShiftEffect.d.ts.map +0 -1
- package/dist/esm/effects/PitchShiftEffect.js +0 -64
- package/dist/esm/effects/PitchShiftEffect.js.map +0 -1
- package/dist/esm/effects/ReverbEffect.d.ts +0 -37
- package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
- package/dist/esm/effects/ReverbEffect.js +0 -112
- package/dist/esm/effects/ReverbEffect.js.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +0 -95
- package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.js +0 -152
- package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
- package/dist/esm/effects/TremoloEffect.d.ts +0 -108
- package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
- package/dist/esm/effects/TremoloEffect.js +0 -192
- package/dist/esm/effects/TremoloEffect.js.map +0 -1
- package/dist/esm/effects/VocoderEffect.d.ts +0 -45
- package/dist/esm/effects/VocoderEffect.d.ts.map +0 -1
- package/dist/esm/effects/VocoderEffect.js +0 -68
- package/dist/esm/effects/VocoderEffect.js.map +0 -1
- package/dist/esm/index.d.ts +0 -25
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -24
- package/dist/esm/worklets/beat-detector.worklet.js +0 -6
- package/dist/esm/worklets/beat-detector.worklet.js.map +0 -1
- package/dist/esm/worklets/bit-crusher.worklet.js +0 -6
- package/dist/esm/worklets/bit-crusher.worklet.js.map +0 -1
- package/dist/esm/worklets/disposable-processor.d.ts +0 -13
- package/dist/esm/worklets/disposable-processor.d.ts.map +0 -1
- package/dist/esm/worklets/ducking.worklet.js +0 -6
- package/dist/esm/worklets/ducking.worklet.js.map +0 -1
- package/dist/esm/worklets/granular.worklet.js +0 -6
- package/dist/esm/worklets/granular.worklet.js.map +0 -1
- package/dist/esm/worklets/pcm-stream.worklet.js +0 -6
- package/dist/esm/worklets/pcm-stream.worklet.js.map +0 -1
- package/dist/esm/worklets/pitch-shift.worklet.js +0 -6
- package/dist/esm/worklets/pitch-shift.worklet.js.map +0 -1
- package/dist/esm/worklets/vocoder.worklet.js +0 -6
- package/dist/esm/worklets/vocoder.worklet.js.map +0 -1
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { AudioEffect } from "@codexo/exojs";
|
|
2
|
-
|
|
3
|
-
//#region src/effects/RingModulatorEffect.ts
|
|
4
|
-
/**
|
|
5
|
-
* Ring modulator effect using native Web Audio nodes (no worklet required).
|
|
6
|
-
*
|
|
7
|
-
* A carrier `OscillatorNode` is connected directly to the `gain` AudioParam of
|
|
8
|
-
* a `GainNode` whose base gain value is 0. The carrier's bipolar output (±1)
|
|
9
|
-
* modulates the gain, multiplying the input signal by the instantaneous carrier
|
|
10
|
-
* amplitude - the mathematical definition of ring modulation. The result
|
|
11
|
-
* contains the sum and difference frequencies of the input and carrier but
|
|
12
|
-
* suppresses the original carrier (unlike amplitude modulation, which retains
|
|
13
|
-
* the carrier). At sub-audio carrier frequencies (< 20 Hz) the effect becomes
|
|
14
|
-
* a tremolo.
|
|
15
|
-
*
|
|
16
|
-
* Node graph:
|
|
17
|
-
* ```
|
|
18
|
-
* input(GainNode) ┬── dryGain ──────────────────────────┐
|
|
19
|
-
* │ ├── output(GainNode)
|
|
20
|
-
* └── ringGain ── wetGain ────────────────┘
|
|
21
|
-
*
|
|
22
|
-
* carrierOsc ── ringGain.gain (AudioParam, base = 0)
|
|
23
|
-
* ```
|
|
24
|
-
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`;
|
|
25
|
-
* `ringGain.gain` base = 0 (carrier provides the ±1 modulation).
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const ringMod = new RingModulatorEffect({ frequency: 220, wet: 0.8 });
|
|
30
|
-
* bus.addEffect(ringMod);
|
|
31
|
-
*
|
|
32
|
-
* // Change carrier frequency at runtime:
|
|
33
|
-
* ringMod.frequency = 440;
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
var RingModulatorEffect = class extends AudioEffect {
|
|
37
|
-
_setup = null;
|
|
38
|
-
_frequency;
|
|
39
|
-
_waveform;
|
|
40
|
-
_wet;
|
|
41
|
-
constructor(options = {}) {
|
|
42
|
-
super();
|
|
43
|
-
this._frequency = Math.max(0, Math.min(2e4, options.frequency ?? 440));
|
|
44
|
-
this._waveform = options.waveform ?? "sine";
|
|
45
|
-
this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
|
|
46
|
-
this._deferSetup((context) => this._setupNodes(context));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* The node where audio enters this effect. Throws if the audio context is
|
|
50
|
-
* not yet initialized.
|
|
51
|
-
*/
|
|
52
|
-
get inputNode() {
|
|
53
|
-
if (!this._setup) throw new Error("RingModulatorEffect not yet initialized.");
|
|
54
|
-
return this._setup.inputGain;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The node where audio exits this effect. Throws if the audio context is
|
|
58
|
-
* not yet initialized.
|
|
59
|
-
*/
|
|
60
|
-
get outputNode() {
|
|
61
|
-
if (!this._setup) throw new Error("RingModulatorEffect not yet initialized.");
|
|
62
|
-
return this._setup.outputGain;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Carrier oscillator frequency in Hz. Range 0..20000, default 440.
|
|
66
|
-
* Changes are ramped smoothly via `setTargetAtTime`.
|
|
67
|
-
*/
|
|
68
|
-
get frequency() {
|
|
69
|
-
return this._frequency;
|
|
70
|
-
}
|
|
71
|
-
set frequency(value) {
|
|
72
|
-
this._frequency = Math.max(0, Math.min(2e4, value));
|
|
73
|
-
if (this._setup) {
|
|
74
|
-
const ctx = this._setup.inputGain.context;
|
|
75
|
-
this._setup.carrierOsc.frequency.setTargetAtTime(this._frequency, ctx.currentTime, .01);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Carrier oscillator waveform shape. Default `'sine'`. Changes take effect
|
|
80
|
-
* immediately (no smoothing; waveform transitions are instantaneous in Web
|
|
81
|
-
* Audio).
|
|
82
|
-
*/
|
|
83
|
-
get waveform() {
|
|
84
|
-
return this._waveform;
|
|
85
|
-
}
|
|
86
|
-
set waveform(value) {
|
|
87
|
-
this._waveform = value;
|
|
88
|
-
if (this._setup) this._setup.carrierOsc.type = this._waveform;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Wet (ring-modulated) mix level, 0..1. The dry level is automatically
|
|
92
|
-
* `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
|
|
93
|
-
*/
|
|
94
|
-
get wet() {
|
|
95
|
-
return this._wet;
|
|
96
|
-
}
|
|
97
|
-
set wet(value) {
|
|
98
|
-
this._wet = Math.max(0, Math.min(1, value));
|
|
99
|
-
if (this._setup) {
|
|
100
|
-
const ctx = this._setup.wetGain.context;
|
|
101
|
-
this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
|
|
102
|
-
this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
destroy() {
|
|
106
|
-
this._teardown();
|
|
107
|
-
if (this._setup) {
|
|
108
|
-
this._setup.carrierOsc.stop();
|
|
109
|
-
this._setup.carrierOsc.disconnect();
|
|
110
|
-
this._setup.ringGain.disconnect();
|
|
111
|
-
this._setup.dryGain.disconnect();
|
|
112
|
-
this._setup.wetGain.disconnect();
|
|
113
|
-
this._setup.inputGain.disconnect();
|
|
114
|
-
this._setup.outputGain.disconnect();
|
|
115
|
-
this._setup = null;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
_setupNodes(ctx) {
|
|
119
|
-
const inputGain = ctx.createGain();
|
|
120
|
-
const outputGain = ctx.createGain();
|
|
121
|
-
const dryGain = ctx.createGain();
|
|
122
|
-
const wetGain = ctx.createGain();
|
|
123
|
-
const ringGain = ctx.createGain();
|
|
124
|
-
inputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
125
|
-
outputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
126
|
-
dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
|
|
127
|
-
wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
|
|
128
|
-
ringGain.gain.setValueAtTime(0, ctx.currentTime);
|
|
129
|
-
const carrierOsc = ctx.createOscillator();
|
|
130
|
-
carrierOsc.type = this._waveform;
|
|
131
|
-
carrierOsc.frequency.value = this._frequency;
|
|
132
|
-
carrierOsc.connect(ringGain.gain);
|
|
133
|
-
inputGain.connect(dryGain);
|
|
134
|
-
dryGain.connect(outputGain);
|
|
135
|
-
inputGain.connect(ringGain);
|
|
136
|
-
ringGain.connect(wetGain);
|
|
137
|
-
wetGain.connect(outputGain);
|
|
138
|
-
carrierOsc.start();
|
|
139
|
-
this._setup = {
|
|
140
|
-
inputGain,
|
|
141
|
-
outputGain,
|
|
142
|
-
dryGain,
|
|
143
|
-
wetGain,
|
|
144
|
-
ringGain,
|
|
145
|
-
carrierOsc
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
//#endregion
|
|
151
|
-
export { RingModulatorEffect };
|
|
152
|
-
//# sourceMappingURL=RingModulatorEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RingModulatorEffect.js","names":[],"sources":["../../../src/effects/RingModulatorEffect.ts"],"sourcesContent":["import { AudioEffect } from '@codexo/exojs';\n\n/** Construction options for {@link RingModulatorEffect}. */\nexport interface RingModulatorEffectOptions {\n /**\n * Carrier oscillator frequency in Hz. Range 0..20000, default 440. Lower\n * frequencies (1-60 Hz) produce tremolo-like pulsing; mid-range values\n * (100-1000 Hz) give the characteristic robotic ring-mod sound; high values\n * shift sidebands above the audible fundamental.\n */\n frequency?: number;\n /**\n * Carrier oscillator waveform shape. Default `'sine'`. Any\n * `OscillatorType` is accepted (`'sine'`, `'square'`, `'sawtooth'`,\n * `'triangle'`). Non-sine shapes introduce additional harmonic content into\n * both sidebands.\n */\n waveform?: OscillatorType;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.0\n * (fully wet / ring-modulated). Set to 0.5 for an equal mix of dry and\n * ring-modulated signal.\n */\n wet?: number;\n}\n\ninterface RingModulatorEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly ringGain: GainNode;\n readonly carrierOsc: OscillatorNode;\n}\n\n/**\n * Ring modulator effect using native Web Audio nodes (no worklet required).\n *\n * A carrier `OscillatorNode` is connected directly to the `gain` AudioParam of\n * a `GainNode` whose base gain value is 0. The carrier's bipolar output (±1)\n * modulates the gain, multiplying the input signal by the instantaneous carrier\n * amplitude - the mathematical definition of ring modulation. The result\n * contains the sum and difference frequencies of the input and carrier but\n * suppresses the original carrier (unlike amplitude modulation, which retains\n * the carrier). At sub-audio carrier frequencies (< 20 Hz) the effect becomes\n * a tremolo.\n *\n * Node graph:\n * ```\n * input(GainNode) ┬── dryGain ──────────────────────────┐\n * │ ├── output(GainNode)\n * └── ringGain ── wetGain ────────────────┘\n *\n * carrierOsc ── ringGain.gain (AudioParam, base = 0)\n * ```\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`;\n * `ringGain.gain` base = 0 (carrier provides the ±1 modulation).\n *\n * @example\n * ```ts\n * const ringMod = new RingModulatorEffect({ frequency: 220, wet: 0.8 });\n * bus.addEffect(ringMod);\n *\n * // Change carrier frequency at runtime:\n * ringMod.frequency = 440;\n * ```\n */\nexport class RingModulatorEffect extends AudioEffect {\n private _setup: RingModulatorEffectSetup | null = null;\n private _frequency: number;\n private _waveform: OscillatorType;\n private _wet: number;\n\n public constructor(options: RingModulatorEffectOptions = {}) {\n super();\n this._frequency = Math.max(0, Math.min(20000, options.frequency ?? 440));\n this._waveform = options.waveform ?? 'sine';\n this._wet = Math.max(0, Math.min(1, options.wet ?? 1));\n this._deferSetup(context => this._setupNodes(context));\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('RingModulatorEffect 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('RingModulatorEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n /**\n * Carrier oscillator frequency in Hz. Range 0..20000, default 440.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get frequency(): number {\n return this._frequency;\n }\n\n public set frequency(value: number) {\n this._frequency = Math.max(0, Math.min(20000, value));\n if (this._setup) {\n const ctx = this._setup.inputGain.context;\n this._setup.carrierOsc.frequency.setTargetAtTime(this._frequency, ctx.currentTime, 0.01);\n }\n }\n\n /**\n * Carrier oscillator waveform shape. Default `'sine'`. Changes take effect\n * immediately (no smoothing; waveform transitions are instantaneous in Web\n * Audio).\n */\n public get waveform(): OscillatorType {\n return this._waveform;\n }\n\n public set waveform(value: OscillatorType) {\n this._waveform = value;\n if (this._setup) {\n this._setup.carrierOsc.type = this._waveform;\n }\n }\n\n /**\n * Wet (ring-modulated) mix level, 0..1. The dry level is automatically\n * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.\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 this._teardown();\n if (this._setup) {\n this._setup.carrierOsc.stop();\n this._setup.carrierOsc.disconnect();\n this._setup.ringGain.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 ringGain = 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 is 0; the carrier oscillator provides the ±1 modulation signal\n // via AudioParam connection - the effective gain becomes exactly the carrier\n // waveform, multiplying the input: output = input × carrier(t).\n ringGain.gain.setValueAtTime(0, ctx.currentTime);\n\n const carrierOsc = ctx.createOscillator();\n carrierOsc.type = this._waveform;\n carrierOsc.frequency.value = this._frequency;\n\n // Connect carrier to ringGain's gain AudioParam. The carrier (±1) is added\n // to the base value (0), producing an effective gain in [-1, +1] - true\n // bipolar ring modulation. The `as unknown as AudioNode` cast works around\n // a TypeScript overload-resolution quirk (same pattern as ChorusEffect).\n carrierOsc.connect(ringGain.gain as unknown as AudioNode);\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet (ring-modulated) path: inputGain → ringGain → wetGain → outputGain\n inputGain.connect(ringGain);\n ringGain.connect(wetGain);\n wetGain.connect(outputGain);\n\n carrierOsc.start();\n\n this._setup = { inputGain, outputGain, dryGain, wetGain, ringGain, carrierOsc };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,IAAa,sBAAb,cAAyC,YAAY;CACnD,AAAQ,SAA0C;CAClD,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAAsC,CAAC,GAAG;EAC3D,MAAM;EACN,KAAK,aAAa,KAAK,IAAI,GAAG,KAAK,IAAI,KAAO,QAAQ,aAAa,GAAG,CAAC;EACvE,KAAK,YAAY,QAAQ,YAAY;EACrC,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,OAAO,CAAC,CAAC;EACrD,KAAK,aAAY,YAAW,KAAK,YAAY,OAAO,CAAC;CACvD;;;;;CAMA,IAAW,YAAuB;EAChC,IAAI,CAAC,KAAK,QAAQ,MAAM,IAAI,MAAM,0CAA0C;EAC5E,OAAO,KAAK,OAAO;CACrB;;;;;CAMA,IAAW,aAAwB;EACjC,IAAI,CAAC,KAAK,QAAQ,MAAM,IAAI,MAAM,0CAA0C;EAC5E,OAAO,KAAK,OAAO;CACrB;;;;;CAMA,IAAW,YAAoB;EAC7B,OAAO,KAAK;CACd;CAEA,IAAW,UAAU,OAAe;EAClC,KAAK,aAAa,KAAK,IAAI,GAAG,KAAK,IAAI,KAAO,KAAK,CAAC;EACpD,IAAI,KAAK,QAAQ;GACf,MAAM,MAAM,KAAK,OAAO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QAAQ,KAAK,eAAe,KAAK,MAAM,IAAI,WAAW;EAItD,SAAS,KAAK,eAAe,GAAG,IAAI,WAAW;EAE/C,MAAM,aAAa,IAAI,iBAAiB;EACxC,WAAW,OAAO,KAAK;EACvB,WAAW,UAAU,QAAQ,KAAK;EAMlC,WAAW,QAAQ,SAAS,IAA4B;EAGxD,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,OAAO;EACxB,QAAQ,QAAQ,UAAU;EAE1B,WAAW,MAAM;EAEjB,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAU;EAAW;CAChF;AACF"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { AudioEffect } from '@codexo/exojs';
|
|
2
|
-
/** Construction options for {@link TremoloEffect}. */
|
|
3
|
-
export interface TremoloEffectOptions {
|
|
4
|
-
/**
|
|
5
|
-
* LFO oscillation rate in Hz controlling the speed of the tremolo pulse.
|
|
6
|
-
* Range 0..20, default 5.
|
|
7
|
-
*/
|
|
8
|
-
rateHz?: number;
|
|
9
|
-
/**
|
|
10
|
-
* Modulation depth, 0..1: the gain swings between `1 - depth` and `1`. At
|
|
11
|
-
* depth=0 the effect is transparent; at depth=1 the trough reaches silence.
|
|
12
|
-
* Default 0.7.
|
|
13
|
-
*/
|
|
14
|
-
depth?: number;
|
|
15
|
-
/**
|
|
16
|
-
* When `true` the same LFO also drives a `StereoPannerNode.pan` (swinging between `-depth` and `depth`),
|
|
17
|
-
* sweeping the signal left and right in synchrony with the tremolo pulsing. This option
|
|
18
|
-
* is read-only after construction. Default `false`.
|
|
19
|
-
*/
|
|
20
|
-
autoPan?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.
|
|
23
|
-
*/
|
|
24
|
-
wet?: number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Tremolo effect that amplitude-modulates the signal with a sine LFO using native WebAudio nodes.
|
|
28
|
-
*
|
|
29
|
-
* A sine-wave LFO drives a `GainNode`'s gain to produce the characteristic volume pulsing of
|
|
30
|
-
* tremolo. The base gain is `1 - depth / 2` and the LFO peak deviation is `depth / 2`, so the
|
|
31
|
-
* gain oscillates between `1 - depth` and `1`. Optionally the same LFO can drive a
|
|
32
|
-
* `StereoPannerNode.pan` for a synchronized auto-pan effect.
|
|
33
|
-
*
|
|
34
|
-
* Node graph (`autoPan = false`):
|
|
35
|
-
* ```
|
|
36
|
-
* inputGain ┬── dryGain ──────────────────────────┐
|
|
37
|
-
* │ ├── outputGain
|
|
38
|
-
* └── tremoloGain ── wetGain ─────────────┘
|
|
39
|
-
*
|
|
40
|
-
* lfoOscillator ── lfoGain (depth / 2) ── tremoloGain.gain
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* Node graph (`autoPan = true`):
|
|
44
|
-
* ```
|
|
45
|
-
* inputGain ┬── dryGain ──────────────────────────────────┐
|
|
46
|
-
* │ ├── outputGain
|
|
47
|
-
* └── tremoloGain ── panner ── wetGain ──────────┘
|
|
48
|
-
*
|
|
49
|
-
* lfoOscillator ── lfoGain (depth / 2) ── tremoloGain.gain
|
|
50
|
-
* lfoOscillator ── panGain (depth) ── panner.pan
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth / 2`.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* // Classic tremolo at 5 Hz, 70 % depth, full wet
|
|
58
|
-
* const tremolo = new TremoloEffect({ rateHz: 5, depth: 0.7, wet: 1 });
|
|
59
|
-
* bus.addEffect(tremolo);
|
|
60
|
-
*
|
|
61
|
-
* // Slow auto-pan at 0.5 Hz
|
|
62
|
-
* const autopan = new TremoloEffect({ rateHz: 0.5, depth: 0.5, autoPan: true });
|
|
63
|
-
* bus.addEffect(autopan);
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export declare class TremoloEffect extends AudioEffect {
|
|
67
|
-
private _setup;
|
|
68
|
-
private _rateHz;
|
|
69
|
-
private _depth;
|
|
70
|
-
private readonly _autoPan;
|
|
71
|
-
private _wet;
|
|
72
|
-
constructor(options?: TremoloEffectOptions);
|
|
73
|
-
/**
|
|
74
|
-
* The node where audio enters this effect. Throws if the audio context is not yet initialized.
|
|
75
|
-
*/
|
|
76
|
-
get inputNode(): AudioNode;
|
|
77
|
-
/**
|
|
78
|
-
* The node where audio exits this effect. Throws if the audio context is not yet initialized.
|
|
79
|
-
*/
|
|
80
|
-
get outputNode(): AudioNode;
|
|
81
|
-
/**
|
|
82
|
-
* LFO oscillation rate in Hz. Range 0..20, default 5.
|
|
83
|
-
* Ramped via `setTargetAtTime` when changed at runtime.
|
|
84
|
-
*/
|
|
85
|
-
get rateHz(): number;
|
|
86
|
-
set rateHz(value: number);
|
|
87
|
-
/**
|
|
88
|
-
* Modulation depth, 0..1: the gain swings between `1 - depth` and `1`, so 0 is
|
|
89
|
-
* transparent and 1 reaches silence at the trough. Default 0.7. Ramped via
|
|
90
|
-
* `setTargetAtTime`.
|
|
91
|
-
*/
|
|
92
|
-
get depth(): number;
|
|
93
|
-
set depth(value: number);
|
|
94
|
-
/**
|
|
95
|
-
* Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};
|
|
96
|
-
* read-only at runtime. Default `false`.
|
|
97
|
-
*/
|
|
98
|
-
get autoPan(): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.
|
|
101
|
-
* Ramped via `setTargetAtTime` when changed at runtime.
|
|
102
|
-
*/
|
|
103
|
-
get wet(): number;
|
|
104
|
-
set wet(value: number);
|
|
105
|
-
destroy(): void;
|
|
106
|
-
private _setupNodes;
|
|
107
|
-
}
|
|
108
|
-
//# sourceMappingURL=TremoloEffect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TremoloEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/TremoloEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,sDAAsD;AACtD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC5C,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,IAAI,CAAS;IAErB,YAAmB,OAAO,GAAE,oBAAyB,EAOpD;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED;;OAEG;IACH,IAAW,UAAU,IAAI,SAAS,CAGjC;IAED;;;OAGG;IACH,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,MAAM,CAAC,KAAK,EAAE,MAAM,EAK9B;IAED;;;;OAIG;IACH,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAU7B;IAED;;;OAGG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;OAGG;IACH,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAO3B;IAEe,OAAO,IAAI,IAAI,CAe9B;IAED,OAAO,CAAC,WAAW;CA0DpB"}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { AudioEffect } from "@codexo/exojs";
|
|
2
|
-
|
|
3
|
-
//#region src/effects/TremoloEffect.ts
|
|
4
|
-
/**
|
|
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 / 2` and the LFO peak deviation is `depth / 2`, so the
|
|
9
|
-
* gain oscillates between `1 - 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 / 2) ── tremoloGain.gain
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* Node graph (`autoPan = true`):
|
|
22
|
-
* ```
|
|
23
|
-
* inputGain ┬── dryGain ──────────────────────────────────┐
|
|
24
|
-
* │ ├── outputGain
|
|
25
|
-
* └── tremoloGain ── panner ── wetGain ──────────┘
|
|
26
|
-
*
|
|
27
|
-
* lfoOscillator ── lfoGain (depth / 2) ── tremoloGain.gain
|
|
28
|
-
* lfoOscillator ── panGain (depth) ── panner.pan
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth / 2`.
|
|
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
|
-
constructor(options = {}) {
|
|
51
|
-
super();
|
|
52
|
-
this._rateHz = Math.max(0, Math.min(20, options.rateHz ?? 5));
|
|
53
|
-
this._depth = Math.max(0, Math.min(1, options.depth ?? .7));
|
|
54
|
-
this._autoPan = options.autoPan ?? false;
|
|
55
|
-
this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
|
|
56
|
-
this._deferSetup((context) => this._setupNodes(context));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* The node where audio enters this effect. Throws if the audio context is not yet initialized.
|
|
60
|
-
*/
|
|
61
|
-
get inputNode() {
|
|
62
|
-
if (!this._setup) throw new Error("TremoloEffect not yet initialized.");
|
|
63
|
-
return this._setup.inputGain;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* The node where audio exits this effect. Throws if the audio context is not yet initialized.
|
|
67
|
-
*/
|
|
68
|
-
get outputNode() {
|
|
69
|
-
if (!this._setup) throw new Error("TremoloEffect not yet initialized.");
|
|
70
|
-
return this._setup.outputGain;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* LFO oscillation rate in Hz. Range 0..20, default 5.
|
|
74
|
-
* Ramped via `setTargetAtTime` when changed at runtime.
|
|
75
|
-
*/
|
|
76
|
-
get rateHz() {
|
|
77
|
-
return this._rateHz;
|
|
78
|
-
}
|
|
79
|
-
set rateHz(value) {
|
|
80
|
-
this._rateHz = Math.max(0, Math.min(20, value));
|
|
81
|
-
if (this._setup) this._setup.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._setup.inputGain.context.currentTime, .01);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Modulation depth, 0..1: the gain swings between `1 - depth` and `1`, so 0 is
|
|
85
|
-
* transparent and 1 reaches silence at the trough. Default 0.7. Ramped via
|
|
86
|
-
* `setTargetAtTime`.
|
|
87
|
-
*/
|
|
88
|
-
get depth() {
|
|
89
|
-
return this._depth;
|
|
90
|
-
}
|
|
91
|
-
set depth(value) {
|
|
92
|
-
this._depth = Math.max(0, Math.min(1, value));
|
|
93
|
-
if (this._setup) {
|
|
94
|
-
const t = this._setup.inputGain.context.currentTime;
|
|
95
|
-
this._setup.lfoGain.gain.setTargetAtTime(this._depth / 2, t, .01);
|
|
96
|
-
this._setup.tremoloGain.gain.setTargetAtTime(1 - this._depth / 2, t, .01);
|
|
97
|
-
if (this._setup.panGain) this._setup.panGain.gain.setTargetAtTime(this._depth, t, .01);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};
|
|
102
|
-
* read-only at runtime. Default `false`.
|
|
103
|
-
*/
|
|
104
|
-
get autoPan() {
|
|
105
|
-
return this._autoPan;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.
|
|
109
|
-
* Ramped via `setTargetAtTime` when changed at runtime.
|
|
110
|
-
*/
|
|
111
|
-
get wet() {
|
|
112
|
-
return this._wet;
|
|
113
|
-
}
|
|
114
|
-
set wet(value) {
|
|
115
|
-
this._wet = Math.max(0, Math.min(1, value));
|
|
116
|
-
if (this._setup) {
|
|
117
|
-
const ctx = this._setup.wetGain.context;
|
|
118
|
-
this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
|
|
119
|
-
this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
destroy() {
|
|
123
|
-
this._teardown();
|
|
124
|
-
if (this._setup) {
|
|
125
|
-
this._setup.lfoOscillator.stop();
|
|
126
|
-
this._setup.lfoOscillator.disconnect();
|
|
127
|
-
this._setup.lfoGain.disconnect();
|
|
128
|
-
this._setup.tremoloGain.disconnect();
|
|
129
|
-
if (this._setup.panner) this._setup.panner.disconnect();
|
|
130
|
-
if (this._setup.panGain) this._setup.panGain.disconnect();
|
|
131
|
-
this._setup.dryGain.disconnect();
|
|
132
|
-
this._setup.wetGain.disconnect();
|
|
133
|
-
this._setup.inputGain.disconnect();
|
|
134
|
-
this._setup.outputGain.disconnect();
|
|
135
|
-
this._setup = null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
_setupNodes(ctx) {
|
|
139
|
-
const inputGain = ctx.createGain();
|
|
140
|
-
const outputGain = ctx.createGain();
|
|
141
|
-
const dryGain = ctx.createGain();
|
|
142
|
-
const wetGain = ctx.createGain();
|
|
143
|
-
const tremoloGain = ctx.createGain();
|
|
144
|
-
const lfoGain = ctx.createGain();
|
|
145
|
-
inputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
146
|
-
outputGain.gain.setValueAtTime(1, ctx.currentTime);
|
|
147
|
-
dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
|
|
148
|
-
wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
|
|
149
|
-
tremoloGain.gain.setValueAtTime(1 - this._depth / 2, ctx.currentTime);
|
|
150
|
-
lfoGain.gain.setValueAtTime(this._depth / 2, ctx.currentTime);
|
|
151
|
-
const lfoOscillator = ctx.createOscillator();
|
|
152
|
-
lfoOscillator.type = "sine";
|
|
153
|
-
lfoOscillator.frequency.value = this._rateHz;
|
|
154
|
-
lfoOscillator.connect(lfoGain);
|
|
155
|
-
lfoGain.connect(tremoloGain.gain);
|
|
156
|
-
inputGain.connect(dryGain);
|
|
157
|
-
dryGain.connect(outputGain);
|
|
158
|
-
let panner = null;
|
|
159
|
-
let panGain = null;
|
|
160
|
-
if (this._autoPan) {
|
|
161
|
-
panner = ctx.createStereoPanner();
|
|
162
|
-
panGain = ctx.createGain();
|
|
163
|
-
panGain.gain.setValueAtTime(this._depth, ctx.currentTime);
|
|
164
|
-
lfoOscillator.connect(panGain);
|
|
165
|
-
panGain.connect(panner.pan);
|
|
166
|
-
inputGain.connect(tremoloGain);
|
|
167
|
-
tremoloGain.connect(panner);
|
|
168
|
-
panner.connect(wetGain);
|
|
169
|
-
wetGain.connect(outputGain);
|
|
170
|
-
} else {
|
|
171
|
-
inputGain.connect(tremoloGain);
|
|
172
|
-
tremoloGain.connect(wetGain);
|
|
173
|
-
wetGain.connect(outputGain);
|
|
174
|
-
}
|
|
175
|
-
lfoOscillator.start();
|
|
176
|
-
this._setup = {
|
|
177
|
-
inputGain,
|
|
178
|
-
outputGain,
|
|
179
|
-
dryGain,
|
|
180
|
-
wetGain,
|
|
181
|
-
tremoloGain,
|
|
182
|
-
lfoOscillator,
|
|
183
|
-
lfoGain,
|
|
184
|
-
panner,
|
|
185
|
-
panGain
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
//#endregion
|
|
191
|
-
export { TremoloEffect };
|
|
192
|
-
//# sourceMappingURL=TremoloEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TremoloEffect.js","names":[],"sources":["../../../src/effects/TremoloEffect.ts"],"sourcesContent":["import { AudioEffect } 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: the gain swings between `1 - depth` and `1`. At\n * depth=0 the effect is transparent; at depth=1 the trough reaches silence.\n * Default 0.7.\n */\n depth?: number;\n /**\n * When `true` the same LFO also drives a `StereoPannerNode.pan` (swinging between `-depth` and `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 / 2` and the LFO peak deviation is `depth / 2`, so the\n * gain oscillates between `1 - 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 / 2) ── tremoloGain.gain\n * ```\n *\n * Node graph (`autoPan = true`):\n * ```\n * inputGain ┬── dryGain ──────────────────────────────────┐\n * │ ├── outputGain\n * └── tremoloGain ── panner ── wetGain ──────────┘\n *\n * lfoOscillator ── lfoGain (depth / 2) ── tremoloGain.gain\n * lfoOscillator ── panGain (depth) ── panner.pan\n * ```\n *\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth / 2`.\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\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 this._deferSetup(context => this._setupNodes(context));\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: the gain swings between `1 - depth` and `1`, so 0 is\n * transparent and 1 reaches silence at the trough. Default 0.7. Ramped via\n * `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 / 2, t, 0.01);\n this._setup.tremoloGain.gain.setTargetAtTime(1 - this._depth / 2, 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 this._teardown();\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 // The LFO is added on top of the base gain via AudioParam modulation. Centring\n // the swing at 1 - depth / 2 keeps the gain in [1 - depth, 1]: never above\n // unity and never negative, which would invert the phase at the trough.\n tremoloGain.gain.setValueAtTime(1 - this._depth / 2, ctx.currentTime);\n lfoGain.gain.setValueAtTime(this._depth / 2, 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,IAAa,gBAAb,cAAmC,YAAY;CAC7C,AAAQ,SAAoC;CAC5C,AAAQ;CACR,AAAQ;CACR,AAAiB;CACjB,AAAQ;CAER,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,OAAO,KAAK,IAAI,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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,45 +0,0 @@
|
|
|
1
|
-
import { type AudioBus, WorkletEffect } from '@codexo/exojs';
|
|
2
|
-
export interface VocoderEffectOptions {
|
|
3
|
-
/** Modulator AudioBus - its output drives the spectral envelope.
|
|
4
|
-
* Typically routed from a microphone or voice sample. */
|
|
5
|
-
modulator: AudioBus;
|
|
6
|
-
/** Number of frequency bands. More bands = better resolution, more CPU. Default 16. */
|
|
7
|
-
numBands?: number;
|
|
8
|
-
/** Lowest band center frequency in Hz. Default 80. */
|
|
9
|
-
minHz?: number;
|
|
10
|
-
/** Highest band center frequency in Hz. Default 8000. */
|
|
11
|
-
maxHz?: number;
|
|
12
|
-
/** Bandpass Q factor. Higher = narrower bands. Default 4. */
|
|
13
|
-
bandQ?: number;
|
|
14
|
-
/** Dry/wet mix, 0..1. Default 1.0. */
|
|
15
|
-
wet?: number;
|
|
16
|
-
/** Envelope follower smoothing factor (one-pole coefficient).
|
|
17
|
-
* Smaller = smoother / slower. Default 0.005. */
|
|
18
|
-
envelopeSmoothing?: number;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Phase-vocoder-style effect implemented as a {@link WorkletEffect}. Analyzes
|
|
22
|
-
* the spectral envelope of a `modulator` {@link AudioBus} across a bank of
|
|
23
|
-
* log-spaced bandpass filters and applies that envelope to the carrier signal
|
|
24
|
-
* (the main input). The result is the classic "robot voice" or talking-synth
|
|
25
|
-
* effect. Band count, frequency range, and Q are compile-time parameters set
|
|
26
|
-
* at construction; only `wet` and `envelopeSmoothing` are adjustable at
|
|
27
|
-
* runtime.
|
|
28
|
-
*/
|
|
29
|
-
export declare class VocoderEffect extends WorkletEffect {
|
|
30
|
-
private readonly _modulator;
|
|
31
|
-
private readonly _numBands;
|
|
32
|
-
private readonly _minHz;
|
|
33
|
-
private readonly _maxHz;
|
|
34
|
-
private readonly _bandQ;
|
|
35
|
-
private _envelopeSmoothing;
|
|
36
|
-
constructor(options: VocoderEffectOptions);
|
|
37
|
-
protected get _workletName(): string;
|
|
38
|
-
protected get _workletSource(): string;
|
|
39
|
-
protected get _workletOptions(): AudioWorkletNodeOptions;
|
|
40
|
-
protected _onWorkletReady(_audioContext: AudioContext): void;
|
|
41
|
-
/** One-pole envelope follower coefficient. Smaller values produce slower, smoother envelope tracking. Range 0.0001..0.1, default 0.005. */
|
|
42
|
-
get envelopeSmoothing(): number;
|
|
43
|
-
set envelopeSmoothing(value: number);
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=VocoderEffect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;IAEnC,YAAmB,OAAO,EAAE,oBAAoB,EAY/C;IAED,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;IACD,SAAS,KAAK,cAAc,IAAI,MAAM,CAErC;IACD,cAAuB,eAAe,IAAI,uBAAuB,CAchE;IAED,UAAmB,eAAe,CAAC,aAAa,EAAE,YAAY,GAAG,IAAI,CAOpE;IAED,2IAA2I;IAC3I,IAAW,iBAAiB,IAAI,MAAM,CAErC;IACD,IAAW,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAGzC;CACF"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import vocoder_worklet_default from "../worklets/vocoder.worklet.js";
|
|
2
|
-
import { WorkletEffect } from "@codexo/exojs";
|
|
3
|
-
|
|
4
|
-
//#region src/effects/VocoderEffect.ts
|
|
5
|
-
/**
|
|
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
|
-
outputChannelCount: [2],
|
|
43
|
-
processorOptions: {
|
|
44
|
-
numBands: this._numBands,
|
|
45
|
-
minHz: this._minHz,
|
|
46
|
-
maxHz: this._maxHz,
|
|
47
|
-
bandQ: this._bandQ
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
_onWorkletReady(_audioContext) {
|
|
52
|
-
if (!this._modulator) return;
|
|
53
|
-
this._setAudioParam("envelopeSmoothing", this._envelopeSmoothing);
|
|
54
|
-
this._connectAuxInput(this._modulator, 1);
|
|
55
|
-
}
|
|
56
|
-
/** One-pole envelope follower coefficient. Smaller values produce slower, smoother envelope tracking. Range 0.0001..0.1, default 0.005. */
|
|
57
|
-
get envelopeSmoothing() {
|
|
58
|
-
return this._envelopeSmoothing;
|
|
59
|
-
}
|
|
60
|
-
set envelopeSmoothing(value) {
|
|
61
|
-
this._envelopeSmoothing = Math.max(1e-4, Math.min(.1, value));
|
|
62
|
-
this._setAudioParam("envelopeSmoothing", this._envelopeSmoothing);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { VocoderEffect };
|
|
68
|
-
//# sourceMappingURL=VocoderEffect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VocoderEffect.js","names":["vocoderWorkletSource"],"sources":["../../../src/effects/VocoderEffect.ts"],"sourcesContent":["import { type AudioBus, WorkletEffect } from '@codexo/exojs';\n\nimport vocoderWorkletSource from '../worklets/vocoder.worklet.ts?worklet';\n\nexport interface VocoderEffectOptions {\n /** Modulator AudioBus - its output drives the spectral envelope.\n * Typically routed from a microphone or voice sample. */\n modulator: AudioBus;\n /** Number of frequency bands. More bands = better resolution, more CPU. Default 16. */\n numBands?: number;\n /** Lowest band center frequency in Hz. Default 80. */\n minHz?: number;\n /** Highest band center frequency in Hz. Default 8000. */\n maxHz?: number;\n /** Bandpass Q factor. Higher = narrower bands. Default 4. */\n bandQ?: number;\n /** Dry/wet mix, 0..1. Default 1.0. */\n wet?: number;\n /** Envelope follower smoothing factor (one-pole coefficient).\n * Smaller = smoother / slower. Default 0.005. */\n envelopeSmoothing?: number;\n}\n\n/**\n * Phase-vocoder-style effect implemented as a {@link WorkletEffect}. Analyzes\n * the spectral envelope of a `modulator` {@link AudioBus} across a bank of\n * log-spaced bandpass filters and applies that envelope to the carrier signal\n * (the main input). The result is the classic \"robot voice\" or talking-synth\n * effect. Band count, frequency range, and Q are compile-time parameters set\n * at construction; only `wet` and `envelopeSmoothing` are adjustable at\n * runtime.\n */\nexport class VocoderEffect extends WorkletEffect {\n // Declared nullable because super() may trigger _onWorkletReady before the\n // subclass constructor body runs (if construction is aborted by a throw).\n private readonly _modulator: AudioBus | null = null;\n private readonly _numBands: number;\n private readonly _minHz: number;\n private readonly _maxHz: number;\n private readonly _bandQ: number;\n private _envelopeSmoothing: number;\n\n public constructor(options: VocoderEffectOptions) {\n super();\n if (!options.modulator) {\n throw new Error('VocoderEffect requires a modulator AudioBus.');\n }\n this._modulator = options.modulator;\n this._numBands = options.numBands ?? 16;\n this._minHz = options.minHz ?? 80;\n this._maxHz = options.maxHz ?? 8000;\n this._bandQ = options.bandQ ?? 4;\n this._envelopeSmoothing = Math.max(0.0001, Math.min(0.1, options.envelopeSmoothing ?? 0.005));\n this.wet = options.wet ?? 1;\n }\n\n protected get _workletName(): string {\n return 'exojs-vocoder';\n }\n protected get _workletSource(): string {\n return vocoderWorkletSource;\n }\n protected override get _workletOptions(): AudioWorkletNodeOptions {\n return {\n numberOfInputs: 2,\n numberOfOutputs: 1,\n // With two inputs the output no longer follows the carrier's channel\n // count and would default to mono, collapsing a stereo carrier.\n outputChannelCount: [2],\n processorOptions: {\n numBands: this._numBands,\n minHz: this._minHz,\n maxHz: this._maxHz,\n bandQ: this._bandQ,\n },\n };\n }\n\n protected override _onWorkletReady(_audioContext: AudioContext): void {\n // Guard against partially-constructed instances (constructor threw after super()).\n if (!this._modulator) return;\n\n this._setAudioParam('envelopeSmoothing', this._envelopeSmoothing);\n\n this._connectAuxInput(this._modulator, 1);\n }\n\n /** One-pole envelope follower coefficient. Smaller values produce slower, smoother envelope tracking. Range 0.0001..0.1, default 0.005. */\n public get envelopeSmoothing(): number {\n return this._envelopeSmoothing;\n }\n public set envelopeSmoothing(value: number) {\n this._envelopeSmoothing = Math.max(0.0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,0 @@
|
|
|
1
|
-
export type { AudioAnalyserOptions, AudioAnalyserSource, SpectrumMappingOptions } from './AudioAnalyser';
|
|
2
|
-
export { AudioAnalyser } from './AudioAnalyser';
|
|
3
|
-
export type { BandEnergy, BarInfo, BeatDetectorOptions, BeatDetectorSource, BeatInfo, TempoCandidate, TimeSignature, UpcomingBeat } from './BeatDetector';
|
|
4
|
-
export { BeatDetector } from './BeatDetector';
|
|
5
|
-
export { AutoWahEffect, type AutoWahEffectOptions } from './effects/AutoWahEffect';
|
|
6
|
-
export { BitCrusherEffect, type BitCrusherEffectOptions } from './effects/BitCrusherEffect';
|
|
7
|
-
export { ChorusEffect, type ChorusEffectOptions } from './effects/ChorusEffect';
|
|
8
|
-
export { CompressorEffect, type CompressorEffectOptions } from './effects/CompressorEffect';
|
|
9
|
-
export { ConvolutionEffect, type ConvolutionEffectOptions } from './effects/ConvolutionEffect';
|
|
10
|
-
export { DelayEffect, type DelayEffectOptions } from './effects/DelayEffect';
|
|
11
|
-
export { DistortionEffect, type DistortionEffectOptions } from './effects/DistortionEffect';
|
|
12
|
-
export { DuckingEffect, type DuckingEffectOptions } from './effects/DuckingEffect';
|
|
13
|
-
export { EqualizerEffect, type EqualizerEffectOptions } from './effects/EqualizerEffect';
|
|
14
|
-
export { FlangerEffect, type FlangerEffectOptions } from './effects/FlangerEffect';
|
|
15
|
-
export { GranularEffect, type GranularEffectOptions } from './effects/GranularEffect';
|
|
16
|
-
export { LimiterEffect, type LimiterEffectOptions } from './effects/LimiterEffect';
|
|
17
|
-
export { PhaserEffect, type PhaserEffectOptions } from './effects/PhaserEffect';
|
|
18
|
-
export { PingPongDelayEffect, type PingPongDelayEffectOptions } from './effects/PingPongDelayEffect';
|
|
19
|
-
export { PitchShiftEffect, type PitchShiftEffectOptions } from './effects/PitchShiftEffect';
|
|
20
|
-
export { ReverbEffect, type ReverbEffectOptions } from './effects/ReverbEffect';
|
|
21
|
-
export { RingModulatorEffect, type RingModulatorEffectOptions } from './effects/RingModulatorEffect';
|
|
22
|
-
export { TremoloEffect, type TremoloEffectOptions } from './effects/TremoloEffect';
|
|
23
|
-
export { VocoderEffect, type VocoderEffectOptions } from './effects/VocoderEffect';
|
|
24
|
-
export { PcmStreamSource, type PcmStreamSourceOptions, type PcmStreamState } from './PcmStreamSource';
|
|
25
|
-
//# sourceMappingURL=index.d.ts.map
|