@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,192 +0,0 @@
1
- /**
2
- * Autocorrelation-based tempogram (single source of truth).
3
- *
4
- * Given a novelty (onset-strength) curve sampled at rate `hopRate = sampleRate / hopSize`,
5
- * this module computes the autocorrelation function (ACF) over a sliding window and
6
- * selects the musically-correct tempo from the resulting periodicity peaks.
7
- *
8
- * The beat-detector worklet imports these functions directly; its bundle inlines them,
9
- * so there is one implementation. The worklet drives them from its own scratch buffers
10
- * rather than calling `computeTempoCandidates` - the audio thread cannot afford the
11
- * per-call allocation that convenience wrapper makes - which is why the allocating
12
- * entry points here are thin shells around out-parameter primitives.
13
- *
14
- * Octave disambiguation (the core fix)
15
- * ------------------------------------
16
- * The ACF of a periodic onset train peaks at the beat lag `p` AND at every sub-harmonic
17
- * lag `2p, 3p, ...` (every other beat also correlates). A naive "biggest peak" or additive
18
- * harmonic-comb picker therefore drifts down to the lowest in-range sub-harmonic. Three
19
- * mechanisms cooperate here to lock the true fundamental instead:
20
- *
21
- * 1. The novelty is mean-subtracted before correlation (removes the DC pedestal under
22
- * every lag) and the ACF uses the BIASED / zero-lag-normalised estimator (÷n, not
23
- * ÷(n−lag)) so long lags are gently tapered rather than inflated. [computeAcf]
24
- * 2. Each candidate `f` is scored by a periodicity comb over its own SUB-multiples
25
- * (`f`, `f/2`, `f/3` → lags `p, 2p, 3p`) MINUS a penalty for energy at its
26
- * SUPER-harmonics (`2f`, `3f` → lags `p/2, p/3`). A true fundamental has no
27
- * super-harmonic energy, so it keeps its full comb; a sub-harmonic candidate is
28
- * demoted because its super-harmonic (the real beat) is strong. Metrical support
29
- * therefore reinforces the fundamental rather than a lone sub-harmonic peak, over
30
- * the `{f/2, f, 2f, 3f}` family. [scoreTempoHypotheses]
31
- *
32
- * The super-harmonic penalty is SUBDIVISION-AWARE: a candidate `kf` (k = 2, 3) only
33
- * demotes `f` when `kf` could itself be the beat, i.e. `kf` lies within the tempo
34
- * band `[minBpm, maxBpm]`. Energy at a super-harmonic ABOVE `maxBpm` is a subdivision
35
- * (e.g. hi-hats on 8th-notes riding over a 180 BPM kick → strong energy at 360 BPM),
36
- * NOT a competing fundamental, so it must NOT penalise the true beat. Without this
37
- * gate a realistic kit pattern whose fundamental carries subdivision energy is wrongly
38
- * demoted in favour of an unrelated in-band multiple (180 → 120). Pure clicktracks
39
- * are unaffected: they have no super-harmonic energy, so the gate changes nothing.
40
- * 3. A soft log-Gaussian tempo prior centred on ~140 BPM breaks residual ties toward
41
- * the musical core (100-200 BPM) without hard-clamping the edges. [tempoPrior]
42
- */
43
- export interface TempoCandidateResult {
44
- /** BPM value. */
45
- bpm: number;
46
- /** Selection score (periodicity comb × tempo prior; not normalised to 0..1). */
47
- score: number;
48
- /** ACF lag in hops that produced this peak. */
49
- lag: number;
50
- }
51
- /** Tuning knobs for tempo-candidate scoring. Internal constants for now. */
52
- export interface TempoScoringOptions {
53
- /** Lowest BPM accepted as a candidate. */
54
- minBpm?: number;
55
- /** Highest BPM accepted as a candidate. */
56
- maxBpm?: number;
57
- /** Log-Gaussian prior centre (geometric mean of the precise band). */
58
- priorMu?: number;
59
- /** Log-Gaussian prior width in natural-log units. */
60
- priorSigma?: number;
61
- /** Number of candidates to return. */
62
- topK?: number;
63
- }
64
- /** Prior centre - geometric mean of the 100-200 BPM "precise" band. */
65
- export declare const defaultPriorMu = 140;
66
- /** Prior width: ≈ ±1 octave at ~0.6 weight. */
67
- export declare const defaultPriorSigma: number;
68
- /**
69
- * Relative tolerance on the candidate-acceptance BPM band. A tempo sitting exactly on
70
- * the edge (e.g. 300) has an ACF lag (18.75) that straddles the boundary; without slack
71
- * its peak can round just outside the band and be discarded.
72
- */
73
- export declare const candidateEdgeTolerance = 0.05;
74
- /** Periodicity-comb weights for a candidate's own sub-multiples (f, f/2, f/3). */
75
- export declare const combWeightFundamental = 1;
76
- export declare const combWeightHalf = 0.5;
77
- export declare const combWeightThird = 0.3;
78
- /** Super-harmonic penalty weights (2f, 3f) - strong evidence the candidate is a sub-harmonic. */
79
- export declare const combPenaltyDouble = 1;
80
- export declare const combPenaltyTriple = 0.5;
81
- /**
82
- * The ACF is computed down to a shorter lag than the candidate band needs, so that
83
- * (a) a high-BPM fundamental whose lag lands on `minLag` is an interior peak with its
84
- * true height, and (b) the 2f/3f super-harmonic penalty can read energy ABOVE maxBpm
85
- * (a sub-harmonic candidate's real beat). One third of `minLag` reaches the 3f lag of a
86
- * candidate at maxBpm.
87
- */
88
- export declare const acfExtendedMinLag: (minLag: number) => number;
89
- /**
90
- * Compute the normalised autocorrelation function over a novelty curve.
91
- *
92
- * The novelty is mean-subtracted (kills the DC pedestal under every lag), correlated with
93
- * the BIASED estimator (`sum / n`, not `sum / (n − lag)`) so long lags are tapered rather
94
- * than inflated, and normalised by the zero-lag energy (variance) so the output is in
95
- * roughly [-1, 1] with the strongest true period near 1.
96
- *
97
- * @param flux Recent novelty values (oldest first).
98
- * @param minLag Minimum lag in hops (inclusive).
99
- * @param maxLag Maximum lag in hops (inclusive).
100
- * @returns ACF array indexed by lag (index 0 = lag minLag).
101
- */
102
- export declare const computeAcf: (flux: Float32Array, minLag: number, maxLag: number) => Float32Array;
103
- /**
104
- * {@link computeAcf} writing into a caller-owned buffer.
105
- *
106
- * Separate from the allocating form because the AudioWorklet calls this once per ACF hop
107
- * on the audio thread, where a per-call `Float32Array` is unaffordable, and because it
108
- * reads only the first `n` entries of a longer scratch buffer instead of the whole array.
109
- *
110
- * @param flux Novelty scratch buffer; only `flux[0..n-1]` is read (oldest first).
111
- * @param n Number of valid novelty values in `flux`.
112
- * @param minLag Minimum lag in hops (inclusive).
113
- * @param maxLag Maximum lag in hops (inclusive).
114
- * @param out Receives `maxLag - minLag + 1` values, indexed by lag from `minLag`.
115
- */
116
- export declare const computeAcfInto: (flux: Float32Array, n: number, minLag: number, maxLag: number, out: Float32Array) => void;
117
- /**
118
- * Sample the ACF at an arbitrary (possibly fractional) lag with linear interpolation.
119
- * Returns 0 outside the computed lag range and clamps negative correlation to 0 so
120
- * anti-correlated harmonics never contribute to (or subtract spuriously from) a comb.
121
- */
122
- export declare const acfAtLag: (acf: Float32Array, minLag: number, lag: number) => number;
123
- /**
124
- * Sub-lag peak refinement. Fit a parabola through the three samples around an interior
125
- * local maximum (acf[i-1], acf[i], acf[i+1]) and return the vertex offset in [-0.5, 0.5].
126
- *
127
- * The lag grid is coarse at the top of the BPM band (a 300 BPM beat sits at lag ≈ 18.75
128
- * hops, ~5 ms / lag), so rounding a peak to its nearest integer lag costs several BPM.
129
- * Interpolating the vertex recovers sub-hop BPM resolution without shrinking the hop.
130
- * Returns 0 when the three points are not strictly concave (cannot happen for a genuine
131
- * strict local maximum, but guards floating-point edge cases).
132
- */
133
- export declare const parabolicPeakOffset: (yPrev: number, yMid: number, yNext: number) => number;
134
- /**
135
- * Find all positive local-maxima peaks in the ACF and convert lags to BPM candidates.
136
- *
137
- * Includes the two array endpoints when they exceed their single in-range neighbour
138
- * (the true high-BPM period can land on minLag, which has no left neighbour). Interior
139
- * maxima are refined to a fractional lag by {@link parabolicPeakOffset} for sub-hop BPM
140
- * resolution; endpoints keep their integer lag (they lack a neighbour to interpolate
141
- * against). Sorted by raw ACF score descending; pass `topK = acf.length` to retain every peak.
142
- *
143
- * @param acf Normalised ACF from `computeAcf`.
144
- * @param minLag The lag (in hops) corresponding to acf[0].
145
- * @param hopSize Number of audio samples per hop.
146
- * @param sampleRate Audio sample rate in Hz.
147
- * @param topK Number of peaks to return (default 3).
148
- */
149
- export declare const findTempoPeaks: (acf: Float32Array, minLag: number, hopSize: number, sampleRate: number, topK?: number) => TempoCandidateResult[];
150
- /** Soft log-Gaussian tempo prior: 1 at `mu`, decaying symmetrically in log-BPM. */
151
- export declare const tempoPrior: (bpm: number, mu?: number, sigma?: number) => number;
152
- /**
153
- * Re-score raw ACF peaks into musically-disambiguated tempo candidates.
154
- *
155
- * For each candidate fundamental `f` (lag `p`):
156
- * support = 1.0·ACF(p) + 0.5·ACF(2p) + 0.3·ACF(3p) // its own sub-multiples (f, f/2, f/3)
157
- * penalty = 1.0·ACF(p/2)[if 2f ≤ maxBpm] + 0.5·ACF(p/3)[if 3f ≤ maxBpm] // super-harmonics
158
- * comb = max(0, support − penalty)
159
- * score = comb · prior(bpm)
160
- *
161
- * The penalty is what defeats the octave-down bias: a sub-harmonic candidate has a strong
162
- * super-harmonic (the real beat), so it is demoted; the true fundamental has no
163
- * super-harmonic energy and keeps its full comb.
164
- *
165
- * The penalty is gated to be SUBDIVISION-AWARE: a super-harmonic
166
- * `kf` only counts against `f` when `kf` is itself a plausible beat (`kf ≤ maxBpm`). Energy
167
- * at a super-harmonic above the tempo band is a subdivision (e.g. hats on 8th-notes over a
168
- * 180 BPM kick), not a competing fundamental, and must not demote the true beat. Returns
169
- * candidates sorted by score.
170
- */
171
- export declare const scoreTempoHypotheses: (peaks: TempoCandidateResult[], acf: Float32Array, minLag: number, options?: TempoScoringOptions) => TempoCandidateResult[];
172
- /**
173
- * Full tempo-candidate pipeline: ACF → peaks → comb + super-harmonic penalty + prior.
174
- *
175
- * This is the single function the worklet mirrors and `worklet-parity.test.ts` checks.
176
- *
177
- * @param flux Recent novelty values (oldest first).
178
- * @param minLag Minimum candidate lag in hops (inclusive); the ACF itself extends below it.
179
- * @param maxLag Maximum lag in hops (inclusive).
180
- * @param hopSize Audio samples per hop.
181
- * @param sampleRate Audio sample rate in Hz.
182
- */
183
- export declare const computeTempoCandidates: (flux: Float32Array, minLag: number, maxLag: number, hopSize: number, sampleRate: number, options?: TempoScoringOptions) => TempoCandidateResult[];
184
- /**
185
- * True when `bpm` is a metrically-related multiple of `reference` - a ½×, 2×, 3× or ⅓×
186
- * octave, OR a 3:2 / 2:3 (dotted ↔ triple) relative. Switching across any of these needs the
187
- * stronger hysteresis margin: they are the same beat counted at a different metrical level
188
- * (e.g. 180 BPM kick vs the 120 BPM "dotted" grouping its 8th-note subdivisions create), not
189
- * a genuine tempo change.
190
- */
191
- export declare const isOctaveRelated: (bpm: number, reference: number) => boolean;
192
- //# sourceMappingURL=tempogram.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tempogram.d.ts","sourceRoot":"","sources":["../../../src/dsp/tempogram.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,MAAM,WAAW,oBAAoB;IACnC,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;CACb;AAED,4EAA4E;AAC5E,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sE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F;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,UACxB,oBAAoB,EAAE,OACxB,YAAY,UACT,MAAM,YACL,mBAAmB,KAC3B,oBAAoB,EA0BtB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,SAC3B,YAAY,UACV,MAAM,UACN,MAAM,WACL,MAAM,cACH,MAAM,YACT,mBAAmB,KAC3B,oBAAoB,EAatB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,QAAS,MAAM,aAAa,MAAM,KAAG,OAWhE,CAAC"}
@@ -1,128 +0,0 @@
1
- import { AudioEffect } from '@codexo/exojs';
2
- /** Construction options for {@link AutoWahEffect}. */
3
- export interface AutoWahEffectOptions {
4
- /**
5
- * Centre frequency of the wah bandpass filter in Hz. The envelope control
6
- * signal sweeps the filter upward from this base. Range 50..2000, default 200.
7
- */
8
- baseFrequency?: number;
9
- /**
10
- * Envelope sensitivity: Hz of filter-frequency sweep added per unit of
11
- * rectified envelope amplitude. At full signal amplitude the filter shifts up
12
- * by this amount above `baseFrequency`. Range 0..6000, default 3000.
13
- */
14
- sensitivity?: number;
15
- /**
16
- * Q (resonance) of the bandpass wah filter. Higher values produce a narrower,
17
- * more pronounced peak. Range 0.1..20, default 4.
18
- */
19
- q?: number;
20
- /**
21
- * Envelope smoothing time constant in milliseconds. Longer values make the
22
- * wah react slowly (legato); shorter values produce a snappier attack
23
- * (percussive). Translated to the smoothing lowpass cutoff as
24
- * `1000 / (2π × responseMs)` Hz. Range 1..500, default 30.
25
- */
26
- responseMs?: number;
27
- /**
28
- * Dry/wet mix, 0..1. The dry level is automatically `1 - wet`. Default 0.7.
29
- */
30
- wet?: number;
31
- }
32
- /**
33
- * Auto-wah effect that uses an amplitude envelope follower to modulate a
34
- * bandpass filter, creating the characteristic "wah" sweep driven by the
35
- * loudness of the input signal.
36
- *
37
- * The envelope follower is built entirely from native Web Audio nodes - no
38
- * `ScriptProcessor` or `AudioWorklet` required:
39
- *
40
- * 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),
41
- * converting the AC audio signal to a unipolar amplitude proxy.
42
- * 2. A `BiquadFilterNode` (lowpass) smooths the rectified signal. The cutoff is
43
- * derived from `responseMs` to control attack/release speed.
44
- * 3. A `GainNode` scales the smoothed envelope by `sensitivity` (Hz/unit) and
45
- * connects its output directly to the wah filter's `frequency` `AudioParam`,
46
- * sweeping the filter centre upward with input loudness.
47
- *
48
- * Node graph:
49
- * ```
50
- * inputGain ─┬─ dryGain ─────────────────────────────┐
51
- * │ ├── outputGain
52
- * └─ wahFilter(bandpass) ─── wetGain ──────┘
53
- *
54
- * Envelope (control) path - parallel off inputGain, sums into wahFilter.frequency:
55
- * inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)
56
- * → sensitivityGain → wahFilter.frequency (AudioParam)
57
- * ```
58
- *
59
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
60
- *
61
- * @example
62
- * ```ts
63
- * const wah = new AutoWahEffect({ baseFrequency: 300, sensitivity: 2500, wet: 0.8 });
64
- * bus.addEffect(wah);
65
- * ```
66
- */
67
- export declare class AutoWahEffect extends AudioEffect {
68
- private _setup;
69
- private _baseFrequency;
70
- private _sensitivity;
71
- private _q;
72
- private _responseMs;
73
- private _wet;
74
- private readonly _onAudioContextReady;
75
- constructor(options?: AutoWahEffectOptions);
76
- /**
77
- * The node where audio enters this effect. Throws if the audio context is
78
- * not yet initialized.
79
- */
80
- get inputNode(): AudioNode;
81
- /**
82
- * The node where audio exits this effect. Throws if the audio context is
83
- * not yet initialized.
84
- */
85
- get outputNode(): AudioNode;
86
- /**
87
- * Centre frequency of the wah filter in Hz. Range 50..2000, default 200.
88
- * Changes are ramped smoothly via `setTargetAtTime`.
89
- */
90
- get baseFrequency(): number;
91
- set baseFrequency(value: number);
92
- /**
93
- * Envelope sensitivity in Hz/unit: the maximum filter sweep above
94
- * `baseFrequency` when input is at full amplitude. Range 0..6000, default 3000.
95
- * Changes are ramped smoothly via `setTargetAtTime`.
96
- */
97
- get sensitivity(): number;
98
- set sensitivity(value: number);
99
- /**
100
- * Q (resonance) of the bandpass wah filter. Range 0.1..20, default 4.
101
- * Changes are ramped smoothly via `setTargetAtTime`.
102
- */
103
- get q(): number;
104
- set q(value: number);
105
- /**
106
- * Envelope smoothing time constant in milliseconds. Range 1..500, default 30.
107
- * Updating this adjusts the smoothing lowpass cutoff immediately via
108
- * `setTargetAtTime`.
109
- */
110
- get responseMs(): number;
111
- set responseMs(value: number);
112
- /**
113
- * Wet (wah-filtered) mix level, 0..1. The dry level is automatically
114
- * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 0.7.
115
- */
116
- get wet(): number;
117
- set wet(value: number);
118
- destroy(): void;
119
- /** Converts `responseMs` to a lowpass cutoff frequency using f = 1/(2π×τ). */
120
- private _smoothingCutoff;
121
- /**
122
- * Builds a 256-point `Float32Array` curve approximating the full-wave
123
- * rectifier `f(x) = |x|` for use with `WaveShaperNode`.
124
- */
125
- private static _makeRectifierCurve;
126
- private _setupNodes;
127
- }
128
- //# sourceMappingURL=AutoWahEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AutoWahEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/AutoWahEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6D,MAAM,eAAe,CAAC;AAEvG,sDAAsD;AACtD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAaD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC5C,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGnC;IAEF,YAAmB,OAAO,GAAE,oBAAyB,EAYpD;IAED;;;OAGG;IACH,IAAW,SAAS,IAAI,SAAS,CAGhC;IAED;;;OAGG;IACH,IAAW,UAAU,IAAI,SAAS,CAGjC;IAMD;;;OAGG;IACH,IAAW,aAAa,IAAI,MAAM,CAEjC;IAED,IAAW,aAAa,CAAC,KAAK,EAAE,MAAM,EAKrC;IAED;;;;OAIG;IACH,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED,IAAW,WAAW,CAAC,KAAK,EAAE,MAAM,EAKnC;IAED;;;OAGG;IACH,IAAW,CAAC,IAAI,MAAM,CAErB;IAED,IAAW,CAAC,CAAC,KAAK,EAAE,MAAM,EAKzB;IAED;;;;OAIG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED,IAAW,UAAU,CAAC,KAAK,EAAE,MAAM,EAKlC;IAED;;;OAGG;IACH,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED,IAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAO3B;IAMe,OAAO,IAAI,IAAI,CAa9B;IAMD,8EAA8E;IAC9E,OAAO,CAAC,gBAAgB;IAIxB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAUlC,OAAO,CAAC,WAAW;CA4DpB"}
@@ -1,214 +0,0 @@
1
- import { AudioEffect, getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
2
-
3
- //#region src/effects/AutoWahEffect.ts
4
- /**
5
- * Auto-wah effect that uses an amplitude envelope follower to modulate a
6
- * bandpass filter, creating the characteristic "wah" sweep driven by the
7
- * loudness of the input signal.
8
- *
9
- * The envelope follower is built entirely from native Web Audio nodes - no
10
- * `ScriptProcessor` or `AudioWorklet` required:
11
- *
12
- * 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),
13
- * converting the AC audio signal to a unipolar amplitude proxy.
14
- * 2. A `BiquadFilterNode` (lowpass) smooths the rectified signal. The cutoff is
15
- * derived from `responseMs` to control attack/release speed.
16
- * 3. A `GainNode` scales the smoothed envelope by `sensitivity` (Hz/unit) and
17
- * connects its output directly to the wah filter's `frequency` `AudioParam`,
18
- * sweeping the filter centre upward with input loudness.
19
- *
20
- * Node graph:
21
- * ```
22
- * inputGain ─┬─ dryGain ─────────────────────────────┐
23
- * │ ├── outputGain
24
- * └─ wahFilter(bandpass) ─── wetGain ──────┘
25
- *
26
- * Envelope (control) path - parallel off inputGain, sums into wahFilter.frequency:
27
- * inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)
28
- * → sensitivityGain → wahFilter.frequency (AudioParam)
29
- * ```
30
- *
31
- * Gains: `dryGain.gain = 1 - wet`; `wetGain.gain = wet`.
32
- *
33
- * @example
34
- * ```ts
35
- * const wah = new AutoWahEffect({ baseFrequency: 300, sensitivity: 2500, wet: 0.8 });
36
- * bus.addEffect(wah);
37
- * ```
38
- */
39
- var AutoWahEffect = class AutoWahEffect extends AudioEffect {
40
- _setup = null;
41
- _baseFrequency;
42
- _sensitivity;
43
- _q;
44
- _responseMs;
45
- _wet;
46
- _onAudioContextReady = (ctx) => {
47
- onAudioContextReady.remove(this._onAudioContextReady);
48
- this._setupNodes(ctx);
49
- };
50
- constructor(options = {}) {
51
- super();
52
- this._baseFrequency = Math.max(50, Math.min(2e3, options.baseFrequency ?? 200));
53
- this._sensitivity = Math.max(0, Math.min(6e3, options.sensitivity ?? 3e3));
54
- this._q = Math.max(.1, Math.min(20, options.q ?? 4));
55
- this._responseMs = Math.max(1, Math.min(500, options.responseMs ?? 30));
56
- this._wet = Math.max(0, Math.min(1, options.wet ?? .7));
57
- if (isAudioContextReady()) this._setupNodes(getAudioContext());
58
- else onAudioContextReady.add(this._onAudioContextReady);
59
- }
60
- /**
61
- * The node where audio enters this effect. Throws if the audio context is
62
- * not yet initialized.
63
- */
64
- get inputNode() {
65
- if (!this._setup) throw new Error("AutoWahEffect not yet initialized.");
66
- return this._setup.inputGain;
67
- }
68
- /**
69
- * The node where audio exits this effect. Throws if the audio context is
70
- * not yet initialized.
71
- */
72
- get outputNode() {
73
- if (!this._setup) throw new Error("AutoWahEffect not yet initialized.");
74
- return this._setup.outputGain;
75
- }
76
- /**
77
- * Centre frequency of the wah filter in Hz. Range 50..2000, default 200.
78
- * Changes are ramped smoothly via `setTargetAtTime`.
79
- */
80
- get baseFrequency() {
81
- return this._baseFrequency;
82
- }
83
- set baseFrequency(value) {
84
- this._baseFrequency = Math.max(50, Math.min(2e3, value));
85
- if (this._setup) this._setup.wahFilter.frequency.setTargetAtTime(this._baseFrequency, this._setup.wahFilter.context.currentTime, .01);
86
- }
87
- /**
88
- * Envelope sensitivity in Hz/unit: the maximum filter sweep above
89
- * `baseFrequency` when input is at full amplitude. Range 0..6000, default 3000.
90
- * Changes are ramped smoothly via `setTargetAtTime`.
91
- */
92
- get sensitivity() {
93
- return this._sensitivity;
94
- }
95
- set sensitivity(value) {
96
- this._sensitivity = Math.max(0, Math.min(6e3, value));
97
- if (this._setup) this._setup.sensitivityGain.gain.setTargetAtTime(this._sensitivity, this._setup.sensitivityGain.context.currentTime, .01);
98
- }
99
- /**
100
- * Q (resonance) of the bandpass wah filter. Range 0.1..20, default 4.
101
- * Changes are ramped smoothly via `setTargetAtTime`.
102
- */
103
- get q() {
104
- return this._q;
105
- }
106
- set q(value) {
107
- this._q = Math.max(.1, Math.min(20, value));
108
- if (this._setup) this._setup.wahFilter.Q.setTargetAtTime(this._q, this._setup.wahFilter.context.currentTime, .01);
109
- }
110
- /**
111
- * Envelope smoothing time constant in milliseconds. Range 1..500, default 30.
112
- * Updating this adjusts the smoothing lowpass cutoff immediately via
113
- * `setTargetAtTime`.
114
- */
115
- get responseMs() {
116
- return this._responseMs;
117
- }
118
- set responseMs(value) {
119
- this._responseMs = Math.max(1, Math.min(500, value));
120
- if (this._setup) this._setup.smoothingLowpass.frequency.setTargetAtTime(this._smoothingCutoff(), this._setup.smoothingLowpass.context.currentTime, .01);
121
- }
122
- /**
123
- * Wet (wah-filtered) mix level, 0..1. The dry level is automatically
124
- * `1 - wet`. Changes are ramped smoothly via `setTargetAtTime`. Default 0.7.
125
- */
126
- get wet() {
127
- return this._wet;
128
- }
129
- set wet(value) {
130
- this._wet = Math.max(0, Math.min(1, value));
131
- if (this._setup) {
132
- const ctx = this._setup.wetGain.context;
133
- this._setup.wetGain.gain.setTargetAtTime(this._wet, ctx.currentTime, .01);
134
- this._setup.dryGain.gain.setTargetAtTime(1 - this._wet, ctx.currentTime, .01);
135
- }
136
- }
137
- destroy() {
138
- onAudioContextReady.remove(this._onAudioContextReady);
139
- if (this._setup) {
140
- this._setup.inputGain.disconnect();
141
- this._setup.dryGain.disconnect();
142
- this._setup.wetGain.disconnect();
143
- this._setup.sensitivityGain.disconnect();
144
- this._setup.wahFilter.disconnect();
145
- this._setup.smoothingLowpass.disconnect();
146
- this._setup.rectifier.disconnect();
147
- this._setup.outputGain.disconnect();
148
- this._setup = null;
149
- }
150
- }
151
- /** Converts `responseMs` to a lowpass cutoff frequency using f = 1/(2π×τ). */
152
- _smoothingCutoff() {
153
- return 1e3 / (2 * Math.PI * this._responseMs);
154
- }
155
- /**
156
- * Builds a 256-point `Float32Array` curve approximating the full-wave
157
- * rectifier `f(x) = |x|` for use with `WaveShaperNode`.
158
- */
159
- static _makeRectifierCurve() {
160
- const n = 256;
161
- const curve = new Float32Array(n);
162
- for (let i = 0; i < n; i++) {
163
- const x = i * 2 / 255 - 1;
164
- curve[i] = Math.abs(x);
165
- }
166
- return curve;
167
- }
168
- _setupNodes(ctx) {
169
- const inputGain = ctx.createGain();
170
- const outputGain = ctx.createGain();
171
- const dryGain = ctx.createGain();
172
- const wetGain = ctx.createGain();
173
- const sensitivityGain = ctx.createGain();
174
- const wahFilter = ctx.createBiquadFilter();
175
- const smoothingLowpass = ctx.createBiquadFilter();
176
- const rectifier = ctx.createWaveShaper();
177
- inputGain.gain.setValueAtTime(1, ctx.currentTime);
178
- outputGain.gain.setValueAtTime(1, ctx.currentTime);
179
- dryGain.gain.setValueAtTime(1 - this._wet, ctx.currentTime);
180
- wetGain.gain.setValueAtTime(this._wet, ctx.currentTime);
181
- sensitivityGain.gain.setValueAtTime(this._sensitivity, ctx.currentTime);
182
- wahFilter.type = "bandpass";
183
- wahFilter.frequency.setValueAtTime(this._baseFrequency, ctx.currentTime);
184
- wahFilter.Q.setValueAtTime(this._q, ctx.currentTime);
185
- rectifier.curve = AutoWahEffect._makeRectifierCurve();
186
- rectifier.oversample = "4x";
187
- smoothingLowpass.type = "lowpass";
188
- smoothingLowpass.frequency.setValueAtTime(this._smoothingCutoff(), ctx.currentTime);
189
- smoothingLowpass.Q.setValueAtTime(.5, ctx.currentTime);
190
- inputGain.connect(dryGain);
191
- dryGain.connect(outputGain);
192
- inputGain.connect(wahFilter);
193
- wahFilter.connect(wetGain);
194
- wetGain.connect(outputGain);
195
- inputGain.connect(rectifier);
196
- rectifier.connect(smoothingLowpass);
197
- smoothingLowpass.connect(sensitivityGain);
198
- sensitivityGain.connect(wahFilter.frequency);
199
- this._setup = {
200
- inputGain,
201
- outputGain,
202
- dryGain,
203
- wetGain,
204
- sensitivityGain,
205
- wahFilter,
206
- smoothingLowpass,
207
- rectifier
208
- };
209
- }
210
- };
211
-
212
- //#endregion
213
- export { AutoWahEffect };
214
- //# sourceMappingURL=AutoWahEffect.js.map
@@ -1 +0,0 @@
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 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;C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,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,64 +0,0 @@
1
- import { WorkletEffect } from '@codexo/exojs';
2
- export interface BitCrusherEffectOptions {
3
- /**
4
- * Bit depth for sample quantization. Lower values produce coarser steps and
5
- * more distortion. Range 1..16, default 8.
6
- */
7
- bits?: number;
8
- /**
9
- * Fraction of the sample rate retained (sample-and-hold). A value of 1 means
10
- * every sample is re-latched (no rate reduction). A value of 0.5 halves the
11
- * effective sample rate, introducing aliasing. Range 0..1, default 0.5.
12
- * Maps directly to the worklet `normFreq` AudioParam.
13
- */
14
- frequencyReduction?: number;
15
- /** Dry/wet mix, 0..1. Default 1. */
16
- wet?: number;
17
- }
18
- /**
19
- * Lo-fi bit-crusher effect implemented as a {@link WorkletEffect}. Applies two
20
- * classic degradation stages in series:
21
- *
22
- * 1. **Bit-depth reduction** - each sample is quantized to `2^bits` discrete
23
- * levels, adding harmonic distortion characteristic of low-resolution audio.
24
- * 2. **Sample-rate reduction** - a phase-accumulator sample-and-hold circuit
25
- * re-latches the (quantized) input only `normFreq` times per input sample on
26
- * average, producing aliasing artefacts reminiscent of early digital hardware.
27
- *
28
- * The worklet emits a pure wet signal; dry/wet mixing is handled by the base
29
- * class.
30
- *
31
- * @example
32
- * ```ts
33
- * const bus = engine.createBus();
34
- * const crusher = new BitCrusherEffect({ bits: 4, frequencyReduction: 0.3, wet: 0.8 });
35
- * bus.addEffect(crusher);
36
- *
37
- * // Adjust at runtime:
38
- * crusher.bits = 2; // extreme quantization crunch
39
- * crusher.frequencyReduction = 0.1; // heavy downsampling aliasing
40
- * crusher.wet = 0.5; // blend with dry signal
41
- * ```
42
- */
43
- export declare class BitCrusherEffect extends WorkletEffect {
44
- private _bits;
45
- private _frequencyReduction;
46
- constructor(options?: BitCrusherEffectOptions);
47
- protected get _workletName(): string;
48
- protected get _workletSource(): string;
49
- protected _onWorkletReady(): void;
50
- /**
51
- * Bit depth for sample quantization. Lower values produce more distortion.
52
- * Range 1..16, default 8.
53
- */
54
- get bits(): number;
55
- set bits(value: number);
56
- /**
57
- * Fraction of the sample rate retained (0 = never re-latch, 1 = every sample).
58
- * Lower values create more aliasing artefacts. Maps to the worklet `normFreq`
59
- * AudioParam. Range 0..1, default 0.5.
60
- */
61
- get frequencyReduction(): number;
62
- set frequencyReduction(value: number);
63
- }
64
- //# sourceMappingURL=BitCrusherEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BitCrusherEffect.d.ts","sourceRoot":"","sources":["../../../src/effects/BitCrusherEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,mBAAmB,CAAS;IAEpC,YAAmB,OAAO,GAAE,uBAA4B,EAKvD;IAED,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;IACD,SAAS,KAAK,cAAc,IAAI,MAAM,CAErC;IAED,UAAmB,eAAe,IAAI,IAAI,CAGzC;IAED;;;OAGG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IACD,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAG5B;IAED;;;;OAIG;IACH,IAAW,kBAAkB,IAAI,MAAM,CAEtC;IACD,IAAW,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAG1C;CACF"}