@codexo/exojs-audio-fx 0.19.0 → 0.19.1

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 (97) hide show
  1. package/dist/esm/AudioAnalyser.d.ts +6 -8
  2. package/dist/esm/AudioAnalyser.d.ts.map +1 -1
  3. package/dist/esm/AudioAnalyser.js +6 -80
  4. package/dist/esm/AudioAnalyser.js.map +1 -1
  5. package/dist/esm/AudioTap.d.ts +33 -0
  6. package/dist/esm/AudioTap.d.ts.map +1 -0
  7. package/dist/esm/AudioTap.js +126 -0
  8. package/dist/esm/AudioTap.js.map +1 -0
  9. package/dist/esm/BeatDetector.d.ts +14 -9
  10. package/dist/esm/BeatDetector.d.ts.map +1 -1
  11. package/dist/esm/BeatDetector.js +30 -84
  12. package/dist/esm/BeatDetector.js.map +1 -1
  13. package/dist/esm/PcmStreamSource.d.ts +6 -1
  14. package/dist/esm/PcmStreamSource.d.ts.map +1 -1
  15. package/dist/esm/PcmStreamSource.js +6 -1
  16. package/dist/esm/PcmStreamSource.js.map +1 -1
  17. package/dist/esm/ReadyGate.d.ts +25 -0
  18. package/dist/esm/ReadyGate.d.ts.map +1 -0
  19. package/dist/esm/ReadyGate.js +69 -0
  20. package/dist/esm/ReadyGate.js.map +1 -0
  21. package/dist/esm/effects/AutoWahEffect.d.ts +0 -1
  22. package/dist/esm/effects/AutoWahEffect.d.ts.map +1 -1
  23. package/dist/esm/effects/AutoWahEffect.js +3 -8
  24. package/dist/esm/effects/AutoWahEffect.js.map +1 -1
  25. package/dist/esm/effects/ChorusEffect.d.ts +11 -5
  26. package/dist/esm/effects/ChorusEffect.d.ts.map +1 -1
  27. package/dist/esm/effects/ChorusEffect.js +19 -16
  28. package/dist/esm/effects/ChorusEffect.js.map +1 -1
  29. package/dist/esm/effects/CompressorEffect.d.ts +0 -1
  30. package/dist/esm/effects/CompressorEffect.d.ts.map +1 -1
  31. package/dist/esm/effects/CompressorEffect.js +3 -8
  32. package/dist/esm/effects/CompressorEffect.js.map +1 -1
  33. package/dist/esm/effects/ConvolutionEffect.d.ts +0 -1
  34. package/dist/esm/effects/ConvolutionEffect.d.ts.map +1 -1
  35. package/dist/esm/effects/ConvolutionEffect.js +3 -8
  36. package/dist/esm/effects/ConvolutionEffect.js.map +1 -1
  37. package/dist/esm/effects/DelayEffect.d.ts +0 -1
  38. package/dist/esm/effects/DelayEffect.d.ts.map +1 -1
  39. package/dist/esm/effects/DelayEffect.js +3 -8
  40. package/dist/esm/effects/DelayEffect.js.map +1 -1
  41. package/dist/esm/effects/DistortionEffect.d.ts +9 -13
  42. package/dist/esm/effects/DistortionEffect.d.ts.map +1 -1
  43. package/dist/esm/effects/DistortionEffect.js +11 -16
  44. package/dist/esm/effects/DistortionEffect.js.map +1 -1
  45. package/dist/esm/effects/DuckingEffect.d.ts.map +1 -1
  46. package/dist/esm/effects/DuckingEffect.js +1 -7
  47. package/dist/esm/effects/DuckingEffect.js.map +1 -1
  48. package/dist/esm/effects/EqualizerEffect.d.ts +0 -1
  49. package/dist/esm/effects/EqualizerEffect.d.ts.map +1 -1
  50. package/dist/esm/effects/EqualizerEffect.js +3 -8
  51. package/dist/esm/effects/EqualizerEffect.js.map +1 -1
  52. package/dist/esm/effects/FlangerEffect.d.ts +12 -4
  53. package/dist/esm/effects/FlangerEffect.d.ts.map +1 -1
  54. package/dist/esm/effects/FlangerEffect.js +17 -15
  55. package/dist/esm/effects/FlangerEffect.js.map +1 -1
  56. package/dist/esm/effects/LimiterEffect.d.ts +12 -8
  57. package/dist/esm/effects/LimiterEffect.d.ts.map +1 -1
  58. package/dist/esm/effects/LimiterEffect.js +12 -13
  59. package/dist/esm/effects/LimiterEffect.js.map +1 -1
  60. package/dist/esm/effects/PhaserEffect.d.ts +0 -1
  61. package/dist/esm/effects/PhaserEffect.d.ts.map +1 -1
  62. package/dist/esm/effects/PhaserEffect.js +3 -8
  63. package/dist/esm/effects/PhaserEffect.js.map +1 -1
  64. package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -1
  65. package/dist/esm/effects/PingPongDelayEffect.d.ts.map +1 -1
  66. package/dist/esm/effects/PingPongDelayEffect.js +3 -8
  67. package/dist/esm/effects/PingPongDelayEffect.js.map +1 -1
  68. package/dist/esm/effects/ReverbEffect.d.ts +0 -1
  69. package/dist/esm/effects/ReverbEffect.d.ts.map +1 -1
  70. package/dist/esm/effects/ReverbEffect.js +3 -8
  71. package/dist/esm/effects/ReverbEffect.js.map +1 -1
  72. package/dist/esm/effects/RingModulatorEffect.d.ts +0 -1
  73. package/dist/esm/effects/RingModulatorEffect.d.ts.map +1 -1
  74. package/dist/esm/effects/RingModulatorEffect.js +3 -8
  75. package/dist/esm/effects/RingModulatorEffect.js.map +1 -1
  76. package/dist/esm/effects/TremoloEffect.d.ts +12 -15
  77. package/dist/esm/effects/TremoloEffect.d.ts.map +1 -1
  78. package/dist/esm/effects/TremoloEffect.js +15 -20
  79. package/dist/esm/effects/TremoloEffect.js.map +1 -1
  80. package/dist/esm/effects/VocoderEffect.d.ts.map +1 -1
  81. package/dist/esm/effects/VocoderEffect.js +2 -7
  82. package/dist/esm/effects/VocoderEffect.js.map +1 -1
  83. package/dist/esm/worklets/beat-detector.worklet.js +1 -1
  84. package/dist/esm/worklets/beat-detector.worklet.js.map +1 -1
  85. package/dist/esm/worklets/bit-crusher.worklet.js +1 -1
  86. package/dist/esm/worklets/bit-crusher.worklet.js.map +1 -1
  87. package/dist/esm/worklets/disposable-processor.d.ts +13 -0
  88. package/dist/esm/worklets/disposable-processor.d.ts.map +1 -0
  89. package/dist/esm/worklets/ducking.worklet.js +1 -1
  90. package/dist/esm/worklets/ducking.worklet.js.map +1 -1
  91. package/dist/esm/worklets/granular.worklet.js +1 -1
  92. package/dist/esm/worklets/granular.worklet.js.map +1 -1
  93. package/dist/esm/worklets/pitch-shift.worklet.js +1 -1
  94. package/dist/esm/worklets/pitch-shift.worklet.js.map +1 -1
  95. package/dist/esm/worklets/vocoder.worklet.js +1 -1
  96. package/dist/esm/worklets/vocoder.worklet.js.map +1 -1
  97. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"AutoWahEffect.js","names":[],"sources":["../../../src/effects/AutoWahEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link AutoWahEffect}. */\nexport interface AutoWahEffectOptions {\n /**\n * Centre frequency of the wah bandpass filter in Hz. The envelope control\n * signal sweeps the filter upward from this base. Range 50..2000, default 200.\n */\n baseFrequency?: number;\n /**\n * Envelope sensitivity: Hz of filter-frequency sweep added per unit of\n * rectified envelope amplitude. At full signal amplitude the filter shifts up\n * by this amount above `baseFrequency`. Range 0..6000, default 3000.\n */\n sensitivity?: number;\n /**\n * Q (resonance) of the bandpass wah filter. Higher values produce a narrower,\n * more pronounced peak. Range 0.1..20, default 4.\n */\n q?: number;\n /**\n * Envelope smoothing time constant in milliseconds. Longer values make the\n * wah react slowly (legato); shorter values produce a snappier attack\n * (percussive). Translated to the smoothing lowpass cutoff as\n * `1000 / (2π × responseMs)` Hz. Range 1..500, default 30.\n */\n responseMs?: number;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 0.7.\n */\n wet?: number;\n}\n\ninterface AutoWahEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly sensitivityGain: GainNode;\n readonly wahFilter: BiquadFilterNode;\n readonly smoothingLowpass: BiquadFilterNode;\n readonly rectifier: WaveShaperNode;\n}\n\n/**\n * Auto-wah effect that uses an amplitude envelope follower to modulate a\n * bandpass filter, creating the characteristic \"wah\" sweep driven by the\n * loudness of the input signal.\n *\n * The envelope follower is built entirely from native Web Audio nodes - no\n * `ScriptProcessor` or `AudioWorklet` required:\n *\n * 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),\n * converting the AC audio signal to a unipolar amplitude proxy.\n * 2. A `BiquadFilterNode` (lowpass) smooths the rectified signal. The cutoff is\n * derived from `responseMs` to control attack/release speed.\n * 3. A `GainNode` scales the smoothed envelope by `sensitivity` (Hz/unit) and\n * connects its output directly to the wah filter's `frequency` `AudioParam`,\n * sweeping the filter centre upward with input loudness.\n *\n * Node graph:\n * ```\n * inputGain ─┬─ dryGain ─────────────────────────────┐\n * │ ├── outputGain\n * └─ wahFilter(bandpass) ─── wetGain ──────┘\n *\n * Envelope (control) path - parallel off inputGain, sums into wahFilter.frequency:\n * inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)\n * → sensitivityGain → wahFilter.frequency (AudioParam)\n * ```\n *\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.\n *\n * @example\n * ```ts\n * const wah = new AutoWahEffect({ baseFrequency: 300, sensitivity: 2500, wet: 0.8 });\n * bus.addEffect(wah);\n * ```\n */\nexport class AutoWahEffect extends AudioEffect {\n private _setup: AutoWahEffectSetup | null = null;\n private _baseFrequency: number;\n private _sensitivity: number;\n private _q: number;\n private _responseMs: number;\n private _wet: number;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\n\n public constructor(options: AutoWahEffectOptions = {}) {\n super();\n this._baseFrequency = Math.max(50, Math.min(2000, options.baseFrequency ?? 200));\n this._sensitivity = Math.max(0, Math.min(6000, options.sensitivity ?? 3000));\n this._q = Math.max(0.1, Math.min(20, options.q ?? 4));\n this._responseMs = Math.max(1, Math.min(500, options.responseMs ?? 30));\n this._wet = Math.max(0, Math.min(1, options.wet ?? 0.7));\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('AutoWahEffect 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('AutoWahEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n // ---------------------------------------------------------------------------\n // Getters / setters\n // ---------------------------------------------------------------------------\n\n /**\n * Centre frequency of the wah filter in Hz. Range 50..2000, default 200.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get baseFrequency(): number {\n return this._baseFrequency;\n }\n\n public set baseFrequency(value: number) {\n this._baseFrequency = Math.max(50, Math.min(2000, value));\n if (this._setup) {\n this._setup.wahFilter.frequency.setTargetAtTime(this._baseFrequency, this._setup.wahFilter.context.currentTime, 0.01);\n }\n }\n\n /**\n * Envelope sensitivity in Hz/unit: the maximum filter sweep above\n * `baseFrequency` when input is at full amplitude. Range 0..6000, default 3000.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get sensitivity(): number {\n return this._sensitivity;\n }\n\n public set sensitivity(value: number) {\n this._sensitivity = Math.max(0, Math.min(6000, value));\n if (this._setup) {\n this._setup.sensitivityGain.gain.setTargetAtTime(this._sensitivity, this._setup.sensitivityGain.context.currentTime, 0.01);\n }\n }\n\n /**\n * Q (resonance) of the bandpass wah filter. Range 0.1..20, default 4.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get q(): number {\n return this._q;\n }\n\n public set q(value: number) {\n this._q = Math.max(0.1, Math.min(20, value));\n if (this._setup) {\n this._setup.wahFilter.Q.setTargetAtTime(this._q, this._setup.wahFilter.context.currentTime, 0.01);\n }\n }\n\n /**\n * Envelope smoothing time constant in milliseconds. Range 1..500, default 30.\n * Updating this adjusts the smoothing lowpass cutoff immediately via\n * `setTargetAtTime`.\n */\n public get responseMs(): number {\n return this._responseMs;\n }\n\n public set responseMs(value: number) {\n this._responseMs = Math.max(1, Math.min(500, value));\n if (this._setup) {\n this._setup.smoothingLowpass.frequency.setTargetAtTime(this._smoothingCutoff(), this._setup.smoothingLowpass.context.currentTime, 0.01);\n }\n }\n\n /**\n * Wet (wah-filtered) mix level, 0..1. The dry level is automatically\n * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 0.7.\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 // ---------------------------------------------------------------------------\n // Lifecycle\n // ---------------------------------------------------------------------------\n\n public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n if (this._setup) {\n this._setup.inputGain.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.sensitivityGain.disconnect();\n this._setup.wahFilter.disconnect();\n this._setup.smoothingLowpass.disconnect();\n this._setup.rectifier.disconnect();\n this._setup.outputGain.disconnect();\n this._setup = null;\n }\n }\n\n // ---------------------------------------------------------------------------\n // Private\n // ---------------------------------------------------------------------------\n\n /** Converts `responseMs` to a lowpass cutoff frequency using f = 1/(2π×τ). */\n private _smoothingCutoff(): number {\n return 1000 / (2 * Math.PI * this._responseMs);\n }\n\n /**\n * Builds a 256-point `Float32Array` curve approximating the full-wave\n * rectifier `f(x) = |x|` for use with `WaveShaperNode`.\n */\n private static _makeRectifierCurve(): Float32Array<ArrayBuffer> {\n const n = 256;\n const curve = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const x = (i * 2) / (n - 1) - 1; // maps index to -1..1\n curve[i] = Math.abs(x);\n }\n return curve;\n }\n\n private _setupNodes(ctx: AudioContext): void {\n // Audio-path gain nodes (createGain order: 0=inputGain, 1=outputGain,\n // 2=dryGain, 3=wetGain, 4=sensitivityGain).\n const inputGain = ctx.createGain();\n const outputGain = ctx.createGain();\n const dryGain = ctx.createGain();\n const wetGain = ctx.createGain();\n const sensitivityGain = ctx.createGain();\n\n // Wah filter (audio path) and smoothing filter (envelope control path)\n // (createBiquadFilter order: 0=wahFilter, 1=smoothingLowpass).\n const wahFilter = ctx.createBiquadFilter();\n const smoothingLowpass = ctx.createBiquadFilter();\n\n // Full-wave rectifier for the envelope follower.\n const rectifier = ctx.createWaveShaper();\n\n // ── Initialize values ────────────────────────────────────────────────────\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 sensitivityGain.gain.setValueAtTime(this._sensitivity, ctx.currentTime);\n\n // Wah bandpass filter: base frequency and Q; envelope signal adds on top.\n wahFilter.type = 'bandpass';\n wahFilter.frequency.setValueAtTime(this._baseFrequency, ctx.currentTime);\n wahFilter.Q.setValueAtTime(this._q, ctx.currentTime);\n\n // Rectifier: full-wave |x| curve; 4× oversampling for accuracy.\n rectifier.curve = AutoWahEffect._makeRectifierCurve();\n rectifier.oversample = '4x';\n\n // Smoothing lowpass: cutoff derived from responseMs; low Q for no ringing.\n smoothingLowpass.type = 'lowpass';\n smoothingLowpass.frequency.setValueAtTime(this._smoothingCutoff(), ctx.currentTime);\n smoothingLowpass.Q.setValueAtTime(0.5, ctx.currentTime);\n\n // ── Wiring ───────────────────────────────────────────────────────────────\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet (audio) path: inputGain → wahFilter → wetGain → outputGain\n inputGain.connect(wahFilter);\n wahFilter.connect(wetGain);\n wetGain.connect(outputGain);\n\n // Envelope (control) path - parallel off inputGain, drives wahFilter.frequency.\n // The rectified+smoothed signal is scaled by sensitivityGain and summed into\n // the wahFilter frequency AudioParam, sweeping the filter with input loudness.\n inputGain.connect(rectifier);\n rectifier.connect(smoothingLowpass);\n smoothingLowpass.connect(sensitivityGain);\n sensitivityGain.connect(wahFilter.frequency as unknown as Audio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E,UAAU,OAAO;EACjB,UAAU,UAAU,eAAe,KAAK,gBAAgB,IAAI,WAAW;EACvE,UAAU,EAAE,eAAe,KAAK,IAAI,IAAI,WAAW;EAGnD,UAAU,QAAQ,cAAc,oBAAoB;EACpD,UAAU,aAAa;EAGvB,iBAAiB,OAAO;EACxB,iBAAiB,UAAU,eAAe,KAAK,iBAAiB,GAAG,IAAI,WAAW;EAClF,iBAAiB,EAAE,eAAe,IAAK,IAAI,WAAW;EAKtD,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,SAAS;EAC3B,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAK1B,UAAU,QAAQ,SAAS;EAC3B,UAAU,QAAQ,gBAAgB;EAClC,iBAAiB,QAAQ,eAAe;EACxC,gBAAgB,QAAQ,UAAU,SAAiC;EAEnE,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAiB;GAAW;GAAkB;EAAU;CACnH;AACF"}
