@codexo/exojs-audio-fx 0.19.0 → 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.
Files changed (117) hide show
  1. package/README.md +7 -53
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +12 -20
  5. package/dist/esm/AudioAnalyser.d.ts +0 -125
  6. package/dist/esm/AudioAnalyser.d.ts.map +0 -1
  7. package/dist/esm/AudioAnalyser.js +0 -369
  8. package/dist/esm/AudioAnalyser.js.map +0 -1
  9. package/dist/esm/BeatDetector.d.ts +0 -286
  10. package/dist/esm/BeatDetector.d.ts.map +0 -1
  11. package/dist/esm/BeatDetector.js +0 -419
  12. package/dist/esm/BeatDetector.js.map +0 -1
  13. package/dist/esm/PcmStreamSource.d.ts +0 -127
  14. package/dist/esm/PcmStreamSource.d.ts.map +0 -1
  15. package/dist/esm/PcmStreamSource.js +0 -308
  16. package/dist/esm/PcmStreamSource.js.map +0 -1
  17. package/dist/esm/dsp/fft.d.ts +0 -22
  18. package/dist/esm/dsp/fft.d.ts.map +0 -1
  19. package/dist/esm/dsp/mel.d.ts +0 -43
  20. package/dist/esm/dsp/mel.d.ts.map +0 -1
  21. package/dist/esm/dsp/mel.js +0 -61
  22. package/dist/esm/dsp/mel.js.map +0 -1
  23. package/dist/esm/dsp/tempogram.d.ts +0 -192
  24. package/dist/esm/dsp/tempogram.d.ts.map +0 -1
  25. package/dist/esm/effects/AutoWahEffect.d.ts +0 -128
  26. package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
  27. package/dist/esm/effects/AutoWahEffect.js +0 -214
  28. package/dist/esm/effects/AutoWahEffect.js.map +0 -1
  29. package/dist/esm/effects/BitCrusherEffect.d.ts +0 -64
  30. package/dist/esm/effects/BitCrusherEffect.d.ts.map +0 -1
  31. package/dist/esm/effects/BitCrusherEffect.js +0 -76
  32. package/dist/esm/effects/BitCrusherEffect.js.map +0 -1
  33. package/dist/esm/effects/ChorusEffect.d.ts +0 -54
  34. package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
  35. package/dist/esm/effects/ChorusEffect.js +0 -136
  36. package/dist/esm/effects/ChorusEffect.js.map +0 -1
  37. package/dist/esm/effects/CompressorEffect.d.ts +0 -56
  38. package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
  39. package/dist/esm/effects/CompressorEffect.js +0 -108
  40. package/dist/esm/effects/CompressorEffect.js.map +0 -1
  41. package/dist/esm/effects/ConvolutionEffect.d.ts +0 -119
  42. package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
  43. package/dist/esm/effects/ConvolutionEffect.js +0 -212
  44. package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
  45. package/dist/esm/effects/DelayEffect.d.ts +0 -36
  46. package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
  47. package/dist/esm/effects/DelayEffect.js +0 -109
  48. package/dist/esm/effects/DelayEffect.js.map +0 -1
  49. package/dist/esm/effects/DistortionEffect.d.ts +0 -120
  50. package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
  51. package/dist/esm/effects/DistortionEffect.js +0 -194
  52. package/dist/esm/effects/DistortionEffect.js.map +0 -1
  53. package/dist/esm/effects/DuckingEffect.d.ts +0 -44
  54. package/dist/esm/effects/DuckingEffect.d.ts.map +0 -1
  55. package/dist/esm/effects/DuckingEffect.js +0 -95
  56. package/dist/esm/effects/DuckingEffect.js.map +0 -1
  57. package/dist/esm/effects/EqualizerEffect.d.ts +0 -51
  58. package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
  59. package/dist/esm/effects/EqualizerEffect.js +0 -124
  60. package/dist/esm/effects/EqualizerEffect.js.map +0 -1
  61. package/dist/esm/effects/FlangerEffect.d.ts +0 -99
  62. package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
  63. package/dist/esm/effects/FlangerEffect.js +0 -176
  64. package/dist/esm/effects/FlangerEffect.js.map +0 -1
  65. package/dist/esm/effects/GranularEffect.d.ts +0 -67
  66. package/dist/esm/effects/GranularEffect.d.ts.map +0 -1
  67. package/dist/esm/effects/GranularEffect.js +0 -104
  68. package/dist/esm/effects/GranularEffect.js.map +0 -1
  69. package/dist/esm/effects/LimiterEffect.d.ts +0 -125
  70. package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
  71. package/dist/esm/effects/LimiterEffect.js +0 -186
  72. package/dist/esm/effects/LimiterEffect.js.map +0 -1
  73. package/dist/esm/effects/PhaserEffect.d.ts +0 -127
  74. package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
  75. package/dist/esm/effects/PhaserEffect.js +0 -218
  76. package/dist/esm/effects/PhaserEffect.js.map +0 -1
  77. package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -84
  78. package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
  79. package/dist/esm/effects/PingPongDelayEffect.js +0 -176
  80. package/dist/esm/effects/PingPongDelayEffect.js.map +0 -1
  81. package/dist/esm/effects/PitchShiftEffect.d.ts +0 -46
  82. package/dist/esm/effects/PitchShiftEffect.d.ts.map +0 -1
  83. package/dist/esm/effects/PitchShiftEffect.js +0 -64
  84. package/dist/esm/effects/PitchShiftEffect.js.map +0 -1
  85. package/dist/esm/effects/ReverbEffect.d.ts +0 -38
  86. package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
  87. package/dist/esm/effects/ReverbEffect.js +0 -117
  88. package/dist/esm/effects/ReverbEffect.js.map +0 -1
  89. package/dist/esm/effects/RingModulatorEffect.d.ts +0 -96
  90. package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
  91. package/dist/esm/effects/RingModulatorEffect.js +0 -157
  92. package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
  93. package/dist/esm/effects/TremoloEffect.d.ts +0 -111
  94. package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
  95. package/dist/esm/effects/TremoloEffect.js +0 -197
  96. package/dist/esm/effects/TremoloEffect.js.map +0 -1
  97. package/dist/esm/effects/VocoderEffect.d.ts +0 -45
  98. package/dist/esm/effects/VocoderEffect.d.ts.map +0 -1
  99. package/dist/esm/effects/VocoderEffect.js +0 -73
  100. package/dist/esm/effects/VocoderEffect.js.map +0 -1
  101. package/dist/esm/index.d.ts +0 -25
  102. package/dist/esm/index.d.ts.map +0 -1
  103. package/dist/esm/index.js +0 -24
  104. package/dist/esm/worklets/beat-detector.worklet.js +0 -6
  105. package/dist/esm/worklets/beat-detector.worklet.js.map +0 -1
  106. package/dist/esm/worklets/bit-crusher.worklet.js +0 -6
  107. package/dist/esm/worklets/bit-crusher.worklet.js.map +0 -1
  108. package/dist/esm/worklets/ducking.worklet.js +0 -6
  109. package/dist/esm/worklets/ducking.worklet.js.map +0 -1
  110. package/dist/esm/worklets/granular.worklet.js +0 -6
  111. package/dist/esm/worklets/granular.worklet.js.map +0 -1
  112. package/dist/esm/worklets/pcm-stream.worklet.js +0 -6
  113. package/dist/esm/worklets/pcm-stream.worklet.js.map +0 -1
  114. package/dist/esm/worklets/pitch-shift.worklet.js +0 -6
  115. package/dist/esm/worklets/pitch-shift.worklet.js.map +0 -1
  116. package/dist/esm/worklets/vocoder.worklet.js +0 -6
  117. package/dist/esm/worklets/vocoder.worklet.js.map +0 -1
