@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.
Files changed (127) 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 -123
  6. package/dist/esm/AudioAnalyser.d.ts.map +0 -1
  7. package/dist/esm/AudioAnalyser.js +0 -295
  8. package/dist/esm/AudioAnalyser.js.map +0 -1
  9. package/dist/esm/AudioTap.d.ts +0 -33
  10. package/dist/esm/AudioTap.d.ts.map +0 -1
  11. package/dist/esm/AudioTap.js +0 -126
  12. package/dist/esm/AudioTap.js.map +0 -1
  13. package/dist/esm/BeatDetector.d.ts +0 -291
  14. package/dist/esm/BeatDetector.d.ts.map +0 -1
  15. package/dist/esm/BeatDetector.js +0 -365
  16. package/dist/esm/BeatDetector.js.map +0 -1
  17. package/dist/esm/PcmStreamSource.d.ts +0 -132
  18. package/dist/esm/PcmStreamSource.d.ts.map +0 -1
  19. package/dist/esm/PcmStreamSource.js +0 -313
  20. package/dist/esm/PcmStreamSource.js.map +0 -1
  21. package/dist/esm/ReadyGate.d.ts +0 -25
  22. package/dist/esm/ReadyGate.d.ts.map +0 -1
  23. package/dist/esm/ReadyGate.js +0 -69
  24. package/dist/esm/ReadyGate.js.map +0 -1
  25. package/dist/esm/dsp/fft.d.ts +0 -22
  26. package/dist/esm/dsp/fft.d.ts.map +0 -1
  27. package/dist/esm/dsp/mel.d.ts +0 -43
  28. package/dist/esm/dsp/mel.d.ts.map +0 -1
  29. package/dist/esm/dsp/mel.js +0 -61
  30. package/dist/esm/dsp/mel.js.map +0 -1
  31. package/dist/esm/dsp/tempogram.d.ts +0 -192
  32. package/dist/esm/dsp/tempogram.d.ts.map +0 -1
  33. package/dist/esm/effects/AutoWahEffect.d.ts +0 -127
  34. package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
  35. package/dist/esm/effects/AutoWahEffect.js +0 -209
  36. package/dist/esm/effects/AutoWahEffect.js.map +0 -1
  37. package/dist/esm/effects/BitCrusherEffect.d.ts +0 -64
  38. package/dist/esm/effects/BitCrusherEffect.d.ts.map +0 -1
  39. package/dist/esm/effects/BitCrusherEffect.js +0 -76
  40. package/dist/esm/effects/BitCrusherEffect.js.map +0 -1
  41. package/dist/esm/effects/ChorusEffect.d.ts +0 -60
  42. package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
  43. package/dist/esm/effects/ChorusEffect.js +0 -139
  44. package/dist/esm/effects/ChorusEffect.js.map +0 -1
  45. package/dist/esm/effects/CompressorEffect.d.ts +0 -55
  46. package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
  47. package/dist/esm/effects/CompressorEffect.js +0 -103
  48. package/dist/esm/effects/CompressorEffect.js.map +0 -1
  49. package/dist/esm/effects/ConvolutionEffect.d.ts +0 -118
  50. package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
  51. package/dist/esm/effects/ConvolutionEffect.js +0 -207
  52. package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
  53. package/dist/esm/effects/DelayEffect.d.ts +0 -35
  54. package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
  55. package/dist/esm/effects/DelayEffect.js +0 -104
  56. package/dist/esm/effects/DelayEffect.js.map +0 -1
  57. package/dist/esm/effects/DistortionEffect.d.ts +0 -116
  58. package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
  59. package/dist/esm/effects/DistortionEffect.js +0 -189
  60. package/dist/esm/effects/DistortionEffect.js.map +0 -1
  61. package/dist/esm/effects/DuckingEffect.d.ts +0 -44
  62. package/dist/esm/effects/DuckingEffect.d.ts.map +0 -1
  63. package/dist/esm/effects/DuckingEffect.js +0 -89
  64. package/dist/esm/effects/DuckingEffect.js.map +0 -1
  65. package/dist/esm/effects/EqualizerEffect.d.ts +0 -50
  66. package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
  67. package/dist/esm/effects/EqualizerEffect.js +0 -119
  68. package/dist/esm/effects/EqualizerEffect.js.map +0 -1
  69. package/dist/esm/effects/FlangerEffect.d.ts +0 -107
  70. package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
  71. package/dist/esm/effects/FlangerEffect.js +0 -178
  72. package/dist/esm/effects/FlangerEffect.js.map +0 -1
  73. package/dist/esm/effects/GranularEffect.d.ts +0 -67
  74. package/dist/esm/effects/GranularEffect.d.ts.map +0 -1
  75. package/dist/esm/effects/GranularEffect.js +0 -104
  76. package/dist/esm/effects/GranularEffect.js.map +0 -1
  77. package/dist/esm/effects/LimiterEffect.d.ts +0 -129
  78. package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
  79. package/dist/esm/effects/LimiterEffect.js +0 -185
  80. package/dist/esm/effects/LimiterEffect.js.map +0 -1
  81. package/dist/esm/effects/PhaserEffect.d.ts +0 -126
  82. package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
  83. package/dist/esm/effects/PhaserEffect.js +0 -213
  84. package/dist/esm/effects/PhaserEffect.js.map +0 -1
  85. package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -83
  86. package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
  87. package/dist/esm/effects/PingPongDelayEffect.js +0 -171
  88. package/dist/esm/effects/PingPongDelayEffect.js.map +0 -1
  89. package/dist/esm/effects/PitchShiftEffect.d.ts +0 -46
  90. package/dist/esm/effects/PitchShiftEffect.d.ts.map +0 -1
  91. package/dist/esm/effects/PitchShiftEffect.js +0 -64
  92. package/dist/esm/effects/PitchShiftEffect.js.map +0 -1
  93. package/dist/esm/effects/ReverbEffect.d.ts +0 -37
  94. package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
  95. package/dist/esm/effects/ReverbEffect.js +0 -112
  96. package/dist/esm/effects/ReverbEffect.js.map +0 -1
  97. package/dist/esm/effects/RingModulatorEffect.d.ts +0 -95
  98. package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
  99. package/dist/esm/effects/RingModulatorEffect.js +0 -152
  100. package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
  101. package/dist/esm/effects/TremoloEffect.d.ts +0 -108
  102. package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
  103. package/dist/esm/effects/TremoloEffect.js +0 -192
  104. package/dist/esm/effects/TremoloEffect.js.map +0 -1
  105. package/dist/esm/effects/VocoderEffect.d.ts +0 -45
  106. package/dist/esm/effects/VocoderEffect.d.ts.map +0 -1
  107. package/dist/esm/effects/VocoderEffect.js +0 -68
  108. package/dist/esm/effects/VocoderEffect.js.map +0 -1
  109. package/dist/esm/index.d.ts +0 -25
  110. package/dist/esm/index.d.ts.map +0 -1
  111. package/dist/esm/index.js +0 -24
  112. package/dist/esm/worklets/beat-detector.worklet.js +0 -6
  113. package/dist/esm/worklets/beat-detector.worklet.js.map +0 -1
  114. package/dist/esm/worklets/bit-crusher.worklet.js +0 -6
  115. package/dist/esm/worklets/bit-crusher.worklet.js.map +0 -1
  116. package/dist/esm/worklets/disposable-processor.d.ts +0 -13
  117. package/dist/esm/worklets/disposable-processor.d.ts.map +0 -1
  118. package/dist/esm/worklets/ducking.worklet.js +0 -6
  119. package/dist/esm/worklets/ducking.worklet.js.map +0 -1
  120. package/dist/esm/worklets/granular.worklet.js +0 -6
  121. package/dist/esm/worklets/granular.worklet.js.map +0 -1
  122. package/dist/esm/worklets/pcm-stream.worklet.js +0 -6
  123. package/dist/esm/worklets/pcm-stream.worklet.js.map +0 -1
  124. package/dist/esm/worklets/pitch-shift.worklet.js +0 -6
  125. package/dist/esm/worklets/pitch-shift.worklet.js.map +0 -1
  126. package/dist/esm/worklets/vocoder.worklet.js +0 -6
  127. package/dist/esm/worklets/vocoder.worklet.js.map +0 -1