1
+ {"version":3,"file":"AutoWahEffect.js","names":[],"sources":["../../../src/effects/AutoWahEffect.ts"],"sourcesContent":["import { AudioEffect } from '@codexo/exojs';\n\n/** Construction options for {@link AutoWahEffect}. */\nexport interface AutoWahEffectOptions {\n /**\n * Centre frequency of the wah bandpass filter in Hz. The envelope control\n * signal sweeps the filter upward from this base. Range 50..2000, default 200.\n */\n baseFrequency?: number;\n /**\n * Envelope sensitivity: Hz of filter-frequency sweep added per unit of\n * rectified envelope amplitude. At full signal amplitude the filter shifts up\n * by this amount above `baseFrequency`. Range 0..6000, default 3000.\n */\n sensitivity?: number;\n /**\n * Q (resonance) of the bandpass wah filter. Higher values produce a narrower,\n * more pronounced peak. Range 0.1..20, default 4.\n */\n q?: number;\n /**\n * Envelope smoothing time constant in milliseconds. Longer values make the\n * wah react slowly (legato); shorter values produce a snappier attack\n * (percussive). Translated to the smoothing lowpass cutoff as\n * `1000 / (2π × responseMs)` Hz. Range 1..500, default 30.\n */\n responseMs?: number;\n /**\n * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 0.7.\n */\n wet?: number;\n}\n\ninterface AutoWahEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly sensitivityGain: GainNode;\n readonly wahFilter: BiquadFilterNode;\n readonly smoothingLowpass: BiquadFilterNode;\n readonly rectifier: WaveShaperNode;\n}\n\n/**\n * Auto-wah effect that uses an amplitude envelope follower to modulate a\n * bandpass filter, creating the characteristic \"wah\" sweep driven by the\n * loudness of the input signal.\n *\n * The envelope follower is built entirely from native Web Audio nodes - no\n * `ScriptProcessor` or `AudioWorklet` required:\n *\n * 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),\n * converting the AC audio signal to a unipolar amplitude proxy.\n * 2. A `BiquadFilterNode` (lowpass) smooths the rectified signal. The cutoff is\n * derived from `responseMs` to control attack/release speed.\n * 3. A `GainNode` scales the smoothed envelope by `sensitivity` (Hz/unit) and\n * connects its output directly to the wah filter's `frequency` `AudioParam`,\n * sweeping the filter centre upward with input loudness.\n *\n * Node graph:\n * ```\n * inputGain ─┬─ dryGain ─────────────────────────────┐\n * │ ├── outputGain\n * └─ wahFilter(bandpass) ─── wetGain ──────┘\n *\n * Envelope (control) path - parallel off inputGain, sums into wahFilter.frequency:\n * inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)\n * → sensitivityGain → wahFilter.frequency (AudioParam)\n * ```\n *\n * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.\n *\n * @example\n * ```ts\n * const wah = new AutoWahEffect({ baseFrequency: 300, sensitivity: 2500, wet: 0.8 });\n * bus.addEffect(wah);\n * ```\n */\nexport class AutoWahEffect extends AudioEffect {\n private _setup: AutoWahEffectSetup | null = null;\n private _baseFrequency: number;\n private _sensitivity: number;\n private _q: number;\n private _responseMs: number;\n private _wet: number;\n\n public constructor(options: AutoWahEffectOptions = {}) {\n super();\n this._baseFrequency = Math.max(50, Math.min(2000, options.baseFrequency ?? 200));\n this._sensitivity = Math.max(0, Math.min(6000, options.sensitivity ?? 3000));\n this._q = Math.max(0.1, Math.min(20, options.q ?? 4));\n this._responseMs = Math.max(1, Math.min(500, options.responseMs ?? 30));\n this._wet = Math.max(0, Math.min(1, options.wet ?? 0.7));\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('AutoWahEffect 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('AutoWahEffect not yet initialized.');\n return this._setup.outputGain;\n }\n\n // ---------------------------------------------------------------------------\n // Getters / setters\n // ---------------------------------------------------------------------------\n\n /**\n * Centre frequency of the wah filter in Hz. Range 50..2000, default 200.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get baseFrequency(): number {\n return this._baseFrequency;\n }\n\n public set baseFrequency(value: number) {\n this._baseFrequency = Math.max(50, Math.min(2000, value));\n if (this._setup) {\n this._setup.wahFilter.frequency.setTargetAtTime(this._baseFrequency, this._setup.wahFilter.context.currentTime, 0.01);\n }\n }\n\n /**\n * Envelope sensitivity in Hz/unit: the maximum filter sweep above\n * `baseFrequency` when input is at full amplitude. Range 0..6000, default 3000.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get sensitivity(): number {\n return this._sensitivity;\n }\n\n public set sensitivity(value: number) {\n this._sensitivity = Math.max(0, Math.min(6000, value));\n if (this._setup) {\n this._setup.sensitivityGain.gain.setTargetAtTime(this._sensitivity, this._setup.sensitivityGain.context.currentTime, 0.01);\n }\n }\n\n /**\n * Q (resonance) of the bandpass wah filter. Range 0.1..20, default 4.\n * Changes are ramped smoothly via `setTargetAtTime`.\n */\n public get q(): number {\n return this._q;\n }\n\n public set q(value: number) {\n this._q = Math.max(0.1, Math.min(20, value));\n if (this._setup) {\n this._setup.wahFilter.Q.setTargetAtTime(this._q, this._setup.wahFilter.context.currentTime, 0.01);\n }\n }\n\n /**\n * Envelope smoothing time constant in milliseconds. Range 1..500, default 30.\n * Updating this adjusts the smoothing lowpass cutoff immediately via\n * `setTargetAtTime`.\n */\n public get responseMs(): number {\n return this._responseMs;\n }\n\n public set responseMs(value: number) {\n this._responseMs = Math.max(1, Math.min(500, value));\n if (this._setup) {\n this._setup.smoothingLowpass.frequency.setTargetAtTime(this._smoothingCutoff(), this._setup.smoothingLowpass.context.currentTime, 0.01);\n }\n }\n\n /**\n * Wet (wah-filtered) mix level, 0..1. The dry level is automatically\n * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 0.7.\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 // ---------------------------------------------------------------------------\n // Lifecycle\n // ---------------------------------------------------------------------------\n\n public override destroy(): void {\n this._teardown();\n if (this._setup) {\n this._setup.inputGain.disconnect();\n this._setup.dryGain.disconnect();\n this._setup.wetGain.disconnect();\n this._setup.sensitivityGain.disconnect();\n this._setup.wahFilter.disconnect();\n this._setup.smoothingLowpass.disconnect();\n this._setup.rectifier.disconnect();\n this._setup.outputGain.disconnect();\n this._setup = null;\n }\n }\n\n // ---------------------------------------------------------------------------\n // Private\n // ---------------------------------------------------------------------------\n\n /** Converts `responseMs` to a lowpass cutoff frequency using f = 1/(2π×τ). */\n private _smoothingCutoff(): number {\n return 1000 / (2 * Math.PI * this._responseMs);\n }\n\n /**\n * Builds a 256-point `Float32Array` curve approximating the full-wave\n * rectifier `f(x) = |x|` for use with `WaveShaperNode`.\n */\n private static _makeRectifierCurve(): Float32Array<ArrayBuffer> {\n const n = 256;\n const curve = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const x = (i * 2) / (n - 1) - 1; // maps index to -1..1\n curve[i] = Math.abs(x);\n }\n return curve;\n }\n\n private _setupNodes(ctx: AudioContext): void {\n // Audio-path gain nodes (createGain order: 0=inputGain, 1=outputGain,\n // 2=dryGain, 3=wetGain, 4=sensitivityGain).\n const inputGain = ctx.createGain();\n const outputGain = ctx.createGain();\n const dryGain = ctx.createGain();\n const wetGain = ctx.createGain();\n const sensitivityGain = ctx.createGain();\n\n // Wah filter (audio path) and smoothing filter (envelope control path)\n // (createBiquadFilter order: 0=wahFilter, 1=smoothingLowpass).\n const wahFilter = ctx.createBiquadFilter();\n const smoothingLowpass = ctx.createBiquadFilter();\n\n // Full-wave rectifier for the envelope follower.\n const rectifier = ctx.createWaveShaper();\n\n // ── Initialize values ────────────────────────────────────────────────────\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 sensitivityGain.gain.setValueAtTime(this._sensitivity, ctx.currentTime);\n\n // Wah bandpass filter: base frequency and Q; envelope signal adds on top.\n wahFilter.type = 'bandpass';\n wahFilter.frequency.setValueAtTime(this._baseFrequency, ctx.currentTime);\n wahFilter.Q.setValueAtTime(this._q, ctx.currentTime);\n\n // Rectifier: full-wave |x| curve; 4× oversampling for accuracy.\n rectifier.curve = AutoWahEffect._makeRectifierCurve();\n rectifier.oversample = '4x';\n\n // Smoothing lowpass: cutoff derived from responseMs; low Q for no ringing.\n smoothingLowpass.type = 'lowpass';\n smoothingLowpass.frequency.setValueAtTime(this._smoothingCutoff(), ctx.currentTime);\n smoothingLowpass.Q.setValueAtTime(0.5, ctx.currentTime);\n\n // ── Wiring ───────────────────────────────────────────────────────────────\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet (audio) path: inputGain → wahFilter → wetGain → outputGain\n inputGain.connect(wahFilter);\n wahFilter.connect(wetGain);\n wetGain.connect(outputGain);\n\n // Envelope (control) path - parallel off inputGain, drives wahFilter.frequency.\n // The rectified+smoothed signal is scaled by sensitivityGain and summed into\n // the wahFilter frequency AudioParam, sweeping the filter with input loudness.\n inputGain.connect(rectifier);\n rectifier.connect(smoothingLowpass);\n smoothingLowpass.connect(sensitivityGain);\n sensitivityGain.connect(wahFilter.frequency as unknown as AudioNode);\n\n this._setup = { inputGain, outputGain, dryGain, wetGain, sensitivityGain, wahFilter, smoothingLowpass, rectifier };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,IAAa,gBAAb,MAAa,sBAAsB,YAAY;CAC7C,AAAQ,SAAoC;CAC5C,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAAgC,CAAC,GAAG;EACrD,MAAM;EACN,KAAK,iBAAiB,KAAK,IAAI,IAAI,KAAK,IAAI,KAAM,QAAQ,iBAAiB,GAAG,CAAC;EAC/E,KAAK,eAAe,KAAK,IAAI,GAAG,KAAK,IAAI,KAAM,QAAQ,eAAe,GAAI,CAAC;EAC3E,KAAK,KAAK,KAAK,IAAI,IAAK,KAAK,IAAI,IAAI,QAAQ,KAAK,CAAC,CAAC;EACpD,KAAK,cAAc,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,QAAQ,cAAc,EAAE,CAAC;EACtE,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,OAAO,EAAG,CAAC;EACvD,KAAK,aAAY,YAAW,KAAK,YAAY,OAAO,CAAC;CACvD;;;;;CAMA,IAAW,YAAuB;EAChC,IAAI,CAAC,KAAK,QAAQ,MAAM,IAAI,MAAM,oCAAoC;EACtE,OAAO,KA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,IAAI,WAAW;EAChD,WAAW,KAAK,eAAe,GAAG,IAAI,WAAW;EACjD,QAAQ,KAAK,eAAe,IAAI,KAAK,MAAM,IAAI,WAAW;EAC1D,QAAQ,KAAK,eAAe,KAAK,MAAM,IAAI,WAAW;EACtD,gBAAgB,KAAK,eAAe,KAAK,cAAc,IAAI,WAAW;EAGtE,UAAU,OAAO;EACjB,UAAU,UAAU,eAAe,KAAK,gBAAgB,IAAI,WAAW;EACvE,UAAU,EAAE,eAAe,KAAK,IAAI,IAAI,WAAW;EAGnD,UAAU,QAAQ,cAAc,oBAAoB;EACpD,UAAU,aAAa;EAGvB,iBAAiB,OAAO;EACxB,iBAAiB,UAAU,eAAe,KAAK,iBAAiB,GAAG,IAAI,WAAW;EAClF,iBAAiB,EAAE,eAAe,IAAK,IAAI,WAAW;EAKtD,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,SAAS;EAC3B,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAK1B,UAAU,QAAQ,SAAS;EAC3B,UAAU,QAAQ,gBAAgB;EAClC,iBAAiB,QAAQ,eAAe;EACxC,gBAAgB,QAAQ,UAAU,SAAiC;EAEnE,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAiB;GAAW;GAAkB;EAAU;CACnH;AACF"}
@@ -1,9 +1,9 @@
1
1
  import { AudioEffect } from '@codexo/exojs';
2
2
  /** Construction options for {@link ChorusEffect}. */
3
3
  export interface ChorusEffectOptions {
4
- /** Base delay in ms. Typical 15-30ms. Default 25. */
4
+ /** Base delay in ms, 0..50. Typical 15-30ms. Default 25. */
5
5
  delayMs?: number;
6
- /** Modulation depth in ms (peak deviation from base). Default 5. */
6
+ /** Modulation depth in ms (peak deviation from base), 0..`delayMs`. Default 5. */
7
7
  depthMs?: number;
8
8
  /** LFO rate in Hz. Typical 0.1-5Hz for chorus, 5-15Hz for vibrato. Default 1.5. */
9
9
  rateHz?: number;
@@ -29,17 +29,23 @@ export interface ChorusEffectOptions {
29
29
  export declare class ChorusEffect extends AudioEffect {
30
30
  private _nodes;
31
31
  private _delayMs;
32
- private readonly _onAudioContextReady;
33
32
  private _depthMs;
34
33
  private _rateHz;
35
34
  private _wet;
36
35
  constructor(options?: ChorusEffectOptions);
37
36
  get inputNode(): AudioNode;
38
37
  get outputNode(): AudioNode;
39
- /** Base delay time in milliseconds. Default 25. */
38
+ /**
39
+ * Base delay time in milliseconds, clamped to `depthMs..50`. Lowering it below
40
+ * {@link ChorusEffect.depthMs} stops at `depthMs`. Default 25.
41
+ */
40
42
  get delayMs(): number;
41
43
  set delayMs(value: number);
42
- /** LFO modulation depth in milliseconds (peak deviation from base delay). Default 5. */
44
+ /**
45
+ * LFO modulation depth in milliseconds (peak deviation from base delay),
46
+ * clamped to `0..delayMs` so the swept delay never reaches below zero, which
47
+ * would flatten one half of the sweep. Default 5.
48
+ */
43
49
  get depthMs(): number;
44
50
  set depthMs(value: number);
45
51
  /** LFO oscillation rate in Hz. Typical chorus range is 0.1-5 Hz; 5-15 Hz produces a vibrato effect. Default 1.5. */
@@ -1 +1 @@
1
- {"version":3,"file":"ChorusEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/ChorusEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6D,MAAM,eAAe,CAAC;AAEvG,qDAAqD;AACrD,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAYD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CA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,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAS;IAErB,YAAmB,OAAO,GAAE,mBAAwB,EAOnD;IAED,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED,IAAW,UAAU,IAAI,SAAS,CAGjC;IAMD;;;OAGG;IACH,IAAW,OAAO,IAAI,MAAM,CAE3B;IACD,IAAW,OAAO,CAAC,KAAK,EAAE,MAAM,EAK/B;IAED;;;;OAIG;IACH,IAAW,OAAO,IAAI,MAAM,CAE3B;IACD,IAAW,OAAO,CAAC,KAAK,EAAE,MAAM,EAK/B;IAED,oHAAoH;IACpH,IAAW,MAAM,IAAI,MAAM,CAE1B;IACD,IAAW,MAAM,CAAC,KAAK,EAAE,MAAM,EAK9B;IAED,8FAA8F;IAC9F,IAAW,GAAG,IAAI,MAAM,CAEvB;IACD,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAO3B;IAMe,OAAO,IAAI,IAAI,CAa9B;IAMD,OAAO,CAAC,WAAW;CAuCpB"}
@@ -1,6 +1,8 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
1
+ import { AudioEffect } from "@codexo/exojs";
2
2
 
3
3
  //#region src/effects/ChorusEffect.ts
4
+ const MAX_DELAY_MS = 50;
5
+ const MAX_DELAY_TIME_SECONDS = 100 / 1e3 + .05;
4
6
  /**
5
7
  * Chorus effect using native WebAudio nodes (no worklet required).
6
8
  *
@@ -20,21 +22,16 @@ import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady
20
22
  var ChorusEffect = class extends AudioEffect {
21
23
  _nodes = null;
22
24
  _delayMs;
23
- _onAudioContextReady = (ctx) => {
24
- onAudioContextReady.remove(this._onAudioContextReady);
25
- this._setupNodes(ctx);
26
- };
27
25
  _depthMs;
28
26
  _rateHz;
29
27
  _wet;
30
28
  constructor(options = {}) {
31
29
  super();
32
- this._delayMs = Math.max(0, options.delayMs ?? 25);
33
- this._depthMs = Math.max(0, options.depthMs ?? 5);
30
+ this._delayMs = Math.max(0, Math.min(MAX_DELAY_MS, options.delayMs ?? 25));
31
+ this._depthMs = Math.max(0, Math.min(this._delayMs, options.depthMs ?? 5));
34
32
  this._rateHz = Math.max(0, options.rateHz ?? 1.5);
35
33
  this._wet = Math.max(0, Math.min(1, options.wet ?? .5));
36
- if (isAudioContextReady()) this._setupNodes(getAudioContext());
37
- else onAudioContextReady.add(this._onAudioContextReady);
34
+ this._deferSetup((context) => this._setupNodes(context));
38
35
  }
39
36
  get inputNode() {
40
37
  if (!this._nodes) throw new Error("ChorusEffect not yet initialized.");
@@ -44,20 +41,27 @@ var ChorusEffect = class extends AudioEffect {
44
41
  if (!this._nodes) throw new Error("ChorusEffect not yet initialized.");
45
42
  return this._nodes.outputGain;
46
43
  }
47
- /** Base delay time in milliseconds. Default 25. */
44
+ /**
45
+ * Base delay time in milliseconds, clamped to `depthMs..50`. Lowering it below
46
+ * {@link ChorusEffect.depthMs} stops at `depthMs`. Default 25.
47
+ */
48
48
  get delayMs() {
49
49
  return this._delayMs;
50
50
  }
51
51
  set delayMs(value) {
52
- this._delayMs = Math.max(0, value);
52
+ this._delayMs = Math.max(this._depthMs, Math.min(MAX_DELAY_MS, value));
53
53
  if (this._nodes) this._nodes.delayNode.delayTime.setTargetAtTime(this._delayMs / 1e3, this._nodes.delayNode.context.currentTime, .01);
54
54
  }
55
- /** LFO modulation depth in milliseconds (peak deviation from base delay). Default 5. */
55
+ /**
56
+ * LFO modulation depth in milliseconds (peak deviation from base delay),
57
+ * clamped to `0..delayMs` so the swept delay never reaches below zero, which
58
+ * would flatten one half of the sweep. Default 5.
59
+ */
56
60
  get depthMs() {
57
61
  return this._depthMs;
58
62
  }
59
63
  set depthMs(value) {
60
- this._depthMs = Math.max(0, value);
64
+ this._depthMs = Math.max(0, Math.min(this._delayMs, value));
61
65
  if (this._nodes) this._nodes.lfoGain.gain.setTargetAtTime(this._depthMs / 1e3, this._nodes.lfoGain.context.currentTime, .01);
62
66
  }
63
67
  /** LFO oscillation rate in Hz. Typical chorus range is 0.1-5 Hz; 5-15 Hz produces a vibrato effect. Default 1.5. */
@@ -81,7 +85,7 @@ var ChorusEffect = class extends AudioEffect {
81
85
  }
82
86
  }
83
87
  destroy() {
84
- onAudioContextReady.remove(this._onAudioContextReady);
88
+ this._teardown();
85
89
  if (this._nodes) {
86
90
  this._nodes.lfoOscillator.stop();
87
91
  this._nodes.lfoOscillator.disconnect();
@@ -99,8 +103,7 @@ var ChorusEffect = class extends AudioEffect {
99
103
  const outputGain = ctx.createGain();
100
104
  const dryGain = ctx.createGain();
101
105
  const wetGain = ctx.createGain();
102
- const maxDelay = (this._delayMs + this._depthMs) / 1e3 + .05;
103
- const delayNode = ctx.createDelay(maxDelay);
106
+ const delayNode = ctx.createDelay(MAX_DELAY_TIME_SECONDS);
104
107
  const lfoGain = ctx.createGain();
105
108
  inputGain.gain.setValueAtTime(1, ctx.currentTime);
106
109
  outputGain.gain.setValueAtTime(1, ctx.currentTime);
@@ -1 +1 @@
1
- {"version":3,"file":"ChorusEffect.js","names":[],"sources":["../../../src/effects/ChorusEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link ChorusEffect}. */\nexport interface ChorusEffectOptions {\n /** Base delay in ms. Typical 15-30ms. Default 25. */\n delayMs?: number;\n /** Modulation depth in ms (peak deviation from base). Default 5. */\n depthMs?: number;\n /** LFO rate in Hz. Typical 0.1-5Hz for chorus, 5-15Hz for vibrato. Default 1.5. */\n rateHz?: number;\n /** Dry/wet mix, 0..1. Default 0.5 (equal mix). */\n wet?: number;\n}\n\ninterface ChorusEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly delayNode: DelayNode;\n readonly lfoOscillator: OscillatorNode;\n readonly lfoGain: GainNode;\n}\n\n/**\n * Chorus effect using native WebAudio nodes (no worklet required).\n *\n * The signal splits into a dry path and a wet path. The wet path passes\n * through a DelayNode whose delay time is modulated by a sine-wave LFO,\n * producing the characteristic pitch-wobble / thickening of chorus.\n *\n * Node graph:\n * ```\n * inputGain ┬── dryGain ────────────────┐\n * │ ├── outputGain\n * └── delayNode ── wetGain ────┘\n *\n * lfoOscillator ── lfoGain (depth) ── delayNode.delayTime\n * ```\n */\nexport class ChorusEffect extends AudioEffect {\n private _nodes: ChorusEffectSetup | null = null;\n private _delayMs: number;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\n private _depthMs: number;\n private _rateHz: number;\n private _wet: number;\n\n public constructor(options: ChorusEffectOptions = {}) {\n super();\n this._delayMs = Math.max(0, options.delayMs ?? 25);\n this._depthMs = Math.max(0, options.depthMs ?? 5);\n this._rateHz = Math.max(0, options.rateHz ?? 1.5);\n this._wet = Math.max(0, Math.min(1, options.wet ?? 0.5));\n if (isAudioContextReady()) {\n this._setupNodes(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\n }\n\n public get inputNode(): AudioNode {\n if (!this._nodes) throw new Error('ChorusEffect not yet initialized.');\n return this._nodes.inputGain;\n }\n\n public get outputNode(): AudioNode {\n if (!this._nodes) throw new Error('ChorusEffect not yet initialized.');\n return this._nodes.outputGain;\n }\n\n // -------------------------------------------------------------------------\n // Getters / setters\n // -------------------------------------------------------------------------\n\n /** Base delay time in milliseconds. Default 25. */\n public get delayMs(): number {\n return this._delayMs;\n }\n public set delayMs(value: number) {\n this._delayMs = Math.max(0, value);\n if (this._nodes) {\n this._nodes.delayNode.delayTime.setTargetAtTime(this._delayMs / 1000, this._nodes.delayNode.context.currentTime, 0.01);\n }\n }\n\n /** LFO modulation depth in milliseconds (peak deviation from base delay). Default 5. */\n public get depthMs(): number {\n return this._depthMs;\n }\n public set depthMs(value: number) {\n this._depthMs = Math.max(0, value);\n if (this._nodes) {\n this._nodes.lfoGain.gain.setTargetAtTime(this._depthMs / 1000, this._nodes.lfoGain.context.currentTime, 0.01);\n }\n }\n\n /** LFO oscillation rate in Hz. Typical chorus range is 0.1-5 Hz; 5-15 Hz produces a vibrato effect. Default 1.5. */\n public get rateHz(): number {\n return this._rateHz;\n }\n public set rateHz(value: number) {\n this._rateHz = Math.max(0, value);\n if (this._nodes) {\n this._nodes.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._nodes.inputGain.context.currentTime, 0.01);\n }\n }\n\n /** Wet (modulated) 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 public set wet(value: number) {\n this._wet = Math.max(0, Math.min(1, value));\n if (this._nodes) {\n const ctx = this._nodes.wetGain.context;\n this._nodes.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, 0.01);\n this._nodes.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, 0.01);\n }\n }\n\n // -------------------------------------------------------------------------\n // Lifecycle\n // -------------------------------------------------------------------------\n\n public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n if (this._nodes) {\n this._nodes.lfoOscillator.stop();\n this._nodes.lfoOscillator.disconnect();\n this._nodes.lfoGain.disconnect();\n this._nodes.delayNode.disconnect();\n this._nodes.dryGain.disconnect();\n this._nodes.wetGain.disconnect();\n this._nodes.inputGain.disconnect();\n this._nodes.outputGain.disconnect();\n this._nodes = null;\n }\n }\n\n // -------------------------------------------------------------------------\n // Private\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 // maxDelayTime must be larger than base + peak depth, with a small buffer.\n const maxDelay = (this._delayMs + this._depthMs) / 1000 + 0.05;\n const delayNode = ctx.createDelay(maxDelay);\n const lfoGain = ctx.createGain();\n\n // Initial values\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 delayNode.delayTime.setValueAtTime(this._delayMs / 1000, ctx.currentTime);\n lfoGain.gain.setValueAtTime(this._depthMs / 1000, ctx.currentTime);\n\n // LFO\n const lfoOscillator = ctx.createOscillator();\n lfoOscillator.type = 'sine';\n lfoOscillator.frequency.value = this._rateHz;\n\n // Wiring\n // LFO → lfoGain → delayNode.delayTime (AudioParam)\n lfoOscillator.connect(lfoGain);\n lfoGain.connect(delayNode.delayTime as unknown as AudioNode);\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet path: inputGain → delayNode → wetGain → outputGain\n inputGain.connect(delayNode);\n delayNode.connect(wetGain);\n wetGain.connect(outputGain);\n\n lfoOscillator.start();\n\n this._nodes = { inputGain, outputGain, dryGain, wetGain, delayNode, lfoOscillator, lfoGain };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,IAAa,eAAb,cAAkC,YAAY;CAC5C,AAAQ,SAAmC;CAC3C,AAAQ;CACR,AAAiB,wBAAwB,QAA4B;EACnE,oBAAoB,OAAO,KAAK,oBAAoB;EACpD,KAAK,YAAY,GAAG;CACtB;CACA,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAA+B,CAAC,GAAG;EACpD,MAAM;EACN,KAAK,WAAW,KAAK,IAAI,GAAG,QAAQ,WAAW,EAAE;EACjD,KAAK,WAAW,KAAK,IAAI,GAAG,QAAQ,WAAW,CAAC;EAChD,KAAK,UAAU,KAAK,IAAI,GAAG,QAAQ,UAAU,GAAG;EAChD,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,OAAO,EAAG,CAAC;EACvD,IAAI,oBAAoB,GACtB,KAAK,YAAY,gBAAgB,CAAC;OAElC,oBAAoB,IAAI,KAAK,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UAAU;EAE1B,cAAc,MAAM;EAEpB,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAW;GAAe;EAAQ;CAC7F;AACF"}
1
+ {"version":3,"file":"ChorusEffect.js","names":[],"sources":["../../../src/effects/ChorusEffect.ts"],"sourcesContent":["import { AudioEffect } from '@codexo/exojs';\n\n/** Construction options for {@link ChorusEffect}. */\nexport interface ChorusEffectOptions {\n /** Base delay in ms, 0..50. Typical 15-30ms. Default 25. */\n delayMs?: number;\n /** Modulation depth in ms (peak deviation from base), 0..`delayMs`. Default 5. */\n depthMs?: number;\n /** LFO rate in Hz. Typical 0.1-5Hz for chorus, 5-15Hz for vibrato. Default 1.5. */\n rateHz?: number;\n /** Dry/wet mix, 0..1. Default 0.5 (equal mix). */\n wet?: number;\n}\n\nconst MAX_DELAY_MS = 50;\n// The swept delay peaks at delayMs + depthMs, and depthMs never exceeds\n// delayMs. A DelayNode silently clamps delayTime to the maxDelayTime it was\n// created with, so the node is sized once for the largest reachable value\n// rather than for the construction-time settings.\nconst MAX_DELAY_TIME_SECONDS = (2 * MAX_DELAY_MS) / 1000 + 0.05;\n\ninterface ChorusEffectSetup {\n readonly inputGain: GainNode;\n readonly outputGain: GainNode;\n readonly dryGain: GainNode;\n readonly wetGain: GainNode;\n readonly delayNode: DelayNode;\n readonly lfoOscillator: OscillatorNode;\n readonly lfoGain: GainNode;\n}\n\n/**\n * Chorus effect using native WebAudio nodes (no worklet required).\n *\n * The signal splits into a dry path and a wet path. The wet path passes\n * through a DelayNode whose delay time is modulated by a sine-wave LFO,\n * producing the characteristic pitch-wobble / thickening of chorus.\n *\n * Node graph:\n * ```\n * inputGain ┬── dryGain ────────────────┐\n * │ ├── outputGain\n * └── delayNode ── wetGain ────┘\n *\n * lfoOscillator ── lfoGain (depth) ── delayNode.delayTime\n * ```\n */\nexport class ChorusEffect extends AudioEffect {\n private _nodes: ChorusEffectSetup | null = null;\n private _delayMs: number;\n private _depthMs: number;\n private _rateHz: number;\n private _wet: number;\n\n public constructor(options: ChorusEffectOptions = {}) {\n super();\n this._delayMs = Math.max(0, Math.min(MAX_DELAY_MS, options.delayMs ?? 25));\n this._depthMs = Math.max(0, Math.min(this._delayMs, options.depthMs ?? 5));\n this._rateHz = Math.max(0, options.rateHz ?? 1.5);\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._nodes) throw new Error('ChorusEffect not yet initialized.');\n return this._nodes.inputGain;\n }\n\n public get outputNode(): AudioNode {\n if (!this._nodes) throw new Error('ChorusEffect not yet initialized.');\n return this._nodes.outputGain;\n }\n\n // -------------------------------------------------------------------------\n // Getters / setters\n // -------------------------------------------------------------------------\n\n /**\n * Base delay time in milliseconds, clamped to `depthMs..50`. Lowering it below\n * {@link ChorusEffect.depthMs} stops at `depthMs`. Default 25.\n */\n public get delayMs(): number {\n return this._delayMs;\n }\n public set delayMs(value: number) {\n this._delayMs = Math.max(this._depthMs, Math.min(MAX_DELAY_MS, value));\n if (this._nodes) {\n this._nodes.delayNode.delayTime.setTargetAtTime(this._delayMs / 1000, this._nodes.delayNode.context.currentTime, 0.01);\n }\n }\n\n /**\n * LFO modulation depth in milliseconds (peak deviation from base delay),\n * clamped to `0..delayMs` so the swept delay never reaches below zero, which\n * would flatten one half of the sweep. Default 5.\n */\n public get depthMs(): number {\n return this._depthMs;\n }\n public set depthMs(value: number) {\n this._depthMs = Math.max(0, Math.min(this._delayMs, value));\n if (this._nodes) {\n this._nodes.lfoGain.gain.setTargetAtTime(this._depthMs / 1000, this._nodes.lfoGain.context.currentTime, 0.01);\n }\n }\n\n /** LFO oscillation rate in Hz. Typical chorus range is 0.1-5 Hz; 5-15 Hz produces a vibrato effect. Default 1.5. */\n public get rateHz(): number {\n return this._rateHz;\n }\n public set rateHz(value: number) {\n this._rateHz = Math.max(0, value);\n if (this._nodes) {\n this._nodes.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._nodes.inputGain.context.currentTime, 0.01);\n }\n }\n\n /** Wet (modulated) 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 public set wet(value: number) {\n this._wet = Math.max(0, Math.min(1, value));\n if (this._nodes) {\n const ctx = this._nodes.wetGain.context;\n this._nodes.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, 0.01);\n this._nodes.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, 0.01);\n }\n }\n\n // -------------------------------------------------------------------------\n // Lifecycle\n // -------------------------------------------------------------------------\n\n public override destroy(): void {\n this._teardown();\n if (this._nodes) {\n this._nodes.lfoOscillator.stop();\n this._nodes.lfoOscillator.disconnect();\n this._nodes.lfoGain.disconnect();\n this._nodes.delayNode.disconnect();\n this._nodes.dryGain.disconnect();\n this._nodes.wetGain.disconnect();\n this._nodes.inputGain.disconnect();\n this._nodes.outputGain.disconnect();\n this._nodes = null;\n }\n }\n\n // -------------------------------------------------------------------------\n // Private\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 delayNode = ctx.createDelay(MAX_DELAY_TIME_SECONDS);\n const lfoGain = ctx.createGain();\n\n // Initial values\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 delayNode.delayTime.setValueAtTime(this._delayMs / 1000, ctx.currentTime);\n lfoGain.gain.setValueAtTime(this._depthMs / 1000, ctx.currentTime);\n\n // LFO\n const lfoOscillator = ctx.createOscillator();\n lfoOscillator.type = 'sine';\n lfoOscillator.frequency.value = this._rateHz;\n\n // Wiring\n // LFO → lfoGain → delayNode.delayTime (AudioParam)\n lfoOscillator.connect(lfoGain);\n lfoGain.connect(delayNode.delayTime as unknown as AudioNode);\n\n // Dry path: inputGain → dryGain → outputGain\n inputGain.connect(dryGain);\n dryGain.connect(outputGain);\n\n // Wet path: inputGain → delayNode → wetGain → outputGain\n inputGain.connect(delayNode);\n delayNode.connect(wetGain);\n wetGain.connect(outputGain);\n\n lfoOscillator.start();\n\n this._nodes = { inputGain, outputGain, dryGain, wetGain, delayNode, lfoOscillator, lfoGain };\n }\n}\n"],"mappings":";;;AAcA,MAAM,eAAe;AAKrB,MAAM,yBAA0B,MAAoB,MAAO;;;;;;;;;;;;;;;;;AA4B3D,IAAa,eAAb,cAAkC,YAAY;CAC5C,AAAQ,SAAmC;CAC3C,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAA+B,CAAC,GAAG;EACpD,MAAM;EACN,KAAK,WAAW,KAAK,IAAI,GAAG,KAAK,IAAI,cAAc,QAAQ,WAAW,EAAE,CAAC;EACzE,KAAK,WAAW,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,UAAU,QAAQ,WAAW,CAAC,CAAC;EACzE,KAAK,UAAU,KAAK,IAAI,GAAG,QAAQ,UAAU,GAAG;EAChD,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,OAAO,EAAG,CAAC;EACvD,KAAK,aAAY,YAAW,KAAK,YAAY,OAAO,CAAC;CACvD;CAEA,IAAW,YAAuB;EAChC,IAAI,CAAC,KAAK,QAAQ,MAAM,IAAI,MAAM,mCAAmC;EACrE,OAAO,KAAK,OAAO;CACrB;CAEA,IAAW,aAAwB;EACjC,IAAI,CAAC,KAAK,QAAQ,MAAM,IAAI,MAAM,mCAAmC;EACrE,OAAO,KAAK,OAAO;CACrB;;;;;CAUA,IAAW,UAAkB;EAC3B,OAAO,KAAK;CACd;CACA,IAAW,QAAQ,OAAe;EAChC,KAAK,WAAW,KAAK,IAAI,KAAK,UAAU,KAAK,IAAI,cAAc,KAAK,CAAC;EACrE,IAAI,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C,KAAK,OAAO,WAAW,WAAW;GAClC,KAAK,SAAS;EAChB;CACF;CAMA,AAAQ,YAAY,KAAyB;EAC3C,MAAM,YAAY,IAAI,WAAW;EACjC,MAAM,aAAa,IAAI,WAAW;EAClC,MAAM,UAAU,IAAI,WAAW;EAC/B,MAAM,UAAU,IAAI,WAAW;EAC/B,MAAM,YAAY,IAAI,YAAY,sBAAsB;EACxD,MAAM,UAAU,IAAI,WAAW;EAG/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,MAAM,IAAI,WAAW;EACtD,UAAU,UAAU,eAAe,KAAK,WAAW,KAAM,IAAI,WAAW;EACxE,QAAQ,KAAK,eAAe,KAAK,WAAW,KAAM,IAAI,WAAW;EAGjE,MAAM,gBAAgB,IAAI,iBAAiB;EAC3C,cAAc,OAAO;EACrB,cAAc,UAAU,QAAQ,KAAK;EAIrC,cAAc,QAAQ,OAAO;EAC7B,QAAQ,QAAQ,UAAU,SAAiC;EAG3D,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAG1B,UAAU,QAAQ,SAAS;EAC3B,UAAU,QAAQ,OAAO;EACzB,QAAQ,QAAQ,UAAU;EAE1B,cAAc,MAAM;EAEpB,KAAK,SAAS;GAAE;GAAW;GAAY;GAAS;GAAS;GAAW;GAAe;EAAQ;CAC7F;AACF"}
@@ -18,7 +18,6 @@ export interface CompressorEffectOptions {
18
18
  export declare class CompressorEffect extends AudioEffect {
19
19
  private _node;
20
20
  private _threshold;
21
- private readonly _onAudioContextReady;
22
21
  private _knee;
23
22
  private _ratio;
24
23
  private _attack;
@@ -1 +1 @@
1
- {"version":3,"file":"CompressorEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/CompressorEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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MAAM,CAE3B;IAED,IAAW,OAAO,CAAC,KAAK,EAAE,MAAM,EAK/B;IAED;;;;;;;OAOG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;IAEe,OAAO,IAAI,IAAI,CAI9B;IAED,OAAO,CAAC,MAAM;CASf"}
@@ -1,4 +1,4 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
1
+ import { AudioEffect } from "@codexo/exojs";
2
2
 
3
3
  //#region src/effects/CompressorEffect.ts
4
4
  /**
@@ -10,10 +10,6 @@ import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady
10
10
  var CompressorEffect = class extends AudioEffect {
11
11
  _node = null;
12
12
  _threshold;
13
- _onAudioContextReady = (ctx) => {
14
- onAudioContextReady.remove(this._onAudioContextReady);
15
- this._setup(ctx);
16
- };
17
13
  _knee;
18
14
  _ratio;
19
15
  _attack;
@@ -25,8 +21,7 @@ var CompressorEffect = class extends AudioEffect {
25
21
  this._ratio = Math.max(1, Math.min(20, options.ratio ?? 12));
26
22
  this._attack = Math.max(0, Math.min(1, options.attack ?? .003));
27
23
  this._release = Math.max(0, Math.min(1, options.release ?? .25));
28
- if (isAudioContextReady()) this._setup(getAudioContext());
29
- else onAudioContextReady.add(this._onAudioContextReady);
24
+ this._deferSetup((context) => this._setup(context));
30
25
  }
31
26
  get inputNode() {
32
27
  if (!this._node) throw new Error("CompressorEffect not yet initialized.");
@@ -88,7 +83,7 @@ var CompressorEffect = class extends AudioEffect {
88
83
  return this._node?.reduction ?? 0;
89
84
  }
90
85
  destroy() {
91
- onAudioContextReady.remove(this._onAudioContextReady);
86
+ this._teardown();
92
87
  this._node?.disconnect();
93
88
  this._node = null;
94
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CompressorEffect.js","names":[],"sources":["../../../src/effects/CompressorEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from '@codexo/exojs';\n\n/** Construction options for {@link CompressorEffect}. All values are clamped to their valid ranges on assignment. */\nexport interface CompressorEffectOptions {\n threshold?: number;\n knee?: number;\n ratio?: number;\n /** Time in seconds for the compressor to engage after the signal exceeds the threshold. Range 0..1, default 0.003. */\n attack?: number;\n /** Time in seconds for the compressor to disengage after the signal drops below the threshold. Range 0..1, default 0.25. */\n release?: number;\n}\n\n/**\n * Dynamic-range compressor backed by a Web Audio `DynamicsCompressorNode`.\n * Reduces the volume of loud signals above a threshold, evening out the\n * perceived loudness of a mix. All parameter changes are applied with a short\n * smoothing ramp so they are artifact-free during playback.\n */\nexport class CompressorEffect extends AudioEffect {\n private _node: DynamicsCompressorNode | null = null;\n private _threshold: number;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setup(ctx);\n };\n private _knee: number;\n private _ratio: number;\n private _attack: number;\n private _release: number;\n\n public constructor(options: CompressorEffectOptions = {}) {\n super();\n this._threshold = Math.max(-100, Math.min(0, options.threshold ?? -24));\n this._knee = Math.max(0, Math.min(40, options.knee ?? 30));\n this._ratio = Math.max(1, Math.min(20, options.ratio ?? 12));\n this._attack = Math.max(0, Math.min(1, options.attack ?? 0.003));\n this._release = Math.max(0, Math.min(1, options.release ?? 0.25));\n if (isAudioContextReady()) {\n this._setup(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\n }\n\n public get inputNode(): AudioNode {\n if (!this._node) throw new Error('CompressorEffect not yet initialized.');\n return this._node;\n }\n\n public get outputNode(): AudioNode {\n if (!this._node) throw new Error('CompressorEffect not yet initialized.');\n return this._node;\n }\n\n /** Level above which compression begins, in dBFS. Range −100..0, default −24. */\n public get threshold(): number {\n return this._threshold;\n }\n\n public set threshold(value: number) {\n this._threshold = Math.max(-100, Math.min(0, value));\n if (this._node) {\n this._node.threshold.setTargetAtTime(this._threshold, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Width in dB of the transition region around the threshold (soft knee). Range 0..40, default 30. */\n public get knee(): number {\n return this._knee;\n }\n\n public set knee(value: number) {\n this._knee = Math.max(0, Math.min(40, value));\n if (this._node) {\n this._node.knee.setTargetAtTime(this._knee, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Input-to-output dB ratio above the threshold. Range 1..20, default 12. */\n public get ratio(): number {\n return this._ratio;\n }\n\n public set ratio(value: number) {\n this._ratio = Math.max(1, Math.min(20, value));\n if (this._node) {\n this._node.ratio.setTargetAtTime(this._ratio, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Time in seconds for the compressor to engage after the signal exceeds the threshold. Range 0..1, default 0.003. */\n public get attack(): number {\n return this._attack;\n }\n\n public set attack(value: number) {\n this._attack = Math.max(0, Math.min(1, value));\n if (this._node) {\n this._node.attack.setTargetAtTime(this._attack, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Time in seconds for the compressor to disengage after the signal drops below the threshold. Range 0..1, default 0.25. */\n public get release(): number {\n return this._release;\n }\n\n public set release(value: number) {\n this._release = Math.max(0, Math.min(1, value));\n if (this._node) {\n this._node.release.setTargetAtTime(this._release, this._node.context.currentTime, 0.01);\n }\n }\n\n /**\n * Live gain reduction in dB applied by the compressor right now. Always\n * `<= 0` (or `0` when the compressor isn't engaging). Read-only - drive\n * input level meters / sidechain visualisations off this value.\n *\n * Returns `0` until the underlying node has been created (before the\n * audio context is ready).\n */\n public get reduction(): number {\n return this._node?.reduction ?? 0;\n }\n\n public override destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._node?.disconnect();\n this._node = null;\n }\n\n private _setup(ctx: AudioContext): void {\n const node = ctx.createDynamicsCompressor();\n node.threshold.setValueAtTime(this._threshold, ctx.currentTime);\n node.knee.setValueAtTime(this._knee, ctx.currentTime);\n node.ratio.setValueAtTime(this._ratio, ctx.currentTime);\n node.attack.setValueAtTime(this._attack, ctx.currentTime);\n node.release.setValueAtTime(this._release, ctx.currentTime);\n this._node = node;\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,IAAa,mBAAb,cAAsC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QAAQ,IAAI,WAAW;EACtD,KAAK,OAAO,eAAe,KAAK,SAAS,IAAI,WAAW;EACxD,KAAK,QAAQ,eAAe,KAAK,UAAU,IAAI,WAAW;EAC1D,KAAK,QAAQ;CACf;AACF"}
1
+ {"version":3,"file":"CompressorEffect.js","names":[],"sources":["../../../src/effects/CompressorEffect.ts"],"sourcesContent":["import { AudioEffect } from '@codexo/exojs';\n\n/** Construction options for {@link CompressorEffect}. All values are clamped to their valid ranges on assignment. */\nexport interface CompressorEffectOptions {\n threshold?: number;\n knee?: number;\n ratio?: number;\n /** Time in seconds for the compressor to engage after the signal exceeds the threshold. Range 0..1, default 0.003. */\n attack?: number;\n /** Time in seconds for the compressor to disengage after the signal drops below the threshold. Range 0..1, default 0.25. */\n release?: number;\n}\n\n/**\n * Dynamic-range compressor backed by a Web Audio `DynamicsCompressorNode`.\n * Reduces the volume of loud signals above a threshold, evening out the\n * perceived loudness of a mix. All parameter changes are applied with a short\n * smoothing ramp so they are artifact-free during playback.\n */\nexport class CompressorEffect extends AudioEffect {\n private _node: DynamicsCompressorNode | null = null;\n private _threshold: number;\n private _knee: number;\n private _ratio: number;\n private _attack: number;\n private _release: number;\n\n public constructor(options: CompressorEffectOptions = {}) {\n super();\n this._threshold = Math.max(-100, Math.min(0, options.threshold ?? -24));\n this._knee = Math.max(0, Math.min(40, options.knee ?? 30));\n this._ratio = Math.max(1, Math.min(20, options.ratio ?? 12));\n this._attack = Math.max(0, Math.min(1, options.attack ?? 0.003));\n this._release = Math.max(0, Math.min(1, options.release ?? 0.25));\n this._deferSetup(context => this._setup(context));\n }\n\n public get inputNode(): AudioNode {\n if (!this._node) throw new Error('CompressorEffect not yet initialized.');\n return this._node;\n }\n\n public get outputNode(): AudioNode {\n if (!this._node) throw new Error('CompressorEffect not yet initialized.');\n return this._node;\n }\n\n /** Level above which compression begins, in dBFS. Range −100..0, default −24. */\n public get threshold(): number {\n return this._threshold;\n }\n\n public set threshold(value: number) {\n this._threshold = Math.max(-100, Math.min(0, value));\n if (this._node) {\n this._node.threshold.setTargetAtTime(this._threshold, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Width in dB of the transition region around the threshold (soft knee). Range 0..40, default 30. */\n public get knee(): number {\n return this._knee;\n }\n\n public set knee(value: number) {\n this._knee = Math.max(0, Math.min(40, value));\n if (this._node) {\n this._node.knee.setTargetAtTime(this._knee, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Input-to-output dB ratio above the threshold. Range 1..20, default 12. */\n public get ratio(): number {\n return this._ratio;\n }\n\n public set ratio(value: number) {\n this._ratio = Math.max(1, Math.min(20, value));\n if (this._node) {\n this._node.ratio.setTargetAtTime(this._ratio, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Time in seconds for the compressor to engage after the signal exceeds the threshold. Range 0..1, default 0.003. */\n public get attack(): number {\n return this._attack;\n }\n\n public set attack(value: number) {\n this._attack = Math.max(0, Math.min(1, value));\n if (this._node) {\n this._node.attack.setTargetAtTime(this._attack, this._node.context.currentTime, 0.01);\n }\n }\n\n /** Time in seconds for the compressor to disengage after the signal drops below the threshold. Range 0..1, default 0.25. */\n public get release(): number {\n return this._release;\n }\n\n public set release(value: number) {\n this._release = Math.max(0, Math.min(1, value));\n if (this._node) {\n this._node.release.setTargetAtTime(this._release, this._node.context.currentTime, 0.01);\n }\n }\n\n /**\n * Live gain reduction in dB applied by the compressor right now. Always\n * `<= 0` (or `0` when the compressor isn't engaging). Read-only - drive\n * input level meters / sidechain visualisations off this value.\n *\n * Returns `0` until the underlying node has been created (before the\n * audio context is ready).\n */\n public get reduction(): number {\n return this._node?.reduction ?? 0;\n }\n\n public override destroy(): void {\n this._teardown();\n this._node?.disconnect();\n this._node = null;\n }\n\n private _setup(ctx: AudioContext): void {\n const node = ctx.createDynamicsCompressor();\n node.threshold.setValueAtTime(this._threshold, ctx.currentTime);\n node.knee.setValueAtTime(this._knee, ctx.currentTime);\n node.ratio.setValueAtTime(this._ratio, ctx.currentTime);\n node.attack.setValueAtTime(this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AAe,KAAK,SAAS,IAAI,WAAW;EACxD,KAAK,QAAQ,eAAe,KAAK,UAAU,IAAI,WAAW;EAC1D,KAAK,QAAQ;CACf;AACF"}
@@ -65,7 +65,6 @@ export declare class ConvolutionEffect extends AudioEffect {
65
65
  private _pendingImpulse;
66
66
  /** Bumped per impulse request so a slow resample cannot overwrite a newer IR. */
67
67
  private _impulseGeneration;
68
- private readonly _onAudioContextReady;
69
68
  constructor(options?: ConvolutionEffectOptions);
70
69
  /**
71
70
  * The node where audio enters this effect. Throws if the audio context is
@@ -1 +1 @@
1
- {"version":3,"file":"ConvolutionEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/ConvolutionEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6D,KAAK,EAAE,MAAM,eAAe,CAAC;AAE9G,0DAA0D;AAC1D,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAC9B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AA0BD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,eAAe,CAA6B;IAEpD,iFAAiF;IACjF,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IAEF,YAAmB,OAAO,GAAE,wBAA6B,EAWxD;IAED;;;OAGG;IACH,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED;;;OAGG;IACH,IAAW,UAAU,IAAI,SAAS,CAGj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AAmB,OAAO,GAAE,wBAA6B,EAOxD;IAED;;;OAGG;IACH,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED;;;OAGG;IACH,IAAW,UAAU,IAAI,SAAS,CAGjC;IAED;;;OAGG;IACH,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAO3B;IAED;;;;;;;OAOG;IACH,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED,IAAW,SAAS,CAAC,KAAK,EAAE,OAAO,EAYlC;IAED;;;;OAIG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAM5B;IAED;;;;;;;;OAQG;IACI,UAAU,CAAC,EAAE,EAAE,WAAW,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,CA4BtD;IAED,4DAA4D;IAC5D,OAAO,CAAC,aAAa;IAUL,OAAO,IAAI,IAAI,CAU9B;IAED,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,WAAW;CAkCpB"}
@@ -1,4 +1,4 @@
1
- import { AudioEffect, Sound, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
1
+ import { AudioEffect, Sound } from "@codexo/exojs";
2
2
 
3
3
  //#region src/effects/ConvolutionEffect.ts
4
4
  /**
@@ -50,18 +50,13 @@ var ConvolutionEffect = class extends AudioEffect {
50
50
  _pendingImpulse;
51
51
  /** Bumped per impulse request so a slow resample cannot overwrite a newer IR. */
52
52
  _impulseGeneration = 0;
53
- _onAudioContextReady = (ctx) => {
54
- onAudioContextReady.remove(this._onAudioContextReady);
55
- this._setupNodes(ctx);
56
- };
57
53
  constructor(options = {}) {
58
54
  super();
59
55
  this._wet = Math.max(0, Math.min(1, options.wet ?? 1));
60
56
  this._normalize = options.normalize ?? true;
61
57
  this._gain = Math.max(0, Math.min(4, options.gain ?? 1));
62
58
  this._pendingImpulse = options.impulse ?? null;
63
- if (isAudioContextReady()) this._setupNodes(getAudioContext());
64
- else onAudioContextReady.add(this._onAudioContextReady);
59
+ this._deferSetup((context) => this._setupNodes(context));
65
60
  }
66
61
  /**
67
62
  * The node where audio enters this effect. Throws if the audio context is
@@ -161,7 +156,7 @@ var ConvolutionEffect = class extends AudioEffect {
161
156
  convolver.buffer = buffer;
162
157
  }
163
158
  destroy() {
164
- onAudioContextReady.remove(this._onAudioContextReady);
159
+ this._teardown();
165
160
  if (this._setup) {
166
161
  this._setup.inputGain.disconnect();
167
162
  this._setup.convolver.disconnect();
@@ -1 +1 @@
1
- {"version":3,"file":"ConvolutionEffect.js","names":[],"sources":["../../../src/effects/ConvolutionEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady, 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 private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\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 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('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 onAudioContextReady.remove(this._onAudioContextReady);\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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A,AAAQ,eAAe,IAAoD;EACzE,IAAI,OAAO,MAAM,OAAO;EACxB,IAAI,cAAc,OAAO,OAAO,GAAG;EACnC,OAAO;CACT;CAEA,AAAQ,YAAY,KAAyB;EAC3C,MAAM,YAAY,IAAI,WAAW;EACjC,MAAM,aAAa,IAAI,WAAW;EAClC,MAAM,YAAY,IAAI,gBAAgB;EACtC,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,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
+ {"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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AAO,UAAU,WAAW;GACjC,KAAK,OAAO,QAAQ,WAAW;GAC/B,KAAK,OAAO,QAAQ,WAAW;GAC/B,KAAK,OAAO,WAAW,WAAW;GAClC,KAAK,SAAS;EAChB;CACF;CAEA,AAAQ,eAAe,IAAoD;EACzE,IAAI,OAAO,MAAM,OAAO;EACxB,IAAI,cAAc,OAAO,OAAO,GAAG;EACnC,OAAO;CACT;CAEA,AAAQ,YAAY,KAAyB;EAC3C,MAAM,YAAY,IAAI,WAAW;EACjC,MAAM,aAAa,IAAI,WAAW;EAClC,MAAM,YAAY,IAAI,gBAAgB;EACtC,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,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"}
@@ -15,7 +15,6 @@ export interface DelayEffectOptions {
15
15
  export declare class DelayEffect extends AudioEffect {
16
16
  private _setup;
17
17
  private _delaySeconds;
18
- private readonly _onAudioContextReady;
19
18
  private _feedback;
20
19
  private _wet;
21
20
  constructor(options?: DelayEffectOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"DelayEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/DelayEffect.ts"],"names":[],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AY,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,4 +1,4 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
1
+ import { AudioEffect } from "@codexo/exojs";
2
2
 
3
3
  //#region src/effects/DelayEffect.ts
4
4
  /**
@@ -11,10 +11,6 @@ import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady
11
11
  var DelayEffect = class extends AudioEffect {
12
12
  _setup = null;
13
13
  _delaySeconds;
14
- _onAudioContextReady = (ctx) => {
15
- onAudioContextReady.remove(this._onAudioContextReady);
16
- this._setupNodes(ctx);
17
- };
18
14
  _feedback;
19
15
  _wet;
20
16
  constructor(options = {}) {
@@ -22,8 +18,7 @@ var DelayEffect = class extends AudioEffect {
22
18
  this._delaySeconds = Math.max(0, Math.min(5, options.delaySeconds ?? .3));
23
19
  this._feedback = Math.max(0, Math.min(.95, options.feedback ?? .4));
24
20
  this._wet = Math.max(0, Math.min(1, options.wet ?? .5));
25
- if (isAudioContextReady()) this._setupNodes(getAudioContext());
26
- else onAudioContextReady.add(this._onAudioContextReady);
21
+ this._deferSetup((context) => this._setupNodes(context));
27
22
  }
28
23
  get inputNode() {
29
24
  if (!this._setup) throw new Error("DelayEffect not yet initialized.");
@@ -62,7 +57,7 @@ var DelayEffect = class extends AudioEffect {
62
57
  }
63
58
  }
64
59
  destroy() {
65
- onAudioContextReady.remove(this._onAudioContextReady);
60
+ this._teardown();
66
61
  if (this._setup) {
67
62
  this._setup.inputGain.disconnect();
68
63
  this._setup.delayNode.disconnect();
@@ -1 +1 @@
1
- {"version":3,"file":"DelayEffect.js","names":[],"sources":["../../../src/effects/DelayEffect.ts"],"sourcesContent":["import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } 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 readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupNodes(ctx);\n };\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 if (isAudioContextReady()) {\n this._setupNodes(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\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 onAudioContextReady.remove(this._onAudioContextReady);\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,AAAiB,wBAAwB,QAA4B;EACnE,oBAAoB,OAAO,KAAK,oBAAoB;EACpD,KAAK,YAAY,GAAG;CACtB;CACA,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,EAAG,CAAC;EACpE,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,OAAO,EAAG,CAAC;EACvD,IAAI,oBAAoB,GACtB,KAAK,YAAY,gBAAgB,CAAC;OAElC,oBAAoB,IAAI,KAAK,oBAAoB;CAErD;CAEA,IAAW,YAAuB;EAChC,IAAI,CAAC,KAAK,QAAQ,MAAM,IAAI,MAAM,kCAAkC;EACpE,OAAO,KAAK,OAAO;CACrB;CAEA,IAAW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B;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
+ {"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,EAAG,CAAC;EACpE,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,OAAO,EAAG,CAAC;EACvD,KAAK,aAAY,YAAW,KAAK,YAAY,OAAO,CAAC;CACvD;CA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