@codexo/exojs-audio-fx 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +7 -53
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +12 -20
  5. package/dist/esm/AudioAnalyser.d.ts +0 -125
  6. package/dist/esm/AudioAnalyser.d.ts.map +0 -1
  7. package/dist/esm/AudioAnalyser.js +0 -369
  8. package/dist/esm/AudioAnalyser.js.map +0 -1
  9. package/dist/esm/BeatDetector.d.ts +0 -286
  10. package/dist/esm/BeatDetector.d.ts.map +0 -1
  11. package/dist/esm/BeatDetector.js +0 -419
  12. package/dist/esm/BeatDetector.js.map +0 -1
  13. package/dist/esm/PcmStreamSource.d.ts +0 -127
  14. package/dist/esm/PcmStreamSource.d.ts.map +0 -1
  15. package/dist/esm/PcmStreamSource.js +0 -308
  16. package/dist/esm/PcmStreamSource.js.map +0 -1
  17. package/dist/esm/dsp/fft.d.ts +0 -22
  18. package/dist/esm/dsp/fft.d.ts.map +0 -1
  19. package/dist/esm/dsp/mel.d.ts +0 -43
  20. package/dist/esm/dsp/mel.d.ts.map +0 -1
  21. package/dist/esm/dsp/mel.js +0 -61
  22. package/dist/esm/dsp/mel.js.map +0 -1
  23. package/dist/esm/dsp/tempogram.d.ts +0 -192
  24. package/dist/esm/dsp/tempogram.d.ts.map +0 -1
  25. package/dist/esm/effects/AutoWahEffect.d.ts +0 -128
  26. package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
  27. package/dist/esm/effects/AutoWahEffect.js +0 -214
  28. package/dist/esm/effects/AutoWahEffect.js.map +0 -1
  29. package/dist/esm/effects/BitCrusherEffect.d.ts +0 -64
  30. package/dist/esm/effects/BitCrusherEffect.d.ts.map +0 -1
  31. package/dist/esm/effects/BitCrusherEffect.js +0 -76
  32. package/dist/esm/effects/BitCrusherEffect.js.map +0 -1
  33. package/dist/esm/effects/ChorusEffect.d.ts +0 -54
  34. package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
  35. package/dist/esm/effects/ChorusEffect.js +0 -136
  36. package/dist/esm/effects/ChorusEffect.js.map +0 -1
  37. package/dist/esm/effects/CompressorEffect.d.ts +0 -56
  38. package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
  39. package/dist/esm/effects/CompressorEffect.js +0 -108
  40. package/dist/esm/effects/CompressorEffect.js.map +0 -1
  41. package/dist/esm/effects/ConvolutionEffect.d.ts +0 -119
  42. package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
  43. package/dist/esm/effects/ConvolutionEffect.js +0 -212
  44. package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
  45. package/dist/esm/effects/DelayEffect.d.ts +0 -36
  46. package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
  47. package/dist/esm/effects/DelayEffect.js +0 -109
  48. package/dist/esm/effects/DelayEffect.js.map +0 -1
  49. package/dist/esm/effects/DistortionEffect.d.ts +0 -120
  50. package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
  51. package/dist/esm/effects/DistortionEffect.js +0 -194
  52. package/dist/esm/effects/DistortionEffect.js.map +0 -1
  53. package/dist/esm/effects/DuckingEffect.d.ts +0 -44
  54. package/dist/esm/effects/DuckingEffect.d.ts.map +0 -1
  55. package/dist/esm/effects/DuckingEffect.js +0 -95
  56. package/dist/esm/effects/DuckingEffect.js.map +0 -1
  57. package/dist/esm/effects/EqualizerEffect.d.ts +0 -51
  58. package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
  59. package/dist/esm/effects/EqualizerEffect.js +0 -124
  60. package/dist/esm/effects/EqualizerEffect.js.map +0 -1
  61. package/dist/esm/effects/FlangerEffect.d.ts +0 -99
  62. package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
  63. package/dist/esm/effects/FlangerEffect.js +0 -176
  64. package/dist/esm/effects/FlangerEffect.js.map +0 -1
  65. package/dist/esm/effects/GranularEffect.d.ts +0 -67
  66. package/dist/esm/effects/GranularEffect.d.ts.map +0 -1
  67. package/dist/esm/effects/GranularEffect.js +0 -104
  68. package/dist/esm/effects/GranularEffect.js.map +0 -1
  69. package/dist/esm/effects/LimiterEffect.d.ts +0 -125
  70. package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
  71. package/dist/esm/effects/LimiterEffect.js +0 -186
  72. package/dist/esm/effects/LimiterEffect.js.map +0 -1
  73. package/dist/esm/effects/PhaserEffect.d.ts +0 -127
  74. package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
  75. package/dist/esm/effects/PhaserEffect.js +0 -218
  76. package/dist/esm/effects/PhaserEffect.js.map +0 -1
  77. package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -84
  78. package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
  79. package/dist/esm/effects/PingPongDelayEffect.js +0 -176
  80. package/dist/esm/effects/PingPongDelayEffect.js.map +0 -1
  81. package/dist/esm/effects/PitchShiftEffect.d.ts +0 -46
  82. package/dist/esm/effects/PitchShiftEffect.d.ts.map +0 -1
  83. package/dist/esm/effects/PitchShiftEffect.js +0 -64
  84. package/dist/esm/effects/PitchShiftEffect.js.map +0 -1
  85. package/dist/esm/effects/ReverbEffect.d.ts +0 -38
  86. package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
  87. package/dist/esm/effects/ReverbEffect.js +0 -117
  88. package/dist/esm/effects/ReverbEffect.js.map +0 -1
  89. package/dist/esm/effects/RingModulatorEffect.d.ts +0 -96
  90. package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
  91. package/dist/esm/effects/RingModulatorEffect.js +0 -157
  92. package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
  93. package/dist/esm/effects/TremoloEffect.d.ts +0 -111
  94. package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
  95. package/dist/esm/effects/TremoloEffect.js +0 -197
  96. package/dist/esm/effects/TremoloEffect.js.map +0 -1
  97. package/dist/esm/effects/VocoderEffect.d.ts +0 -45
  98. package/dist/esm/effects/VocoderEffect.d.ts.map +0 -1
  99. package/dist/esm/effects/VocoderEffect.js +0 -73
  100. package/dist/esm/effects/VocoderEffect.js.map +0 -1
  101. package/dist/esm/index.d.ts +0 -25
  102. package/dist/esm/index.d.ts.map +0 -1
  103. package/dist/esm/index.js +0 -24
  104. package/dist/esm/worklets/beat-detector.worklet.js +0 -6
  105. package/dist/esm/worklets/beat-detector.worklet.js.map +0 -1
  106. package/dist/esm/worklets/bit-crusher.worklet.js +0 -6
  107. package/dist/esm/worklets/bit-crusher.worklet.js.map +0 -1
  108. package/dist/esm/worklets/ducking.worklet.js +0 -6
  109. package/dist/esm/worklets/ducking.worklet.js.map +0 -1
  110. package/dist/esm/worklets/granular.worklet.js +0 -6
  111. package/dist/esm/worklets/granular.worklet.js.map +0 -1
  112. package/dist/esm/worklets/pcm-stream.worklet.js +0 -6
  113. package/dist/esm/worklets/pcm-stream.worklet.js.map +0 -1
  114. package/dist/esm/worklets/pitch-shift.worklet.js +0 -6
  115. package/dist/esm/worklets/pitch-shift.worklet.js.map +0 -1
  116. package/dist/esm/worklets/vocoder.worklet.js +0 -6
  117. package/dist/esm/worklets/vocoder.worklet.js.map +0 -1