@@ -1,96 +0,0 @@
1
- import { AudioEffect } from '@codexo/exojs';
2
- /** Construction options for {@link RingModulatorEffect}. */
3
- export interface RingModulatorEffectOptions {
4
- /**
5
- * Carrier oscillator frequency in Hz. Range 0..20000, default 440. Lower
6
- * frequencies (1-60 Hz) produce tremolo-like pulsing; mid-range values
7
- * (100-1000 Hz) give the characteristic robotic ring-mod sound; high values
8
- * shift sidebands above the audible fundamental.
9
- */
10
- frequency?: number;
11
- /**
12
- * Carrier oscillator waveform shape. Default `'sine'`. Any
13
- * `OscillatorType` is accepted (`'sine'`, `'square'`, `'sawtooth'`,
14
- * `'triangle'`). Non-sine shapes introduce additional harmonic content into
15
- * both sidebands.
16
- */
17
- waveform?: OscillatorType;
18
- /**
19
- * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.0
20
- * (fully wet / ring-modulated). Set to 0.5 for an equal mix of dry and
21
- * ring-modulated signal.
22
- */
23
- wet?: number;
24
- }
25
- /**
26
- * Ring modulator effect using native Web Audio nodes (no worklet required).
27
- *
28
- * A carrier `OscillatorNode` is connected directly to the `gain` AudioParam of
29
- * a `GainNode` whose base gain value is 0. The carrier's bipolar output (±1)
30
- * modulates the gain, multiplying the input signal by the instantaneous carrier
31
- * amplitude - the mathematical definition of ring modulation. The result
32
- * contains the sum and difference frequencies of the input and carrier but
33
- * suppresses the original carrier (unlike amplitude modulation, which retains
34
- * the carrier). At sub-audio carrier frequencies (< 20 Hz) the effect becomes
35
- * a tremolo.
36
- *
37
- * Node graph:
38
- * ```
39
- * input(GainNode) ┬── dryGain ──────────────────────────┐
40
- * │ ├── output(GainNode)
41
- * └── ringGain ── wetGain ────────────────┘
42
- *
43
- * carrierOsc ── ringGain.gain (AudioParam, base = 0)
44
- * ```
45
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`;
46
- * `ringGain.gain` base = 0 (carrier provides the ±1 modulation).
47
- *
48
- * @example
49
- * ```ts
50
- * const ringMod = new RingModulatorEffect({ frequency: 220, wet: 0.8 });
51
- * bus.addEffect(ringMod);
52
- *
53
- * // Change carrier frequency at runtime:
54
- * ringMod.frequency = 440;
55
- * ```
56
- */
57
- export declare class RingModulatorEffect extends AudioEffect {
58
- private _setup;
59
- private _frequency;
60
- private _waveform;
61
- private _wet;
62
- private readonly _onAudioContextReady;
63
- constructor(options?: RingModulatorEffectOptions);
64
- /**
65
- * The node where audio enters this effect. Throws if the audio context is
66
- * not yet initialized.
67
- */
68
- get inputNode(): AudioNode;
69
- /**
70
- * The node where audio exits this effect. Throws if the audio context is
71
- * not yet initialized.
72
- */
73
- get outputNode(): AudioNode;
74
- /**
75
- * Carrier oscillator frequency in Hz. Range 0..20000, default 440.
76
- * Changes are ramped smoothly via `setTargetAtTime`.
77
- */
78
- get frequency(): number;
79
- set frequency(value: number);
80
- /**
81
- * Carrier oscillator waveform shape. Default `'sine'`. Changes take effect
82
- * immediately (no smoothing; waveform transitions are instantaneous in Web
83
- * Audio).
84
- */
85
- get waveform(): OscillatorType;
86
- set waveform(value: OscillatorType);
87
- /**
88
- * Wet (ring-modulated) mix level, 0..1. The dry level is automatically
89
- * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
90
- */
91
- get wet(): number;
92
- set wet(value: number);
93
- destroy(): void;
94
- private _setupNodes;
95
- }
96
- //# sourceMappingURL=RingModulatorEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RingModulatorEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/RingModulatorEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6D,MAAM,eAAe,CAAC;AAEvG,4DAA4D;AAC5D,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,OAAO,CAAC,MAAM,CAAyC;IACvD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IAEF,YAAmB,OAAO,GAAE,0BAA+B,EAU1D;IAED;;;OAGG;IACH,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED;;;OAGG;IACH,IAAW,UAAU,IAAI,SAAS,CAGjC;IAED;;;OAGG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,IAAW,SAAS,CAAC,KAAK,EAAE,MAAM,EAMjC;IAED;;;;OAIG;IACH,IAAW,QAAQ,IAAI,cAAc,CAEpC;IAED,IAAW,QAAQ,CAAC,KAAK,EAAE,cAAc,EAKxC;IAED;;;OAGG;IACH,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAO3B;IAEe,OAAO,IAAI,IAAI,CAY9B;IAED,OAAO,CAAC,WAAW;CAuCpB"}
@@ -1,157 +0,0 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } 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
- _onAudioContextReady = (ctx) => {
42
- onAudioContextReady.remove(this._onAudioContextReady);
43
- this._setupNodes(ctx);
44
- };
45
- constructor(options = {}) {
46
- super();
47
- this._frequency = Math.max(0, Math.min(2e4, options.frequency ?? 440));
48
- this._waveform = options.waveform ?? "sine";
49
- this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
50
- if (isAudioContextReady()) this._setupNodes(getAudioContext());
51
- else onAudioContextReady.add(this._onAudioContextReady);
52
- }
53
- /**
54
- * The node where audio enters this effect. Throws if the audio context is
55
- * not yet initialized.
56
- */
57
- get inputNode() {
58
- if (!this._setup) throw new Error("RingModulatorEffect not yet initialized.");
59
- return this._setup.inputGain;
60
- }
61
- /**
62
- * The node where audio exits this effect. Throws if the audio context is
63
- * not yet initialized.
64
- */
65
- get outputNode() {
66
- if (!this._setup) throw new Error("RingModulatorEffect not yet initialized.");
67
- return this._setup.outputGain;
68
- }
69
- /**
70
- * Carrier oscillator frequency in Hz. Range 0..20000, default 440.
71
- * Changes are ramped smoothly via `setTargetAtTime`.
72
- */
73
- get frequency() {
74
- return this._frequency;
75
- }
76
- set frequency(value) {
77
- this._frequency = Math.max(0, Math.min(2e4, value));
78
- if (this._setup) {
79
- const ctx = this._setup.inputGain.context;
80
- this._setup.carrierOsc.frequency.setTargetAtTime(this._frequency, ctx.currentTime, .01);
81
- }
82
- }
83
- /**
84
- * Carrier oscillator waveform shape. Default `'sine'`. Changes take effect
85
- * immediately (no smoothing; waveform transitions are instantaneous in Web
86
- * Audio).
87
- */
88
- get waveform() {
89
- return this._waveform;
90
- }
91
- set waveform(value) {
92
- this._waveform = value;
93
- if (this._setup) this._setup.carrierOsc.type = this._waveform;
94
- }
95
- /**
96
- * Wet (ring-modulated) mix level, 0..1. The dry level is automatically
97
- * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
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.carrierOsc.stop();
114
- this._setup.carrierOsc.disconnect();
115
- this._setup.ringGain.disconnect();
116
- this._setup.dryGain.disconnect();
117
- this._setup.wetGain.disconnect();
118
- this._setup.inputGain.disconnect();
119
- this._setup.outputGain.disconnect();
120
- this._setup = null;
121
- }
122
- }
123
- _setupNodes(ctx) {
124
- const inputGain = ctx.createGain();
125
- const outputGain = ctx.createGain();
126
- const dryGain = ctx.createGain();
127
- const wetGain = ctx.createGain();
128
- const ringGain = ctx.createGain();
129
- inputGain.gain.setValueAtTime(1, ctx.currentTime);
130
- outputGain.gain.setValueAtTime(1, ctx.currentTime);
131
- dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
132
- wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
133
- ringGain.gain.setValueAtTime(0, ctx.currentTime);
134
- const carrierOsc = ctx.createOscillator();
135
- carrierOsc.type = this._waveform;
136
- carrierOsc.frequency.value = this._frequency;
137
- carrierOsc.connect(ringGain.gain);
138
- inputGain.connect(dryGain);
139
- dryGain.connect(outputGain);
140
- inputGain.connect(ringGain);
141
- ringGain.connect(wetGain);
142
- wetGain.connect(outputGain);
143
- carrierOsc.start();
144
- this._setup = {
145
- inputGain,
146
- outputGain,
147
- dryGain,
148
- wetGain,
149
- ringGain,
150
- carrierOsc
151
- };
152
- }
153
- };
154
-
155
- //#endregion
156
- export { RingModulatorEffect };
157
- //# sourceMappingURL=RingModulatorEffect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RingModulatorEffect.js","names":[],"sources":["../../../src/effects/RingModulatorEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } 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 private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\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 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('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 onAudioContextReady.remove(this._onAudioContextReady);\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;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,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,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,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,UAAU;GAClC,KAAK,OAAO,WAAW,UAAU,gBAAgB,KAAK,YAAY,IAAI,aAAa,GAAI;EACzF;CACF;;;;;;CAOA,IAAW,W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E/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,111 +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. Determines the amplitude of the LFO that modulates
11
- * `tremoloGain.gain`. The base gain is `1 - depth`; adding the LFO (peak = `depth`)
12
- * makes the gain oscillate between `1 - 2 * depth` and `1`. At depth=0 the effect
13
- * is transparent; at depth=0.5 the gain briefly reaches zero at the trough; at
14
- * depth>0.5 the gain goes negative (phase inversion at the trough). Default 0.7.
15
- */
16
- depth?: number;
17
- /**
18
- * When `true` the same LFO also drives a `StereoPannerNode.pan` (amplitude = `depth`),
19
- * sweeping the signal left and right in synchrony with the tremolo pulsing. This option
20
- * is read-only after construction. Default `false`.
21
- */
22
- autoPan?: boolean;
23
- /**
24
- * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.
25
- */
26
- wet?: number;
27
- }
28
- /**
29
- * Tremolo effect that amplitude-modulates the signal with a sine LFO using native WebAudio nodes.
30
- *
31
- * A sine-wave LFO drives a `GainNode`'s gain to produce the characteristic volume pulsing of
32
- * tremolo. The base gain is `1 - depth` and the LFO peak deviation is `depth`, so the gain
33
- * oscillates between `1 - 2 * depth` and `1`. Optionally the same LFO can drive a
34
- * `StereoPannerNode.pan` for a synchronized auto-pan effect.
35
- *
36
- * Node graph (`autoPan = false`):
37
- * ```
38
- * inputGain ┬── dryGain ──────────────────────────┐
39
- * │ ├── outputGain
40
- * └── tremoloGain ── wetGain ─────────────┘
41
- *
42
- * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
43
- * ```
44
- *
45
- * Node graph (`autoPan = true`):
46
- * ```
47
- * inputGain ┬── dryGain ──────────────────────────────────┐
48
- * │ ├── outputGain
49
- * └── tremoloGain ── panner ── wetGain ──────────┘
50
- *
51
- * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
52
- * lfoOscillator ── panGain (depth) ── panner.pan
53
- * ```
54
- *
55
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth`.
56
- *
57
- * @example
58
- * ```ts
59
- * // Classic tremolo at 5 Hz, 70 % depth, full wet
60
- * const tremolo = new TremoloEffect({ rateHz: 5, depth: 0.7, wet: 1 });
61
- * bus.addEffect(tremolo);
62
- *
63
- * // Slow auto-pan at 0.5 Hz
64
- * const autopan = new TremoloEffect({ rateHz: 0.5, depth: 0.5, autoPan: true });
65
- * bus.addEffect(autopan);
66
- * ```
67
- */
68
- export declare class TremoloEffect extends AudioEffect {
69
- private _setup;
70
- private _rateHz;
71
- private _depth;
72
- private readonly _autoPan;
73
- private _wet;
74
- private readonly _onAudioContextReady;
75
- constructor(options?: TremoloEffectOptions);
76
- /**
77
- * The node where audio enters this effect. Throws if the audio context is not yet initialized.
78
- */
79
- get inputNode(): AudioNode;
80
- /**
81
- * The node where audio exits this effect. Throws if the audio context is not yet initialized.
82
- */
83
- get outputNode(): AudioNode;
84
- /**
85
- * LFO oscillation rate in Hz. Range 0..20, default 5.
86
- * Ramped via `setTargetAtTime` when changed at runtime.
87
- */
88
- get rateHz(): number;
89
- set rateHz(value: number);
90
- /**
91
- * Modulation depth, 0..1. At 0 the effect is transparent; at 0.5 the gain briefly
92
- * reaches zero at the trough; at depth>0.5 the gain goes negative (phase inversion).
93
- * Default 0.7. Ramped via `setTargetAtTime`.
94
- */
95
- get depth(): number;
96
- set depth(value: number);
97
- /**
98
- * Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};
99
- * read-only at runtime. Default `false`.
100
- */
101
- get autoPan(): boolean;
102
- /**
103
- * Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.
104
- * Ramped via `setTargetAtTime` when changed at runtime.
105
- */
106
- get wet(): number;
107
- set wet(value: number);
108
- destroy(): void;
109
- private _setupNodes;
110
- }
111
- //# 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,EAA6D,MAAM,eAAe,CAAC;AAEvG,sDAAsD;AACtD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;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;IACrB,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IAEF,YAAmB,OAAO,GAAE,oBAAyB,EAWpD;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;CAyDpB"}
@@ -1,197 +0,0 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } 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` and the LFO peak deviation is `depth`, so the gain
9
- * oscillates between `1 - 2 * depth` and `1`. Optionally the same LFO can drive a
10
- * `StereoPannerNode.pan` for a synchronized auto-pan effect.
11
- *
12
- * Node graph (`autoPan = false`):
13
- * ```
14
- * inputGain ┬── dryGain ──────────────────────────┐
15
- * │ ├── outputGain
16
- * └── tremoloGain ── wetGain ─────────────┘
17
- *
18
- * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
19
- * ```
20
- *
21
- * Node graph (`autoPan = true`):
22
- * ```
23
- * inputGain ┬── dryGain ──────────────────────────────────┐
24
- * │ ├── outputGain
25
- * └── tremoloGain ── panner ── wetGain ──────────┘
26
- *
27
- * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain
28
- * lfoOscillator ── panGain (depth) ── panner.pan
29
- * ```
30
- *
31
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth`.
32
- *
33
- * @example
34
- * ```ts
35
- * // Classic tremolo at 5 Hz, 70 % depth, full wet
36
- * const tremolo = new TremoloEffect({ rateHz: 5, depth: 0.7, wet: 1 });
37
- * bus.addEffect(tremolo);
38
- *
39
- * // Slow auto-pan at 0.5 Hz
40
- * const autopan = new TremoloEffect({ rateHz: 0.5, depth: 0.5, autoPan: true });
41
- * bus.addEffect(autopan);
42
- * ```
43
- */
44
- var TremoloEffect = class extends AudioEffect {
45
- _setup = null;
46
- _rateHz;
47
- _depth;
48
- _autoPan;
49
- _wet;
50
- _onAudioContextReady = (ctx) => {
51
- onAudioContextReady.remove(this._onAudioContextReady);
52
- this._setupNodes(ctx);
53
- };
54
- constructor(options = {}) {
55
- super();
56
- this._rateHz = Math.max(0, Math.min(20, options.rateHz ?? 5));
57
- this._depth = Math.max(0, Math.min(1, options.depth ?? .7));
58
- this._autoPan = options.autoPan ?? false;
59
- this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
60
- if (isAudioContextReady()) this._setupNodes(getAudioContext());
61
- else onAudioContextReady.add(this._onAudioContextReady);
62
- }
63
- /**
64
- * The node where audio enters this effect. Throws if the audio context is not yet initialized.
65
- */
66
- get inputNode() {
67
- if (!this._setup) throw new Error("TremoloEffect not yet initialized.");
68
- return this._setup.inputGain;
69
- }
70
- /**
71
- * The node where audio exits this effect. Throws if the audio context is not yet initialized.
72
- */
73
- get outputNode() {
74
- if (!this._setup) throw new Error("TremoloEffect not yet initialized.");
75
- return this._setup.outputGain;
76
- }
77
- /**
78
- * LFO oscillation rate in Hz. Range 0..20, default 5.
79
- * Ramped via `setTargetAtTime` when changed at runtime.
80
- */
81
- get rateHz() {
82
- return this._rateHz;
83
- }
84
- set rateHz(value) {
85
- this._rateHz = Math.max(0, Math.min(20, value));
86
- if (this._setup) this._setup.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._setup.inputGain.context.currentTime, .01);
87
- }
88
- /**
89
- * Modulation depth, 0..1. At 0 the effect is transparent; at 0.5 the gain briefly
90
- * reaches zero at the trough; at depth>0.5 the gain goes negative (phase inversion).
91
- * Default 0.7. Ramped via `setTargetAtTime`.
92
- */
93
- get depth() {
94
- return this._depth;
95
- }
96
- set depth(value) {
97
- this._depth = Math.max(0, Math.min(1, value));
98
- if (this._setup) {
99
- const t = this._setup.inputGain.context.currentTime;
100
- this._setup.lfoGain.gain.setTargetAtTime(this._depth, t, .01);
101
- this._setup.tremoloGain.gain.setTargetAtTime(1 - this._depth, t, .01);
102
- if (this._setup.panGain) this._setup.panGain.gain.setTargetAtTime(this._depth, t, .01);
103
- }
104
- }
105
- /**
106
- * Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};
107
- * read-only at runtime. Default `false`.
108
- */
109
- get autoPan() {
110
- return this._autoPan;
111
- }
112
- /**
113
- * Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.
114
- * Ramped via `setTargetAtTime` when changed at runtime.
115
- */
116
- get wet() {
117
- return this._wet;
118
- }
119
- set wet(value) {
120
- this._wet = Math.max(0, Math.min(1, value));
121
- if (this._setup) {
122
- const ctx = this._setup.wetGain.context;
123
- this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
124
- this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
125
- }
126
- }
127
- destroy() {
128
- onAudioContextReady.remove(this._onAudioContextReady);
129
- if (this._setup) {
130
- this._setup.lfoOscillator.stop();
131
- this._setup.lfoOscillator.disconnect();
132
- this._setup.lfoGain.disconnect();
133
- this._setup.tremoloGain.disconnect();
134
- if (this._setup.panner) this._setup.panner.disconnect();
135
- if (this._setup.panGain) this._setup.panGain.disconnect();
136
- this._setup.dryGain.disconnect();
137
- this._setup.wetGain.disconnect();
138
- this._setup.inputGain.disconnect();
139
- this._setup.outputGain.disconnect();
140
- this._setup = null;
141
- }
142
- }
143
- _setupNodes(ctx) {
144
- const inputGain = ctx.createGain();
145
- const outputGain = ctx.createGain();
146
- const dryGain = ctx.createGain();
147
- const wetGain = ctx.createGain();
148
- const tremoloGain = ctx.createGain();
149
- const lfoGain = ctx.createGain();
150
- inputGain.gain.setValueAtTime(1, ctx.currentTime);
151
- outputGain.gain.setValueAtTime(1, ctx.currentTime);
152
- dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
153
- wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
154
- tremoloGain.gain.setValueAtTime(1 - this._depth, ctx.currentTime);
155
- lfoGain.gain.setValueAtTime(this._depth, ctx.currentTime);
156
- const lfoOscillator = ctx.createOscillator();
157
- lfoOscillator.type = "sine";
158
- lfoOscillator.frequency.value = this._rateHz;
159
- lfoOscillator.connect(lfoGain);
160
- lfoGain.connect(tremoloGain.gain);
161
- inputGain.connect(dryGain);
162
- dryGain.connect(outputGain);
163
- let panner = null;
164
- let panGain = null;
165
- if (this._autoPan) {
166
- panner = ctx.createStereoPanner();
167
- panGain = ctx.createGain();
168
- panGain.gain.setValueAtTime(this._depth, ctx.currentTime);
169
- lfoOscillator.connect(panGain);
170
- panGain.connect(panner.pan);
171
- inputGain.connect(tremoloGain);
172
- tremoloGain.connect(panner);
173
- panner.connect(wetGain);
174
- wetGain.connect(outputGain);
175
- } else {
176
- inputGain.connect(tremoloGain);
177
- tremoloGain.connect(wetGain);
178
- wetGain.connect(outputGain);
179
- }
180
- lfoOscillator.start();
181
- this._setup = {
182
- inputGain,
183
- outputGain,
184
- dryGain,
185
- wetGain,
186
- tremoloGain,
187
- lfoOscillator,
188
- lfoGain,
189
- panner,
190
- panGain
191
- };
192
- }
193
- };
194
-
195
- //#endregion
196
- export { TremoloEffect };
197
- //# sourceMappingURL=TremoloEffect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TremoloEffect.js","names":[],"sources":["../../../src/effects/TremoloEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link TremoloEffect}. */\nexport interface TremoloEffectOptions {\n /**\n * LFO oscillation rate in Hz controlling the speed of the tremolo pulse.\n * Range 0..20, default 5.\n */\n rateHz?: number;\n /**\n * Modulation depth, 0..1. Determines the amplitude of the LFO that modulates\n * `tremoloGain.gain`. The base gain is `1 - depth`; adding the LFO (peak = `depth`)\n * makes the gain oscillate between `1 - 2 * depth` and `1`. At depth=0 the effect\n * is transparent; at depth=0.5 the gain briefly reaches zero at the trough; at\n * depth>0.5 the gain goes negative (phase inversion at the trough). Default 0.7.\n */\n depth?: number;\n /**\n * When `true` the same LFO also drives a `StereoPannerNode.pan` (amplitude = `depth`),\n * sweeping the signal left and right in synchrony with the tremolo pulsing. This option\n * is read-only after construction. Default `false`.\n */\n autoPan?: boolean;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.\n */\n wet?: number;\n}\n\ninterface TremoloEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly tremoloGain: GainNode;\n readonly lfoOscillator: OscillatorNode;\n readonly lfoGain: GainNode;\n readonly panner: StereoPannerNode | null;\n readonly panGain: GainNode | null;\n}\n\n/**\n * Tremolo effect that amplitude-modulates the signal with a sine LFO using native WebAudio nodes.\n *\n * A sine-wave LFO drives a `GainNode`'s gain to produce the characteristic volume pulsing of\n * tremolo. The base gain is `1 - depth` and the LFO peak deviation is `depth`, so the gain\n * oscillates between `1 - 2 * depth` and `1`. Optionally the same LFO can drive a\n * `StereoPannerNode.pan` for a synchronized auto-pan effect.\n *\n * Node graph (`autoPan = false`):\n * ```\n * inputGain ┬── dryGain ──────────────────────────┐\n * │ ├── outputGain\n * └── tremoloGain ── wetGain ─────────────┘\n *\n * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain\n * ```\n *\n * Node graph (`autoPan = true`):\n * ```\n * inputGain ┬── dryGain ──────────────────────────────────┐\n * │ ├── outputGain\n * └── tremoloGain ── panner ── wetGain ──────────┘\n *\n * lfoOscillator ── lfoGain (depth) ── tremoloGain.gain\n * lfoOscillator ── panGain (depth) ── panner.pan\n * ```\n *\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`; `tremoloGain.gain` base = `1 - depth`.\n *\n * @example\n * ```ts\n * // Classic tremolo at 5 Hz, 70 % depth, full wet\n * const tremolo = new TremoloEffect({ rateHz: 5, depth: 0.7, wet: 1 });\n * bus.addEffect(tremolo);\n *\n * // Slow auto-pan at 0.5 Hz\n * const autopan = new TremoloEffect({ rateHz: 0.5, depth: 0.5, autoPan: true });\n * bus.addEffect(autopan);\n * ```\n */\nexport class TremoloEffect extends AudioEffect {\n private _setup: TremoloEffectSetup | null = null;\n private _rateHz: number;\n private _depth: number;\n private readonly _autoPan: boolean;\n private _wet: number;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\n\n public constructor(options: TremoloEffectOptions = {}) {\n super();\n this._rateHz = Math.max(0, Math.min(20, options.rateHz ?? 5));\n this._depth = Math.max(0, Math.min(1, options.depth ?? 0.7));\n this._autoPan = options.autoPan ?? false;\n this._wet = Math.max(0, Math.min(1, options.wet ?? 1));\n if (isAudioContextReady()) {\n this._setupNodes(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\n }\n\n /**\n * The node where audio enters this effect. Throws if the audio context is not yet initialized.\n */\n public get inputNode(): AudioNode {\n if (!this._setup) throw new Error('TremoloEffect not yet initialized.');\n return this._setup.inputGain;\n }\n\n /**\n * The node where audio exits this effect. Throws if the audio context is not yet initialized.\n */\n public get outputNode(): AudioNode {\n if (!this._setup) throw new Error('TremoloEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n /**\n * LFO oscillation rate in Hz. Range 0..20, default 5.\n * Ramped via `setTargetAtTime` when changed at runtime.\n */\n public get rateHz(): number {\n return this._rateHz;\n }\n\n public set rateHz(value: number) {\n this._rateHz = Math.max(0, Math.min(20, value));\n if (this._setup) {\n this._setup.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._setup.inputGain.context.currentTime, 0.01);\n }\n }\n\n /**\n * Modulation depth, 0..1. At 0 the effect is transparent; at 0.5 the gain briefly\n * reaches zero at the trough; at depth>0.5 the gain goes negative (phase inversion).\n * Default 0.7. Ramped via `setTargetAtTime`.\n */\n public get depth(): number {\n return this._depth;\n }\n\n public set depth(value: number) {\n this._depth = Math.max(0, Math.min(1, value));\n if (this._setup) {\n const t = this._setup.inputGain.context.currentTime;\n this._setup.lfoGain.gain.setTargetAtTime(this._depth, t, 0.01);\n this._setup.tremoloGain.gain.setTargetAtTime(1 - this._depth, t, 0.01);\n if (this._setup.panGain) {\n this._setup.panGain.gain.setTargetAtTime(this._depth, t, 0.01);\n }\n }\n }\n\n /**\n * Whether auto-pan is enabled. Set at construction time via {@link TremoloEffectOptions.autoPan};\n * read-only at runtime. Default `false`.\n */\n public get autoPan(): boolean {\n return this._autoPan;\n }\n\n /**\n * Wet (tremolo) mix level, 0..1. The dry level is automatically `1 - wet`. Default 1.\n * Ramped via `setTargetAtTime` when changed at runtime.\n */\n public get wet(): number {\n return this._wet;\n }\n\n public set wet(value: number) {\n this._wet = Math.max(0, Math.min(1, value));\n if (this._setup) {\n const ctx = this._setup.wetGain.context;\n this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, 0.01);\n this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, 0.01);\n }\n }\n\n public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n if (this._setup) {\n this._setup.lfoOscillator.stop();\n this._setup.lfoOscillator.disconnect();\n this._setup.lfoGain.disconnect();\n this._setup.tremoloGain.disconnect();\n if (this._setup.panner) this._setup.panner.disconnect();\n if (this._setup.panGain) this._setup.panGain.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.inputGain.disconnect();\n this._setup.outputGain.disconnect();\n this._setup = null;\n }\n }\n\n private _setupNodes(ctx: AudioContext): void {\n const inputGain = ctx.createGain();\n const outputGain = ctx.createGain();\n const dryGain = ctx.createGain();\n const wetGain = ctx.createGain();\n const tremoloGain = ctx.createGain();\n const lfoGain = ctx.createGain();\n\n inputGain.gain.setValueAtTime(1, ctx.currentTime);\n outputGain.gain.setValueAtTime(1, ctx.currentTime);\n dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);\n wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);\n // Base gain = 1 - depth; the LFO (amplitude = depth) is added on top via AudioParam\n // modulation, making the effective gain oscillate in [1 - 2*depth, 1].\n tremoloGain.gain.setValueAtTime(1 - this._depth, ctx.currentTime);\n lfoGain.gain.setValueAtTime(this._depth, ctx.currentTime);\n\n const lfoOscillator = ctx.createOscillator();\n lfoOscillator.type = 'sine';\n lfoOscillator.frequency.value = this._rateHz;\n\n // LFO → lfoGain → tremoloGain.gain (AudioParam modulation)\n lfoOscillator.connect(lfoGain);\n lfoGain.connect(tremoloGain.gain as unknown as AudioNode);\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n let panner: StereoPannerNode | null = null;\n let panGain: GainNode | null = null;\n\n if (this._autoPan) {\n panner = ctx.createStereoPanner();\n panGain = ctx.createGain();\n panGain.gain.setValueAtTime(this._depth, ctx.currentTime);\n\n // LFO → panGain → panner.pan (AudioParam modulation)\n lfoOscillator.connect(panGain);\n panGain.connect(panner.pan as unknown as AudioNode);\n\n // Wet path: inputGain → tremoloGain → panner → wetGain → outputGain\n inputGain.connect(tremoloGain);\n tremoloGain.connect(panner);\n panner.connect(wetGain);\n wetGain.connect(outputGain);\n } else {\n // Wet path: inputGain → tremoloGain → wetGain → outputGain\n inputGain.connect(tremoloGain);\n tremoloGain.connect(wetGain);\n wetGain.connect(outputGain);\n }\n\n lfoOscillator.start();\n\n this._setup = { inputGain, outputGain, dryGain, wetGain, tremoloGain, lfoOscillator, lfoGain, panner, panGain };\n }\n}\n"],"m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AAQ;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,CAWhE;IAED,UAAmB,eAAe,CAAC,aAAa,EAAE,YAAY,GAAG,IAAI,CAmBpE;IAED,2IAA2I;IAC3I,IAAW,iBAAiB,IAAI,MAAM,CAErC;IACD,IAAW,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAGzC;CACF"}