@@ -1,207 +0,0 @@
1
- import { AudioEffect, Sound } from "@codexo/exojs";
2
-
3
- //#region src/effects/ConvolutionEffect.ts
4
- /**
5
- * Render `buffer` at `sampleRate`. Used for impulse responses, which a
6
- * `ConvolverNode` only accepts at its own context's rate.
7
- */
8
- const resampleBuffer = async (buffer, sampleRate) => {
9
- const frames = Math.max(1, Math.ceil(buffer.length / buffer.sampleRate * sampleRate));
10
- const offline = new OfflineAudioContext(buffer.numberOfChannels, frames, sampleRate);
11
- const source = offline.createBufferSource();
12
- source.buffer = buffer;
13
- source.connect(offline.destination);
14
- source.start();
15
- return offline.startRendering();
16
- };
17
- /**
18
- * Convolution effect that convolves the input signal with a user-supplied
19
- * impulse response (IR). Unlike {@link ReverbEffect}, which generates a
20
- * procedural noise-based IR, `ConvolutionEffect` accepts a *real* decoded IR -
21
- * enabling convolution reverb from acoustic-space captures, cabinet/speaker
22
- * simulations, telephone/pipe character filtering, and any other linear
23
- * time-invariant transformation.
24
- *
25
- * Pass the IR as an `AudioBuffer` (typically decoded via
26
- * `AudioContext.decodeAudioData`) or as a `Sound` (its `audioBuffer` is used).
27
- * Omitting the IR leaves `convolver.buffer` as `null`, making the wet path
28
- * silent and the effect act as a passthrough until {@link setImpulse} is
29
- * called - safe to add to a bus before an IR is available.
30
- *
31
- * Node graph:
32
- * ```
33
- * input(GainNode) → dryGain → output(GainNode)
34
- * input → convolver → wetGain → output
35
- * ```
36
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet × gain`.
37
- *
38
- * @example
39
- * ```ts
40
- * const hall = await loader.load(Asset.type('sound', 'hall.wav'));
41
- * const reverb = new ConvolutionEffect({ impulse: hall, wet: 0.6 });
42
- * bus.addEffect(reverb);
43
- * ```
44
- */
45
- var ConvolutionEffect = class extends AudioEffect {
46
- _setup = null;
47
- _wet;
48
- _normalize;
49
- _gain;
50
- _pendingImpulse;
51
- /** Bumped per impulse request so a slow resample cannot overwrite a newer IR. */
52
- _impulseGeneration = 0;
53
- constructor(options = {}) {
54
- super();
55
- this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
56
- this._normalize = options.normalize ?? true;
57
- this._gain = Math.max(0, Math.min(4, options.gain ?? 1));
58
- this._pendingImpulse = options.impulse ?? null;
59
- this._deferSetup((context) => this._setupNodes(context));
60
- }
61
- /**
62
- * The node where audio enters this effect. Throws if the audio context is
63
- * not yet initialized.
64
- */
65
- get inputNode() {
66
- if (!this._setup) throw new Error("ConvolutionEffect not yet initialized.");
67
- return this._setup.inputGain;
68
- }
69
- /**
70
- * The node where audio exits this effect. Throws if the audio context is
71
- * not yet initialized.
72
- */
73
- get outputNode() {
74
- if (!this._setup) throw new Error("ConvolutionEffect not yet initialized.");
75
- return this._setup.outputGain;
76
- }
77
- /**
78
- * Wet (convolved) mix level, 0..1. The dry level is automatically `1 - wet`.
79
- * Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
80
- */
81
- get wet() {
82
- return this._wet;
83
- }
84
- set wet(value) {
85
- this._wet = Math.max(0, Math.min(1, value));
86
- if (this._setup) {
87
- const ctx = this._setup.wetGain.context;
88
- this._setup.wetGain.gain.setTargetAtTime(this._wet * this._gain, ctx.currentTime, .01);
89
- this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
90
- }
91
- }
92
- /**
93
- * Whether the browser normalizes the IR for equal-power loudness. Mirrors
94
- * `ConvolverNode.normalize`. Default `true`.
95
- *
96
- * Changing this at runtime re-assigns the current buffer so the new value
97
- * takes effect (a Web Audio requirement: `normalize` is only applied on
98
- * buffer assignment).
99
- */
100
- get normalize() {
101
- return this._normalize;
102
- }
103
- set normalize(value) {
104
- this._normalize = value;
105
- if (this._setup) {
106
- const { convolver } = this._setup;
107
- convolver.normalize = this._normalize;
108
- if (convolver.buffer !== null) convolver.buffer = convolver.buffer;
109
- }
110
- }
111
- /**
112
- * Makeup gain multiplier applied to the wet path. Range 0..4, default 1.
113
- * Adjusting this changes the wet-path amplitude without altering the
114
- * dry/wet balance ratio.
115
- */
116
- get gain() {
117
- return this._gain;
118
- }
119
- set gain(value) {
120
- this._gain = Math.max(0, Math.min(4, value));
121
- if (this._setup) {
122
- const ctx = this._setup.wetGain.context;
123
- this._setup.wetGain.gain.setTargetAtTime(this._wet * this._gain, ctx.currentTime, .01);
124
- }
125
- }
126
- /**
127
- * Set or replace the impulse response. Accepts a decoded `AudioBuffer`, a
128
- * `Sound` (its `audioBuffer` is used), or `null` to clear the IR (wet path
129
- * goes silent). Safe to call before the audio context is ready - the impulse
130
- * is stored and applied once nodes are created.
131
- *
132
- * **Web Audio note:** `normalize` is written to the convolver *before*
133
- * `buffer` is assigned, as required by the spec for the value to take effect.
134
- */
135
- setImpulse(ir) {
136
- const generation = ++this._impulseGeneration;
137
- if (!this._setup) {
138
- this._pendingImpulse = ir;
139
- return;
140
- }
141
- const resolved = this._resolveBuffer(ir);
142
- const rate = this._setup.convolver.context.sampleRate;
143
- if (resolved === null || resolved.sampleRate === rate) {
144
- this._applyImpulse(resolved);
145
- return;
146
- }
147
- resampleBuffer(resolved, rate).then((converted) => {
148
- if (this._impulseGeneration === generation && this._setup) this._applyImpulse(converted);
149
- });
150
- }
151
- /** Assign an IR that is known to match the context rate. */
152
- _applyImpulse(buffer) {
153
- if (!this._setup) return;
154
- const { convolver } = this._setup;
155
- convolver.normalize = this._normalize;
156
- convolver.buffer = buffer;
157
- }
158
- destroy() {
159
- this._teardown();
160
- if (this._setup) {
161
- this._setup.inputGain.disconnect();
162
- this._setup.convolver.disconnect();
163
- this._setup.dryGain.disconnect();
164
- this._setup.wetGain.disconnect();
165
- this._setup.outputGain.disconnect();
166
- this._setup = null;
167
- }
168
- }
169
- _resolveBuffer(ir) {
170
- if (ir === null) return null;
171
- if (ir instanceof Sound) return ir.audioBuffer;
172
- return ir;
173
- }
174
- _setupNodes(ctx) {
175
- const inputGain = ctx.createGain();
176
- const outputGain = ctx.createGain();
177
- const convolver = ctx.createConvolver();
178
- const dryGain = ctx.createGain();
179
- const wetGain = ctx.createGain();
180
- inputGain.gain.setValueAtTime(1, ctx.currentTime);
181
- outputGain.gain.setValueAtTime(1, ctx.currentTime);
182
- dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
183
- wetGain.gain.setValueAtTime(this._wet * this._gain, ctx.currentTime);
184
- convolver.normalize = this._normalize;
185
- inputGain.connect(dryGain);
186
- dryGain.connect(outputGain);
187
- inputGain.connect(convolver);
188
- convolver.connect(wetGain);
189
- wetGain.connect(outputGain);
190
- this._setup = {
191
- inputGain,
192
- outputGain,
193
- convolver,
194
- dryGain,
195
- wetGain
196
- };
197
- if (this._pendingImpulse !== null) {
198
- const pending = this._pendingImpulse;
199
- this._pendingImpulse = null;
200
- this.setImpulse(pending);
201
- }
202
- }
203
- };
204
-
205
- //#endregion
206
- export { ConvolutionEffect };
207
- //# sourceMappingURL=ConvolutionEffect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConvolutionEffect.js","names":[],"sources":["../../../src/effects/ConvolutionEffect.ts"],"sourcesContent":["import { AudioEffect, Sound } from '@codexo/exojs';\n\n/** Construction options for {@link ConvolutionEffect}. */\nexport interface ConvolutionEffectOptions {\n /**\n * Impulse response. Accepts a decoded `AudioBuffer` or a `Sound` (its\n * `audioBuffer` is used). If omitted the effect runs dry (passthrough) until\n * {@link ConvolutionEffect.setImpulse} is called.\n */\n impulse?: AudioBuffer | Sound;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.0.\n */\n wet?: number;\n /**\n * Maps to `ConvolverNode.normalize`. When `true` the browser applies an\n * equal-power normalization pass on the IR so different IRs play at a\n * consistent perceived loudness. Default `true` (the Web Audio spec default).\n *\n * **Note:** the Web Audio spec only respects `normalize` if it is set\n * *before* `buffer` is assigned. This class always writes `normalize` first.\n * Changing `normalize` at runtime while an IR is loaded re-assigns the\n * buffer so the new value takes effect.\n */\n normalize?: boolean;\n /**\n * Optional makeup gain multiplier applied to the wet path. Useful when the\n * IR is very quiet or very loud and `normalize` is off. Range 0..4,\n * default 1.\n */\n gain?: number;\n}\n\n/**\n * Render `buffer` at `sampleRate`. Used for impulse responses, which a\n * `ConvolverNode` only accepts at its own context's rate.\n */\nconst resampleBuffer = async (buffer: AudioBuffer, sampleRate: number): Promise<AudioBuffer> => {\n const frames = Math.max(1, Math.ceil((buffer.length / buffer.sampleRate) * sampleRate));\n const offline = new OfflineAudioContext(buffer.numberOfChannels, frames, sampleRate);\n const source = offline.createBufferSource();\n\n source.buffer = buffer;\n source.connect(offline.destination);\n source.start();\n\n return offline.startRendering();\n};\n\ninterface ConvolutionEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly convolver: ConvolverNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n}\n\n/**\n * Convolution effect that convolves the input signal with a user-supplied\n * impulse response (IR). Unlike {@link ReverbEffect}, which generates a\n * procedural noise-based IR, `ConvolutionEffect` accepts a *real* decoded IR -\n * enabling convolution reverb from acoustic-space captures, cabinet/speaker\n * simulations, telephone/pipe character filtering, and any other linear\n * time-invariant transformation.\n *\n * Pass the IR as an `AudioBuffer` (typically decoded via\n * `AudioContext.decodeAudioData`) or as a `Sound` (its `audioBuffer` is used).\n * Omitting the IR leaves `convolver.buffer` as `null`, making the wet path\n * silent and the effect act as a passthrough until {@link setImpulse} is\n * called - safe to add to a bus before an IR is available.\n *\n * Node graph:\n * ```\n * input(GainNode) → dryGain → output(GainNode)\n * input → convolver → wetGain → output\n * ```\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet × gain`.\n *\n * @example\n * ```ts\n * const hall = await loader.load(Asset.type('sound', 'hall.wav'));\n * const reverb = new ConvolutionEffect({ impulse: hall, wet: 0.6 });\n * bus.addEffect(reverb);\n * ```\n */\nexport class ConvolutionEffect extends AudioEffect {\n private _setup: ConvolutionEffectSetup | null = null;\n private _wet: number;\n private _normalize: boolean;\n private _gain: number;\n private _pendingImpulse: AudioBuffer | Sound | null;\n\n /** Bumped per impulse request so a slow resample cannot overwrite a newer IR. */\n private _impulseGeneration = 0;\n\n public constructor(options: ConvolutionEffectOptions = {}) {\n super();\n this._wet = Math.max(0, Math.min(1, options.wet ?? 1));\n this._normalize = options.normalize ?? true;\n this._gain = Math.max(0, Math.min(4, options.gain ?? 1));\n this._pendingImpulse = options.impulse ?? null;\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('ConvolutionEffect 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('ConvolutionEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n /**\n * Wet (convolved) mix level, 0..1. The dry level is automatically `1 - wet`.\n * 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 * this._gain, ctx.currentTime, 0.01);\n this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, 0.01);\n }\n }\n\n /**\n * Whether the browser normalizes the IR for equal-power loudness. Mirrors\n * `ConvolverNode.normalize`. Default `true`.\n *\n * Changing this at runtime re-assigns the current buffer so the new value\n * takes effect (a Web Audio requirement: `normalize` is only applied on\n * buffer assignment).\n */\n public get normalize(): boolean {\n return this._normalize;\n }\n\n public set normalize(value: boolean) {\n this._normalize = value;\n if (this._setup) {\n const { convolver } = this._setup;\n convolver.normalize = this._normalize;\n if (convolver.buffer !== null) {\n // Re-assign so the new normalize value takes effect immediately.\n // (The Web Audio spec only applies normalize on buffer assignment.)\n const current = convolver.buffer;\n convolver.buffer = current;\n }\n }\n }\n\n /**\n * Makeup gain multiplier applied to the wet path. Range 0..4, default 1.\n * Adjusting this changes the wet-path amplitude without altering the\n * dry/wet balance ratio.\n */\n public get gain(): number {\n return this._gain;\n }\n\n public set gain(value: number) {\n this._gain = Math.max(0, Math.min(4, value));\n if (this._setup) {\n const ctx = this._setup.wetGain.context;\n this._setup.wetGain.gain.setTargetAtTime(this._wet * this._gain, ctx.currentTime, 0.01);\n }\n }\n\n /**\n * Set or replace the impulse response. Accepts a decoded `AudioBuffer`, a\n * `Sound` (its `audioBuffer` is used), or `null` to clear the IR (wet path\n * goes silent). Safe to call before the audio context is ready - the impulse\n * is stored and applied once nodes are created.\n *\n * **Web Audio note:** `normalize` is written to the convolver *before*\n * `buffer` is assigned, as required by the spec for the value to take effect.\n */\n public setImpulse(ir: AudioBuffer | Sound | null): void {\n const generation = ++this._impulseGeneration;\n\n if (!this._setup) {\n // Store for application in _setupNodes once the context is ready.\n this._pendingImpulse = ir;\n return;\n }\n\n const resolved = this._resolveBuffer(ir);\n const rate = this._setup.convolver.context.sampleRate;\n\n if (resolved === null || resolved.sampleRate === rate) {\n this._applyImpulse(resolved);\n return;\n }\n\n // A `ConvolverNode` rejects any buffer that is not already at the\n // context's sample rate - unlike an `AudioBufferSourceNode`, which\n // resamples as it plays. Assets decoded before a live context exists land\n // at the default rate, so an IR routinely needs a conversion pass first.\n // The wet path keeps the previous IR until the new one is converted.\n void resampleBuffer(resolved, rate).then(converted => {\n // A newer impulse may have been requested while this one converted.\n if (this._impulseGeneration === generation && this._setup) {\n this._applyImpulse(converted);\n }\n });\n }\n\n /** Assign an IR that is known to match the context rate. */\n private _applyImpulse(buffer: AudioBuffer | null): void {\n if (!this._setup) return;\n\n const { convolver } = this._setup;\n\n // Web Audio requirement: set normalize BEFORE assigning buffer.\n convolver.normalize = this._normalize;\n convolver.buffer = buffer;\n }\n\n public override destroy(): void {\n this._teardown();\n if (this._setup) {\n this._setup.inputGain.disconnect();\n this._setup.convolver.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.outputGain.disconnect();\n this._setup = null;\n }\n }\n\n private _resolveBuffer(ir: AudioBuffer | Sound | null): AudioBuffer | null {\n if (ir === null) return null;\n if (ir instanceof Sound) return ir.audioBuffer;\n return ir;\n }\n\n private _setupNodes(ctx: AudioContext): void {\n const inputGain = ctx.createGain();\n const outputGain = ctx.createGain();\n const convolver = ctx.createConvolver();\n const dryGain = ctx.createGain();\n const wetGain = 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 * this._gain, ctx.currentTime);\n\n // Web Audio requirement: set normalize BEFORE assigning buffer.\n convolver.normalize = this._normalize;\n\n // Dry path: input → dryGain → output\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet path: input → convolver → wetGain → output\n inputGain.connect(convolver);\n convolver.connect(wetGain);\n wetGain.connect(outputGain);\n\n this._setup = { inputGain, outputGain, convolver, dryGain, wetGain };\n\n // Now that a context exists, route any IR supplied earlier through the\n // same path as a runtime change - including the resample it may need.\n if (this._pendingImpulse !== null) {\n const pending = this._pendingImpulse;\n this._pendingImpulse = null;\n this.setImpulse(pending);\n }\n }\n}\n"],"mappings":";;;;;;;AAqCA,MAAM,iBAAiB,OAAO,QAAqB,eAA6C;CAC9F,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,KAAM,OAAO,SAAS,OAAO,aAAc,UAAU,CAAC;CACtF,MAAM,UAAU,IAAI,oBAAoB,OAAO,kBAAkB,QAAQ,UAAU;CACnF,MAAM,SAAS,QAAQ,mBAAmB;CAE1C,OAAO,SAAS;CAChB,OAAO,QAAQ,QAAQ,WAAW;CAClC,OAAO,MAAM;CAEb,OAAO,QAAQ,eAAe;AAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,oBAAb,cAAuC,YAAY;CACjD,AAAQ,SAAwC;CAChD,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;;CAGR,AAAQ,qBAAqB;CAE7B,AAAO,YAAY,UAAoC,CAAC,GAAG;EACzD,MAAM;EACN,KAAK,OAAO,KA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AC/B,MAAM,UAAU,IAAI,WAAW;EAE/B,UAAU,KAAK,eAAe,GAAG,IAAI,WAAW;EAChD,WAAW,KAAK,eAAe,GAAG,IAAI,WAAW;EACjD,QAAQ,KAAK,eAAe,IAAI,KAAK,MAAM,IAAI,WAAW;EAC1D,QAAQ,KAAK,eAAe,KAAK,OAAO,KAAK,OAAO,IAAI,WAAW;EAGnE,UAAU,YAAY,KAAK;EAG3B,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,SAAS;EAC3B,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAE1B,KAAK,SAAS;GAAE;GAAW;GAAY;GAAW;GAAS;EAAQ;EAInE,IAAI,KAAK,oBAAoB,MAAM;GACjC,MAAM,UAAU,KAAK;GACrB,KAAK,kBAAkB;GACvB,KAAK,WAAW,OAAO;EACzB;CACF;AACF"}
@@ -1,35 +0,0 @@
1
- import { AudioEffect } from '@codexo/exojs';
2
- /** Construction options for {@link DelayEffect}. */
3
- export interface DelayEffectOptions {
4
- delaySeconds?: number;
5
- feedback?: number;
6
- wet?: number;
7
- }
8
- /**
9
- * Echo/delay effect using a Web Audio `DelayNode` with a feedback loop and
10
- * dry/wet mix. The feedback path feeds the delayed signal back into itself,
11
- * producing repeating echoes that decay naturally. Setting `feedback` near
12
- * its maximum of 0.95 produces a long, prominent tail; lower values create
13
- * a single slap-back echo.
14
- */
15
- export declare class DelayEffect extends AudioEffect {
16
- private _setup;
17
- private _delaySeconds;
18
- private _feedback;
19
- private _wet;
20
- constructor(options?: DelayEffectOptions);
21
- get inputNode(): AudioNode;
22
- get outputNode(): AudioNode;
23
- /** Delay time in seconds. Range 0..5, default 0.3. */
24
- get delaySeconds(): number;
25
- set delaySeconds(value: number);
26
- /** Fraction of the delayed signal fed back into the delay input. Range 0..0.95, default 0.4. */
27
- get feedback(): number;
28
- set feedback(value: number);
29
- /** Wet (delayed) mix level, 0..1. The dry level is automatically `1 - wet`. Default 0.5. */
30
- get wet(): number;
31
- set wet(value: number);
32
- destroy(): void;
33
- private _setupNodes;
34
- }
35
- //# sourceMappingURL=DelayEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DelayEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/DelayEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,oDAAoD;AACpD,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAWD;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,WAAW;IAC1C,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,IAAI,CAAS;IAErB,YAAmB,OAAO,GAAE,kBAAuB,EAMlD;IAED,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED,IAAW,UAAU,IAAI,SAAS,CAGjC;IAED,sDAAsD;IACtD,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED,IAAW,YAAY,CAAC,KAAK,EAAE,MAAM,EAKpC;IAED,gGAAgG;IAChG,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,IAAW,QAAQ,CAAC,KAAK,EAAE,MAAM,EAKhC;IAED,4FAA4F;IAC5F,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAO3B;IAEe,OAAO,IAAI,IAAI,CAW9B;IAED,OAAO,CAAC,WAAW;CA8BpB"}
@@ -1,104 +0,0 @@
1
- import { AudioEffect } from "@codexo/exojs";
2
-
3
- //#region src/effects/DelayEffect.ts
4
- /**
5
- * Echo/delay effect using a Web Audio `DelayNode` with a feedback loop and
6
- * dry/wet mix. The feedback path feeds the delayed signal back into itself,
7
- * producing repeating echoes that decay naturally. Setting `feedback` near
8
- * its maximum of 0.95 produces a long, prominent tail; lower values create
9
- * a single slap-back echo.
10
- */
11
- var DelayEffect = class extends AudioEffect {
12
- _setup = null;
13
- _delaySeconds;
14
- _feedback;
15
- _wet;
16
- constructor(options = {}) {
17
- super();
18
- this._delaySeconds = Math.max(0, Math.min(5, options.delaySeconds ?? .3));
19
- this._feedback = Math.max(0, Math.min(.95, options.feedback ?? .4));
20
- this._wet = Math.max(0, Math.min(1, options.wet ?? .5));
21
- this._deferSetup((context) => this._setupNodes(context));
22
- }
23
- get inputNode() {
24
- if (!this._setup) throw new Error("DelayEffect not yet initialized.");
25
- return this._setup.inputGain;
26
- }
27
- get outputNode() {
28
- if (!this._setup) throw new Error("DelayEffect not yet initialized.");
29
- return this._setup.outputGain;
30
- }
31
- /** Delay time in seconds. Range 0..5, default 0.3. */
32
- get delaySeconds() {
33
- return this._delaySeconds;
34
- }
35
- set delaySeconds(value) {
36
- this._delaySeconds = Math.max(0, Math.min(5, value));
37
- if (this._setup) this._setup.delayNode.delayTime.setTargetAtTime(this._delaySeconds, this._setup.delayNode.context.currentTime, .01);
38
- }
39
- /** Fraction of the delayed signal fed back into the delay input. Range 0..0.95, default 0.4. */
40
- get feedback() {
41
- return this._feedback;
42
- }
43
- set feedback(value) {
44
- this._feedback = Math.max(0, Math.min(.95, value));
45
- if (this._setup) this._setup.feedbackGain.gain.setTargetAtTime(this._feedback, this._setup.feedbackGain.context.currentTime, .01);
46
- }
47
- /** Wet (delayed) mix level, 0..1. The dry level is automatically `1 - wet`. Default 0.5. */
48
- get wet() {
49
- return this._wet;
50
- }
51
- set wet(value) {
52
- this._wet = Math.max(0, Math.min(1, value));
53
- if (this._setup) {
54
- const ctx = this._setup.wetGain.context;
55
- this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
56
- this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
57
- }
58
- }
59
- destroy() {
60
- this._teardown();
61
- if (this._setup) {
62
- this._setup.inputGain.disconnect();
63
- this._setup.delayNode.disconnect();
64
- this._setup.feedbackGain.disconnect();
65
- this._setup.dryGain.disconnect();
66
- this._setup.wetGain.disconnect();
67
- this._setup.outputGain.disconnect();
68
- this._setup = null;
69
- }
70
- }
71
- _setupNodes(ctx) {
72
- const inputGain = ctx.createGain();
73
- const outputGain = ctx.createGain();
74
- const delayNode = ctx.createDelay(5);
75
- const feedbackGain = ctx.createGain();
76
- const dryGain = ctx.createGain();
77
- const wetGain = ctx.createGain();
78
- inputGain.gain.setValueAtTime(1, ctx.currentTime);
79
- outputGain.gain.setValueAtTime(1, ctx.currentTime);
80
- delayNode.delayTime.setValueAtTime(this._delaySeconds, ctx.currentTime);
81
- feedbackGain.gain.setValueAtTime(this._feedback, ctx.currentTime);
82
- dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
83
- wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
84
- inputGain.connect(dryGain);
85
- dryGain.connect(outputGain);
86
- inputGain.connect(delayNode);
87
- delayNode.connect(wetGain);
88
- wetGain.connect(outputGain);
89
- delayNode.connect(feedbackGain);
90
- feedbackGain.connect(delayNode);
91
- this._setup = {
92
- inputGain,
93
- outputGain,
94
- delayNode,
95
- feedbackGain,
96
- dryGain,
97
- wetGain
98
- };
99
- }
100
- };
101
-
102
- //#endregion
103
- export { DelayEffect };
104
- //# sourceMappingURL=DelayEffect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DelayEffect.js","names":[],"sources":["../../../src/effects/DelayEffect.ts"],"sourcesContent":["import { AudioEffect } from '@codexo/exojs';\n\n/** Construction options for {@link DelayEffect}. */\nexport interface DelayEffectOptions {\n delaySeconds?: number;\n feedback?: number;\n wet?: number;\n}\n\ninterface DelayEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly delayNode: DelayNode;\n readonly feedbackGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n}\n\n/**\n * Echo/delay effect using a Web Audio `DelayNode` with a feedback loop and\n * dry/wet mix. The feedback path feeds the delayed signal back into itself,\n * producing repeating echoes that decay naturally. Setting `feedback` near\n * its maximum of 0.95 produces a long, prominent tail; lower values create\n * a single slap-back echo.\n */\nexport class DelayEffect extends AudioEffect {\n private _setup: DelayEffectSetup | null = null;\n private _delaySeconds: number;\n private _feedback: number;\n private _wet: number;\n\n public constructor(options: DelayEffectOptions = {}) {\n super();\n this._delaySeconds = Math.max(0, Math.min(5, options.delaySeconds ?? 0.3));\n this._feedback = Math.max(0, Math.min(0.95, options.feedback ?? 0.4));\n this._wet = Math.max(0, Math.min(1, options.wet ?? 0.5));\n this._deferSetup(context => this._setupNodes(context));\n }\n\n public get inputNode(): AudioNode {\n if (!this._setup) throw new Error('DelayEffect not yet initialized.');\n return this._setup.inputGain;\n }\n\n public get outputNode(): AudioNode {\n if (!this._setup) throw new Error('DelayEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n /** Delay time in seconds. Range 0..5, default 0.3. */\n public get delaySeconds(): number {\n return this._delaySeconds;\n }\n\n public set delaySeconds(value: number) {\n this._delaySeconds = Math.max(0, Math.min(5, value));\n if (this._setup) {\n this._setup.delayNode.delayTime.setTargetAtTime(this._delaySeconds, this._setup.delayNode.context.currentTime, 0.01);\n }\n }\n\n /** Fraction of the delayed signal fed back into the delay input. Range 0..0.95, default 0.4. */\n public get feedback(): number {\n return this._feedback;\n }\n\n public set feedback(value: number) {\n this._feedback = Math.max(0, Math.min(0.95, value));\n if (this._setup) {\n this._setup.feedbackGain.gain.setTargetAtTime(this._feedback, this._setup.feedbackGain.context.currentTime, 0.01);\n }\n }\n\n /** Wet (delayed) mix level, 0..1. The dry level is automatically `1 - wet`. Default 0.5. */\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.inputGain.disconnect();\n this._setup.delayNode.disconnect();\n this._setup.feedbackGain.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.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 delayNode = ctx.createDelay(5);\n const feedbackGain = ctx.createGain();\n const dryGain = ctx.createGain();\n const wetGain = ctx.createGain();\n\n inputGain.gain.setValueAtTime(1, ctx.currentTime);\n outputGain.gain.setValueAtTime(1, ctx.currentTime);\n delayNode.delayTime.setValueAtTime(this._delaySeconds, ctx.currentTime);\n feedbackGain.gain.setValueAtTime(this._feedback, ctx.currentTime);\n dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);\n wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);\n\n // Dry path: input → dryGain → output\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet path: input → delay → wetGain → output\n inputGain.connect(delayNode);\n delayNode.connect(wetGain);\n wetGain.connect(outputGain);\n\n // Feedback loop: delay → feedbackGain → delay\n delayNode.connect(feedbackGain);\n feedbackGain.connect(delayNode);\n\n this._setup = { inputGain, outputGain, delayNode, feedbackGain, dryGain, wetGain };\n }\n}\n"],"mappings":";;;;;;;;;;AAyBA,IAAa,cAAb,cAAiC,YAAY;CAC3C,AAAQ,SAAkC;CAC1C,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAA8B,CAAC,GAAG;EACnD,MAAM;EACN,KAAK,gBAAgB,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,gBAAgB,EAAG,CAAC;EACzE,KAAK,YAAY,KAAK,IAAI,GAAG,KAAK,IAAI,KAAM,QAAQ,YAAY,EA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,KAAK,UAAU;EACf,IAAI,KAAK,QAAQ;GACf,KAAK,OAAO,UAAU,WAAW;GACjC,KAAK,OAAO,UAAU,WAAW;GACjC,KAAK,OAAO,aAAa,WAAW;GACpC,KAAK,OAAO,QAAQ,WAAW;GAC/B,KAAK,OAAO,QAAQ,WAAW;GAC/B,KAAK,OAAO,WAAW,WAAW;GAClC,KAAK,SAAS;EAChB;CACF;CAEA,AAAQ,YAAY,KAAyB;EAC3C,MAAM,YAAY,IAAI,WAAW;EACjC,MAAM,aAAa,IAAI,WAAW;EAClC,MAAM,YAAY,IAAI,YAAY,CAAC;EACnC,MAAM,eAAe,IAAI,WAAW;EACpC,MAAM,UAAU,IAAI,WAAW;EAC/B,MAAM,UAAU,IAAI,WAAW;EAE/B,UAAU,KAAK,eAAe,GAAG,IAAI,WAAW;EAChD,WAAW,KAAK,eAAe,GAAG,IAAI,WAAW;EACjD,UAAU,UAAU,eAAe,KAAK,eAAe,IAAI,WAAW;EACtE,aAAa,KAAK,eAAe,KAAK,WAAW,IAAI,WAAW;EAChE,QAAQ,KAAK,eAAe,IAAI,KAAK,MAAM,IAAI,WAAW;EAC1D,QAAQ,KAAK,eAAe,KAAK,MAAM,IAAI,WAAW;EAGtD,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,SAAS;EAC3B,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,YAAY;EAC9B,aAAa,QAAQ,SAAS;EAE9B,KAAK,SAAS;GAAE;GAAW;GAAY;GAAW;GAAc;GAAS;EAAQ;CACnF;AACF"}
@@ -1,116 +0,0 @@
1
- import { AudioEffect } from '@codexo/exojs';
2
- /** Construction options for {@link DistortionEffect}. */
3
- export interface DistortionEffectOptions {
4
- /**
5
- * Drive amount, 0..1, default 0.4. At 0 the wet path is transparent; higher
6
- * values blend in a steeper tanh soft-clip, up to a near hard clip at 1.
7
- */
8
- drive?: number;
9
- /**
10
- * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.0.
11
- */
12
- wet?: number;
13
- /**
14
- * Oversampling mode applied by the `WaveShaperNode`. Higher oversampling
15
- * reduces aliasing artifacts at the cost of extra CPU. One of `'none'`,
16
- * `'2x'`, or `'4x'`. Default `'2x'`.
17
- */
18
- oversample?: OverSampleType;
19
- /**
20
- * Tone control: cutoff of a post-distortion low-pass filter on the wet path.
21
- * Mapped logarithmically from 100 Hz (tone=0, fully dark) to 20 kHz
22
- * (tone=1, fully open). Range 0..1, default 1.
23
- */
24
- tone?: number;
25
- }
26
- /**
27
- * Distortion effect built from native Web Audio nodes - no worklet required.
28
- *
29
- * The input signal is split into a dry path and a wet path. The wet path runs
30
- * through a `WaveShaperNode` loaded with a tanh-based soft-clip curve, then
31
- * through a `BiquadFilterNode` (lowpass) acting as a tone control, before
32
- * being mixed back with the dry signal. The wave-shaper curve is rebuilt any
33
- * time `drive` changes. Oversampling is delegated directly to
34
- * `WaveShaperNode.oversample`.
35
- *
36
- * Node graph:
37
- * ```
38
- * input(GainNode) ──── dryGain ─────────────────────────── output(GainNode)
39
- * input ──── waveShaper ── toneFilter ── wetGain ── output
40
- * ```
41
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
42
- *
43
- * @example
44
- * ```ts
45
- * const dist = new DistortionEffect({ drive: 0.7, wet: 0.9, tone: 0.6 });
46
- * bus.addEffect(dist);
47
- *
48
- * // Soften the drive at runtime:
49
- * dist.drive = 0.3;
50
- *
51
- * // Open the tone filter fully:
52
- * dist.tone = 1;
53
- * ```
54
- */
55
- export declare class DistortionEffect extends AudioEffect {
56
- private _setup;
57
- private _drive;
58
- private _wet;
59
- private _oversample;
60
- private _tone;
61
- constructor(options?: DistortionEffectOptions);
62
- /**
63
- * The node where audio enters this effect. Throws if the audio context is
64
- * not yet initialized.
65
- */
66
- get inputNode(): AudioNode;
67
- /**
68
- * The node where audio exits this effect. Throws if the audio context is
69
- * not yet initialized.
70
- */
71
- get outputNode(): AudioNode;
72
- /**
73
- * Drive amount, 0..1: 0 is transparent, 1 a near hard clip. Default 0.4.
74
- * Changing this rebuilds the wave-shaper curve immediately (sample-accurate
75
- * on the next render quantum).
76
- */
77
- get drive(): number;
78
- set drive(value: number);
79
- /**
80
- * Wet (distorted) mix level, 0..1. The dry level is automatically `1 - wet`.
81
- * Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
82
- */
83
- get wet(): number;
84
- set wet(value: number);
85
- /**
86
- * Oversampling mode for the `WaveShaperNode`. One of `'none'`, `'2x'`, or
87
- * `'4x'`. Higher values reduce aliasing but increase CPU usage. Default `'2x'`.
88
- */
89
- get oversample(): OverSampleType;
90
- set oversample(value: OverSampleType);
91
- /**
92
- * Tone control: low-pass cutoff on the wet path. 0 = fully dark (~100 Hz),
93
- * 1 = fully open (~20 kHz). Mapped logarithmically. Default 1.
94
- * Changes are ramped smoothly via `setTargetAtTime`.
95
- */
96
- get tone(): number;
97
- set tone(value: number);
98
- destroy(): void;
99
- /**
100
- * Build a 256-point curve for the given drive (0..1): the identity blended
101
- * with a soft clip `tanh(x * a) / tanh(a)`, `a = drive * 400 + 1`, by `drive`.
102
- *
103
- * The blend is what makes drive=0 exactly transparent. A bare soft clip is
104
- * never linear (at a = 1 its small-signal gain is 1/tanh(1) ≈ 1.31), and
105
- * special-casing 0 would make the sound jump at the first step above it.
106
- * Both curves run from -1 to 1 and rise monotonically, so the blend does too.
107
- */
108
- private static _buildCurve;
109
- /**
110
- * Map tone (0..1) to a low-pass cutoff frequency in Hz.
111
- * Logarithmic scale: 100 Hz at tone=0, 20 000 Hz at tone=1.
112
- */
113
- private static _toneToFrequency;
114
- private _setupNodes;
115
- }
116
- //# sourceMappingURL=DistortionEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DistortionEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/DistortionEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,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