@@ -1,76 +0,0 @@
1
- import bit_crusher_worklet_default from "../worklets/bit-crusher.worklet.js";
2
- import { WorkletEffect } from "@codexo/exojs";
3
-
4
- //#region src/effects/BitCrusherEffect.ts
5
- /**
6
- * Lo-fi bit-crusher effect implemented as a {@link WorkletEffect}. Applies two
7
- * classic degradation stages in series:
8
- *
9
- * 1. **Bit-depth reduction** - each sample is quantized to `2^bits` discrete
10
- * levels, adding harmonic distortion characteristic of low-resolution audio.
11
- * 2. **Sample-rate reduction** - a phase-accumulator sample-and-hold circuit
12
- * re-latches the (quantized) input only `normFreq` times per input sample on
13
- * average, producing aliasing artefacts reminiscent of early digital hardware.
14
- *
15
- * The worklet emits a pure wet signal; dry/wet mixing is handled by the base
16
- * class.
17
- *
18
- * @example
19
- * ```ts
20
- * const bus = engine.createBus();
21
- * const crusher = new BitCrusherEffect({ bits: 4, frequencyReduction: 0.3, wet: 0.8 });
22
- * bus.addEffect(crusher);
23
- *
24
- * // Adjust at runtime:
25
- * crusher.bits = 2; // extreme quantization crunch
26
- * crusher.frequencyReduction = 0.1; // heavy downsampling aliasing
27
- * crusher.wet = 0.5; // blend with dry signal
28
- * ```
29
- */
30
- var BitCrusherEffect = class extends WorkletEffect {
31
- _bits;
32
- _frequencyReduction;
33
- constructor(options = {}) {
34
- super();
35
- this._bits = Math.round(Math.max(1, Math.min(16, options.bits ?? 8)));
36
- this._frequencyReduction = Math.max(0, Math.min(1, options.frequencyReduction ?? .5));
37
- this.wet = options.wet ?? 1;
38
- }
39
- get _workletName() {
40
- return "exojs-bit-crusher";
41
- }
42
- get _workletSource() {
43
- return bit_crusher_worklet_default;
44
- }
45
- _onWorkletReady() {
46
- this._setAudioParam("bits", this._bits);
47
- this._setAudioParam("normFreq", this._frequencyReduction);
48
- }
49
- /**
50
- * Bit depth for sample quantization. Lower values produce more distortion.
51
- * Range 1..16, default 8.
52
- */
53
- get bits() {
54
- return this._bits;
55
- }
56
- set bits(value) {
57
- this._bits = Math.round(Math.max(1, Math.min(16, value)));
58
- this._setAudioParam("bits", this._bits);
59
- }
60
- /**
61
- * Fraction of the sample rate retained (0 = never re-latch, 1 = every sample).
62
- * Lower values create more aliasing artefacts. Maps to the worklet `normFreq`
63
- * AudioParam. Range 0..1, default 0.5.
64
- */
65
- get frequencyReduction() {
66
- return this._frequencyReduction;
67
- }
68
- set frequencyReduction(value) {
69
- this._frequencyReduction = Math.max(0, Math.min(1, value));
70
- this._setAudioParam("normFreq", this._frequencyReduction);
71
- }
72
- };
73
-
74
- //#endregion
75
- export { BitCrusherEffect };
76
- //# sourceMappingURL=BitCrusherEffect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BitCrusherEffect.js","names":["bitCrusherWorkletSource"],"sources":["../../../src/effects/BitCrusherEffect.ts"],"sourcesContent":["import { WorkletEffect } from '@codexo/exojs';\n\nimport bitCrusherWorkletSource from '../worklets/bit-crusher.worklet.ts?worklet';\n\nexport interface BitCrusherEffectOptions {\n /**\n * Bit depth for sample quantization. Lower values produce coarser steps and\n * more distortion. Range 1..16, default 8.\n */\n bits?: number;\n /**\n * Fraction of the sample rate retained (sample-and-hold). A value of 1 means\n * every sample is re-latched (no rate reduction). A value of 0.5 halves the\n * effective sample rate, introducing aliasing. Range 0..1, default 0.5.\n * Maps directly to the worklet `normFreq` AudioParam.\n */\n frequencyReduction?: number;\n /** Dry/wet mix, 0..1. Default 1. */\n wet?: number;\n}\n\n/**\n * Lo-fi bit-crusher effect implemented as a {@link WorkletEffect}. Applies two\n * classic degradation stages in series:\n *\n * 1. **Bit-depth reduction** - each sample is quantized to `2^bits` discrete\n * levels, adding harmonic distortion characteristic of low-resolution audio.\n * 2. **Sample-rate reduction** - a phase-accumulator sample-and-hold circuit\n * re-latches the (quantized) input only `normFreq` times per input sample on\n * average, producing aliasing artefacts reminiscent of early digital hardware.\n *\n * The worklet emits a pure wet signal; dry/wet mixing is handled by the base\n * class.\n *\n * @example\n * ```ts\n * const bus = engine.createBus();\n * const crusher = new BitCrusherEffect({ bits: 4, frequencyReduction: 0.3, wet: 0.8 });\n * bus.addEffect(crusher);\n *\n * // Adjust at runtime:\n * crusher.bits = 2; // extreme quantization crunch\n * crusher.frequencyReduction = 0.1; // heavy downsampling aliasing\n * crusher.wet = 0.5; // blend with dry signal\n * ```\n */\nexport class BitCrusherEffect extends WorkletEffect {\n private _bits: number;\n private _frequencyReduction: number;\n\n public constructor(options: BitCrusherEffectOptions = {}) {\n super();\n this._bits = Math.round(Math.max(1, Math.min(16, options.bits ?? 8)));\n this._frequencyReduction = Math.max(0, Math.min(1, options.frequencyReduction ?? 0.5));\n this.wet = options.wet ?? 1;\n }\n\n protected get _workletName(): string {\n return 'exojs-bit-crusher';\n }\n protected get _workletSource(): string {\n return bitCrusherWorkletSource;\n }\n\n protected override _onWorkletReady(): void {\n this._setAudioParam('bits', this._bits);\n this._setAudioParam('normFreq', this._frequencyReduction);\n }\n\n /**\n * Bit depth for sample quantization. Lower values produce more distortion.\n * Range 1..16, default 8.\n */\n public get bits(): number {\n return this._bits;\n }\n public set bits(value: number) {\n this._bits = Math.round(Math.max(1, Math.min(16, value)));\n this._setAudioParam('bits', this._bits);\n }\n\n /**\n * Fraction of the sample rate retained (0 = never re-latch, 1 = every sample).\n * Lower values create more aliasing artefacts. Maps to the worklet `normFreq`\n * AudioParam. Range 0..1, default 0.5.\n */\n public get frequencyReduction(): number {\n return this._frequencyReduction;\n }\n public set frequencyReduction(value: number) {\n this._frequencyReduction = Math.max(0, Math.min(1, value));\n this._setAudioParam('normFreq', this._frequencyReduction);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,IAAa,mBAAb,cAAsC,cAAc;CAClD,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAAmC,CAAC,GAAG;EACxD,MAAM;EACN,KAAK,QAAQ,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,QAAQ,QAAQ,CAAC,CAAC,CAAC;EACpE,KAAK,sBAAsB,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,sBAAsB,EAAG,CAAC;EACrF,KAAK,MAAM,QAAQ,OAAO;CAC5B;CAEA,IAAc,eAAuB;EACnC,OAAO;CACT;CACA,IAAc,iBAAyB;EACrC,OAAOA;CACT;CAEA,AAAmB,kBAAwB;EACzC,KAAK,eAAe,QAAQ,KAAK,KAAK;EACtC,KAAK,eAAe,YAAY,KAAK,mBAAmB;CAC1D;;;;;CAMA,IAAW,OAAe;EACxB,OAAO,KAAK;CACd;CACA,IAAW,KAAK,OAAe;EAC7B,KAAK,QAAQ,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,CAAC;EACxD,KAAK,eAAe,QAAQ,KAAK,KAAK;CACxC;;;;;;CAOA,IAAW,qBAA6B;EACtC,OAAO,KAAK;CACd;CACA,IAAW,mBAAmB,OAAe;EAC3C,KAAK,sBAAsB,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,CAAC;EACzD,KAAK,eAAe,YAAY,KAAK,mBAAmB;CAC1D;AACF"}
@@ -1,54 +0,0 @@
1
- import { AudioEffect } from '@codexo/exojs';
2
- /** Construction options for {@link ChorusEffect}. */
3
- export interface ChorusEffectOptions {
4
- /** Base delay in ms. Typical 15-30ms. Default 25. */
5
- delayMs?: number;
6
- /** Modulation depth in ms (peak deviation from base). Default 5. */
7
- depthMs?: number;
8
- /** LFO rate in Hz. Typical 0.1-5Hz for chorus, 5-15Hz for vibrato. Default 1.5. */
9
- rateHz?: number;
10
- /** Dry/wet mix, 0..1. Default 0.5 (equal mix). */
11
- wet?: number;
12
- }
13
- /**
14
- * Chorus effect using native WebAudio nodes (no worklet required).
15
- *
16
- * The signal splits into a dry path and a wet path. The wet path passes
17
- * through a DelayNode whose delay time is modulated by a sine-wave LFO,
18
- * producing the characteristic pitch-wobble / thickening of chorus.
19
- *
20
- * Node graph:
21
- * ```
22
- * inputGain ┬── dryGain ────────────────┐
23
- * │ ├── outputGain
24
- * └── delayNode ── wetGain ────┘
25
- *
26
- * lfoOscillator ── lfoGain (depth) ── delayNode.delayTime
27
- * ```
28
- */
29
- export declare class ChorusEffect extends AudioEffect {
30
- private _nodes;
31
- private _delayMs;
32
- private readonly _onAudioContextReady;
33
- private _depthMs;
34
- private _rateHz;
35
- private _wet;
36
- constructor(options?: ChorusEffectOptions);
37
- get inputNode(): AudioNode;
38
- get outputNode(): AudioNode;
39
- /** Base delay time in milliseconds. Default 25. */
40
- get delayMs(): number;
41
- set delayMs(value: number);
42
- /** LFO modulation depth in milliseconds (peak deviation from base delay). Default 5. */
43
- get depthMs(): number;
44
- set depthMs(value: number);
45
- /** LFO oscillation rate in Hz. Typical chorus range is 0.1-5 Hz; 5-15 Hz produces a vibrato effect. Default 1.5. */
46
- get rateHz(): number;
47
- set rateHz(value: number);
48
- /** Wet (modulated) mix level, 0..1. The dry level is automatically `1 - wet`. Default 0.5. */
49
- get wet(): number;
50
- set wet(value: number);
51
- destroy(): void;
52
- private _setupNodes;
53
- }
54
- //# sourceMappingURL=ChorusEffect.d.ts.map
@@ -1 +0,0 @@
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,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IACF,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAS;IAErB,YAAmB,OAAO,GAAE,mBAAwB,EAWnD;IAED,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED,IAAW,UAAU,IAAI,SAAS,CAGjC;IAMD,mDAAmD;IACnD,IAAW,OAAO,IAAI,MAAM,CAE3B;IACD,IAAW,OAAO,CAAC,KAAK,EAAE,MAAM,EAK/B;IAED,wFAAwF;IACxF,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;CAyCpB"}
@@ -1,136 +0,0 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
2
-
3
- //#region src/effects/ChorusEffect.ts
4
- /**
5
- * Chorus effect using native WebAudio nodes (no worklet required).
6
- *
7
- * The signal splits into a dry path and a wet path. The wet path passes
8
- * through a DelayNode whose delay time is modulated by a sine-wave LFO,
9
- * producing the characteristic pitch-wobble / thickening of chorus.
10
- *
11
- * Node graph:
12
- * ```
13
- * inputGain ┬── dryGain ────────────────┐
14
- * │ ├── outputGain
15
- * └── delayNode ── wetGain ────┘
16
- *
17
- * lfoOscillator ── lfoGain (depth) ── delayNode.delayTime
18
- * ```
19
- */
20
- var ChorusEffect = class extends AudioEffect {
21
- _nodes = null;
22
- _delayMs;
23
- _onAudioContextReady = (ctx) => {
24
- onAudioContextReady.remove(this._onAudioContextReady);
25
- this._setupNodes(ctx);
26
- };
27
- _depthMs;
28
- _rateHz;
29
- _wet;
30
- constructor(options = {}) {
31
- super();
32
- this._delayMs = Math.max(0, options.delayMs ?? 25);
33
- this._depthMs = Math.max(0, options.depthMs ?? 5);
34
- this._rateHz = Math.max(0, options.rateHz ?? 1.5);
35
- this._wet = Math.max(0, Math.min(1, options.wet ?? .5));
36
- if (isAudioContextReady()) this._setupNodes(getAudioContext());
37
- else onAudioContextReady.add(this._onAudioContextReady);
38
- }
39
- get inputNode() {
40
- if (!this._nodes) throw new Error("ChorusEffect not yet initialized.");
41
- return this._nodes.inputGain;
42
- }
43
- get outputNode() {
44
- if (!this._nodes) throw new Error("ChorusEffect not yet initialized.");
45
- return this._nodes.outputGain;
46
- }
47
- /** Base delay time in milliseconds. Default 25. */
48
- get delayMs() {
49
- return this._delayMs;
50
- }
51
- set delayMs(value) {
52
- this._delayMs = Math.max(0, value);
53
- if (this._nodes) this._nodes.delayNode.delayTime.setTargetAtTime(this._delayMs / 1e3, this._nodes.delayNode.context.currentTime, .01);
54
- }
55
- /** LFO modulation depth in milliseconds (peak deviation from base delay). Default 5. */
56
- get depthMs() {
57
- return this._depthMs;
58
- }
59
- set depthMs(value) {
60
- this._depthMs = Math.max(0, value);
61
- if (this._nodes) this._nodes.lfoGain.gain.setTargetAtTime(this._depthMs / 1e3, this._nodes.lfoGain.context.currentTime, .01);
62
- }
63
- /** LFO oscillation rate in Hz. Typical chorus range is 0.1-5 Hz; 5-15 Hz produces a vibrato effect. Default 1.5. */
64
- get rateHz() {
65
- return this._rateHz;
66
- }
67
- set rateHz(value) {
68
- this._rateHz = Math.max(0, value);
69
- if (this._nodes) this._nodes.lfoOscillator.frequency.setTargetAtTime(this._rateHz, this._nodes.inputGain.context.currentTime, .01);
70
- }
71
- /** Wet (modulated) mix level, 0..1. The dry level is automatically `1 - wet`. Default 0.5. */
72
- get wet() {
73
- return this._wet;
74
- }
75
- set wet(value) {
76
- this._wet = Math.max(0, Math.min(1, value));
77
- if (this._nodes) {
78
- const ctx = this._nodes.wetGain.context;
79
- this._nodes.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
80
- this._nodes.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
81
- }
82
- }
83
- destroy() {
84
- onAudioContextReady.remove(this._onAudioContextReady);
85
- if (this._nodes) {
86
- this._nodes.lfoOscillator.stop();
87
- this._nodes.lfoOscillator.disconnect();
88
- this._nodes.lfoGain.disconnect();
89
- this._nodes.delayNode.disconnect();
90
- this._nodes.dryGain.disconnect();
91
- this._nodes.wetGain.disconnect();
92
- this._nodes.inputGain.disconnect();
93
- this._nodes.outputGain.disconnect();
94
- this._nodes = null;
95
- }
96
- }
97
- _setupNodes(ctx) {
98
- const inputGain = ctx.createGain();
99
- const outputGain = ctx.createGain();
100
- const dryGain = ctx.createGain();
101
- const wetGain = ctx.createGain();
102
- const maxDelay = (this._delayMs + this._depthMs) / 1e3 + .05;
103
- const delayNode = ctx.createDelay(maxDelay);
104
- const lfoGain = ctx.createGain();
105
- inputGain.gain.setValueAtTime(1, ctx.currentTime);
106
- outputGain.gain.setValueAtTime(1, ctx.currentTime);
107
- dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
108
- wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
109
- delayNode.delayTime.setValueAtTime(this._delayMs / 1e3, ctx.currentTime);
110
- lfoGain.gain.setValueAtTime(this._depthMs / 1e3, ctx.currentTime);
111
- const lfoOscillator = ctx.createOscillator();
112
- lfoOscillator.type = "sine";
113
- lfoOscillator.frequency.value = this._rateHz;
114
- lfoOscillator.connect(lfoGain);
115
- lfoGain.connect(delayNode.delayTime);
116
- inputGain.connect(dryGain);
117
- dryGain.connect(outputGain);
118
- inputGain.connect(delayNode);
119
- delayNode.connect(wetGain);
120
- wetGain.connect(outputGain);
121
- lfoOscillator.start();
122
- this._nodes = {
123
- inputGain,
124
- outputGain,
125
- dryGain,
126
- wetGain,
127
- delayNode,
128
- lfoOscillator,
129
- lfoGain
130
- };
131
- }
132
- };
133
-
134
- //#endregion
135
- export { ChorusEffect };
136
- //# sourceMappingURL=ChorusEffect.js.map
@@ -1 +0,0 @@
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,CAA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rB,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"}
@@ -1,56 +0,0 @@
1
- import { AudioEffect } from '@codexo/exojs';
2
- /** Construction options for {@link CompressorEffect}. All values are clamped to their valid ranges on assignment. */
3
- export interface CompressorEffectOptions {
4
- threshold?: number;
5
- knee?: number;
6
- ratio?: number;
7
- /** Time in seconds for the compressor to engage after the signal exceeds the threshold. Range 0..1, default 0.003. */
8
- attack?: number;
9
- /** Time in seconds for the compressor to disengage after the signal drops below the threshold. Range 0..1, default 0.25. */
10
- release?: number;
11
- }
12
- /**
13
- * Dynamic-range compressor backed by a Web Audio `DynamicsCompressorNode`.
14
- * Reduces the volume of loud signals above a threshold, evening out the
15
- * perceived loudness of a mix. All parameter changes are applied with a short
16
- * smoothing ramp so they are artifact-free during playback.
17
- */
18
- export declare class CompressorEffect extends AudioEffect {
19
- private _node;
20
- private _threshold;
21
- private readonly _onAudioContextReady;
22
- private _knee;
23
- private _ratio;
24
- private _attack;
25
- private _release;
26
- constructor(options?: CompressorEffectOptions);
27
- get inputNode(): AudioNode;
28
- get outputNode(): AudioNode;
29
- /** Level above which compression begins, in dBFS. Range −100..0, default −24. */
30
- get threshold(): number;
31
- set threshold(value: number);
32
- /** Width in dB of the transition region around the threshold (soft knee). Range 0..40, default 30. */
33
- get knee(): number;
34
- set knee(value: number);
35
- /** Input-to-output dB ratio above the threshold. Range 1..20, default 12. */
36
- get ratio(): number;
37
- set ratio(value: number);
38
- /** Time in seconds for the compressor to engage after the signal exceeds the threshold. Range 0..1, default 0.003. */
39
- get attack(): number;
40
- set attack(value: number);
41
- /** Time in seconds for the compressor to disengage after the signal drops below the threshold. Range 0..1, default 0.25. */
42
- get release(): number;
43
- set release(value: number);
44
- /**
45
- * Live gain reduction in dB applied by the compressor right now. Always
46
- * `<= 0` (or `0` when the compressor isn't engaging). Read-only - drive
47
- * input level meters / sidechain visualisations off this value.
48
- *
49
- * Returns `0` until the underlying node has been created (before the
50
- * audio context is ready).
51
- */
52
- get reduction(): number;
53
- destroy(): void;
54
- private _setup;
55
- }
56
- //# sourceMappingURL=CompressorEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CompressorEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/CompressorEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6D,MAAM,eAAe,CAAC;AAEvG,qHAAqH;AACrH,MAAM,WAAW,uBAAuB;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sHAAsH;IACtH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4HAA4H;IAC5H,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;IAC/C,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IACF,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;IAEzB,YAAmB,OAAO,GAAE,uBAA4B,EAYvD;IAED,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED,IAAW,UAAU,IAAI,SAAS,CAGjC;IAED,iFAAiF;IACjF,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,IAAW,SAAS,CAAC,KAAK,EAAE,MAAM,EAKjC;IAED,sGAAsG;IACtG,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAK5B;IAED,6EAA6E;IAC7E,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAK7B;IAED,sHAAsH;IACtH,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,MAAM,CAAC,KAAK,EAAE,MAAM,EAK9B;IAED,4HAA4H;IAC5H,IAAW,OAAO,IAAI,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,108 +0,0 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
2
-
3
- //#region src/effects/CompressorEffect.ts
4
- /**
5
- * Dynamic-range compressor backed by a Web Audio `DynamicsCompressorNode`.
6
- * Reduces the volume of loud signals above a threshold, evening out the
7
- * perceived loudness of a mix. All parameter changes are applied with a short
8
- * smoothing ramp so they are artifact-free during playback.
9
- */
10
- var CompressorEffect = class extends AudioEffect {
11
- _node = null;
12
- _threshold;
13
- _onAudioContextReady = (ctx) => {
14
- onAudioContextReady.remove(this._onAudioContextReady);
15
- this._setup(ctx);
16
- };
17
- _knee;
18
- _ratio;
19
- _attack;
20
- _release;
21
- constructor(options = {}) {
22
- super();
23
- this._threshold = Math.max(-100, Math.min(0, options.threshold ?? -24));
24
- this._knee = Math.max(0, Math.min(40, options.knee ?? 30));
25
- this._ratio = Math.max(1, Math.min(20, options.ratio ?? 12));
26
- this._attack = Math.max(0, Math.min(1, options.attack ?? .003));
27
- this._release = Math.max(0, Math.min(1, options.release ?? .25));
28
- if (isAudioContextReady()) this._setup(getAudioContext());
29
- else onAudioContextReady.add(this._onAudioContextReady);
30
- }
31
- get inputNode() {
32
- if (!this._node) throw new Error("CompressorEffect not yet initialized.");
33
- return this._node;
34
- }
35
- get outputNode() {
36
- if (!this._node) throw new Error("CompressorEffect not yet initialized.");
37
- return this._node;
38
- }
39
- /** Level above which compression begins, in dBFS. Range −100..0, default −24. */
40
- get threshold() {
41
- return this._threshold;
42
- }
43
- set threshold(value) {
44
- this._threshold = Math.max(-100, Math.min(0, value));
45
- if (this._node) this._node.threshold.setTargetAtTime(this._threshold, this._node.context.currentTime, .01);
46
- }
47
- /** Width in dB of the transition region around the threshold (soft knee). Range 0..40, default 30. */
48
- get knee() {
49
- return this._knee;
50
- }
51
- set knee(value) {
52
- this._knee = Math.max(0, Math.min(40, value));
53
- if (this._node) this._node.knee.setTargetAtTime(this._knee, this._node.context.currentTime, .01);
54
- }
55
- /** Input-to-output dB ratio above the threshold. Range 1..20, default 12. */
56
- get ratio() {
57
- return this._ratio;
58
- }
59
- set ratio(value) {
60
- this._ratio = Math.max(1, Math.min(20, value));
61
- if (this._node) this._node.ratio.setTargetAtTime(this._ratio, this._node.context.currentTime, .01);
62
- }
63
- /** Time in seconds for the compressor to engage after the signal exceeds the threshold. Range 0..1, default 0.003. */
64
- get attack() {
65
- return this._attack;
66
- }
67
- set attack(value) {
68
- this._attack = Math.max(0, Math.min(1, value));
69
- if (this._node) this._node.attack.setTargetAtTime(this._attack, this._node.context.currentTime, .01);
70
- }
71
- /** Time in seconds for the compressor to disengage after the signal drops below the threshold. Range 0..1, default 0.25. */
72
- get release() {
73
- return this._release;
74
- }
75
- set release(value) {
76
- this._release = Math.max(0, Math.min(1, value));
77
- if (this._node) this._node.release.setTargetAtTime(this._release, this._node.context.currentTime, .01);
78
- }
79
- /**
80
- * Live gain reduction in dB applied by the compressor right now. Always
81
- * `<= 0` (or `0` when the compressor isn't engaging). Read-only - drive
82
- * input level meters / sidechain visualisations off this value.
83
- *
84
- * Returns `0` until the underlying node has been created (before the
85
- * audio context is ready).
86
- */
87
- get reduction() {
88
- return this._node?.reduction ?? 0;
89
- }
90
- destroy() {
91
- onAudioContextReady.remove(this._onAudioContextReady);
92
- this._node?.disconnect();
93
- this._node = null;
94
- }
95
- _setup(ctx) {
96
- const node = ctx.createDynamicsCompressor();
97
- node.threshold.setValueAtTime(this._threshold, ctx.currentTime);
98
- node.knee.setValueAtTime(this._knee, ctx.currentTime);
99
- node.ratio.setValueAtTime(this._ratio, ctx.currentTime);
100
- node.attack.setValueAtTime(this._attack, ctx.currentTime);
101
- node.release.setValueAtTime(this._release, ctx.currentTime);
102
- this._node = node;
103
- }
104
- };
105
-
106
- //#endregion
107
- export { CompressorEffect };
108
- //# sourceMappingURL=CompressorEffect.js.map
@@ -1 +0,0 @@
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,YAAY;CAChD,AAAQ,QAAuC;CAC/C,AAAQ;CACR,AAAiB,wBAAwB,QAA4B;EACnE,oBAAoB,OAAO,KAAK,oBAAoB;EACpD,KAAK,OAAO,GAAG;CACjB;CACA,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,UAAmC,CAAC,GAAG;EACxD,MAAM;EACN,KAAK,aAAa,KAAK,IAAI,MAAM,KAAK,IAAI,GAAG,QAAQ,aAAa,GAAG,CAAC;EACtE,KAAK,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,QAAQ,QAAQ,EAAE,CAAC;EACzD,KAAK,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,QAAQ,SAAS,EAAE,CAAC;EAC3D,KAAK,UAAU,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,UAAU,IAAK,CAAC;EAC/D,KAAK,WAAW,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,WAAW,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Aa,GAAI;CAExF;;CAGA,IAAW,UAAkB;EAC3B,OAAO,KAAK;CACd;CAEA,IAAW,QAAQ,OAAe;EAChC,KAAK,WAAW,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,CAAC;EAC9C,IAAI,KAAK,OACP,KAAK,MAAM,QAAQ,gBAAgB,KAAK,UAAU,KAAK,MAAM,QAAQ,aAAa,GAAI;CAE1F;;;;;;;;;CAUA,IAAW,YAAoB;EAC7B,OAAO,KAAK,OAAO,aAAa;CAClC;CAEA,AAAgB,UAAgB;EAC9B,oBAAoB,OAAO,KAAK,oBAAoB;EACpD,KAAK,OAAO,WAAW;EACvB,KAAK,QAAQ;CACf;CAEA,AAAQ,OAAO,KAAyB;EACtC,MAAM,OAAO,IAAI,yBAAyB;EAC1C,KAAK,UAAU,eAAe,KAAK,YAAY,IAAI,WAAW;EAC9D,KAAK,KAAK,eAAe,KAAK,OAAO,IAAI,WAAW;EACpD,KAAK,MAAM,eAAe,KAAK,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,119 +0,0 @@
1
- import { AudioEffect, Sound } from '@codexo/exojs';
2
- /** Construction options for {@link ConvolutionEffect}. */
3
- export interface ConvolutionEffectOptions {
4
- /**
5
- * Impulse response. Accepts a decoded `AudioBuffer` or a `Sound` (its
6
- * `audioBuffer` is used). If omitted the effect runs dry (passthrough) until
7
- * {@link ConvolutionEffect.setImpulse} is called.
8
- */
9
- impulse?: AudioBuffer | Sound;
10
- /**
11
- * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 1.0.
12
- */
13
- wet?: number;
14
- /**
15
- * Maps to `ConvolverNode.normalize`. When `true` the browser applies an
16
- * equal-power normalization pass on the IR so different IRs play at a
17
- * consistent perceived loudness. Default `true` (the Web Audio spec default).
18
- *
19
- * **Note:** the Web Audio spec only respects `normalize` if it is set
20
- * *before* `buffer` is assigned. This class always writes `normalize` first.
21
- * Changing `normalize` at runtime while an IR is loaded re-assigns the
22
- * buffer so the new value takes effect.
23
- */
24
- normalize?: boolean;
25
- /**
26
- * Optional makeup gain multiplier applied to the wet path. Useful when the
27
- * IR is very quiet or very loud and `normalize` is off. Range 0..4,
28
- * default 1.
29
- */
30
- gain?: number;
31
- }
32
- /**
33
- * Convolution effect that convolves the input signal with a user-supplied
34
- * impulse response (IR). Unlike {@link ReverbEffect}, which generates a
35
- * procedural noise-based IR, `ConvolutionEffect` accepts a *real* decoded IR -
36
- * enabling convolution reverb from acoustic-space captures, cabinet/speaker
37
- * simulations, telephone/pipe character filtering, and any other linear
38
- * time-invariant transformation.
39
- *
40
- * Pass the IR as an `AudioBuffer` (typically decoded via
41
- * `AudioContext.decodeAudioData`) or as a `Sound` (its `audioBuffer` is used).
42
- * Omitting the IR leaves `convolver.buffer` as `null`, making the wet path
43
- * silent and the effect act as a passthrough until {@link setImpulse} is
44
- * called - safe to add to a bus before an IR is available.
45
- *
46
- * Node graph:
47
- * ```
48
- * input(GainNode) → dryGain → output(GainNode)
49
- * input → convolver → wetGain → output
50
- * ```
51
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet × gain`.
52
- *
53
- * @example
54
- * ```ts
55
- * const hall = await loader.load(Asset.type('sound', 'hall.wav'));
56
- * const reverb = new ConvolutionEffect({ impulse: hall, wet: 0.6 });
57
- * bus.addEffect(reverb);
58
- * ```
59
- */
60
- export declare class ConvolutionEffect extends AudioEffect {
61
- private _setup;
62
- private _wet;
63
- private _normalize;
64
- private _gain;
65
- private _pendingImpulse;
66
- /** Bumped per impulse request so a slow resample cannot overwrite a newer IR. */
67
- private _impulseGeneration;
68
- private readonly _onAudioContextReady;
69
- constructor(options?: ConvolutionEffectOptions);
70
- /**
71
- * The node where audio enters this effect. Throws if the audio context is
72
- * not yet initialized.
73
- */
74
- get inputNode(): AudioNode;
75
- /**
76
- * The node where audio exits this effect. Throws if the audio context is
77
- * not yet initialized.
78
- */
79
- get outputNode(): AudioNode;
80
- /**
81
- * Wet (convolved) mix level, 0..1. The dry level is automatically `1 - wet`.
82
- * Changes are ramped smoothly via `setTargetAtTime`. Default 1.0.
83
- */
84
- get wet(): number;
85
- set wet(value: number);
86
- /**
87
- * Whether the browser normalizes the IR for equal-power loudness. Mirrors
88
- * `ConvolverNode.normalize`. Default `true`.
89
- *
90
- * Changing this at runtime re-assigns the current buffer so the new value
91
- * takes effect (a Web Audio requirement: `normalize` is only applied on
92
- * buffer assignment).
93
- */
94
- get normalize(): boolean;
95
- set normalize(value: boolean);
96
- /**
97
- * Makeup gain multiplier applied to the wet path. Range 0..4, default 1.
98
- * Adjusting this changes the wet-path amplitude without altering the
99
- * dry/wet balance ratio.
100
- */
101
- get gain(): number;
102
- set gain(value: number);
103
- /**
104
- * Set or replace the impulse response. Accepts a decoded `AudioBuffer`, a
105
- * `Sound` (its `audioBuffer` is used), or `null` to clear the IR (wet path
106
- * goes silent). Safe to call before the audio context is ready - the impulse
107
- * is stored and applied once nodes are created.
108
- *
109
- * **Web Audio note:** `normalize` is written to the convolver *before*
110
- * `buffer` is assigned, as required by the spec for the value to take effect.
111
- */
112
- setImpulse(ir: AudioBuffer | Sound | null): void;
113
- /** Assign an IR that is known to match the context rate. */
114
- private _applyImpulse;
115
- destroy(): void;
116
- private _resolveBuffer;
117
- private _setupNodes;
118
- }
119
- //# sourceMappingURL=ConvolutionEffect.d.ts.map
@@ -1 +0,0 @@
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,GA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