cacophony 0.37.0 → 0.39.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 (229) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +62 -26
  3. package/dist/bandGainStage.cjs +2 -0
  4. package/dist/bandGainStage.cjs.map +1 -0
  5. package/dist/bandGainStage.d.ts +49 -0
  6. package/dist/bandGainStage.mjs +64 -0
  7. package/dist/bandGainStage.mjs.map +1 -0
  8. package/dist/bandGains.cjs +2 -0
  9. package/dist/bandGains.cjs.map +1 -0
  10. package/dist/bandGains.d.ts +81 -0
  11. package/dist/bandGains.mjs +129 -0
  12. package/dist/bandGains.mjs.map +1 -0
  13. package/dist/basePlayback.cjs +1 -1
  14. package/dist/basePlayback.cjs.map +1 -1
  15. package/dist/basePlayback.d.ts +9 -0
  16. package/dist/basePlayback.mjs +7 -1
  17. package/dist/basePlayback.mjs.map +1 -1
  18. package/dist/bundles/fdn-reverb-bundle.js_url.cjs +1 -1
  19. package/dist/bundles/fdn-reverb-bundle.js_url.cjs.map +1 -1
  20. package/dist/bundles/fdn-reverb-bundle.js_url.mjs +1 -1
  21. package/dist/bundles/fdn-reverb-bundle.js_url.mjs.map +1 -1
  22. package/dist/cli/commands.cjs +1 -1
  23. package/dist/cli/commands.cjs.map +1 -1
  24. package/dist/cli/commands.mjs +30 -30
  25. package/dist/cli/commands.mjs.map +1 -1
  26. package/dist/cli/effects-registry.cjs +1 -1
  27. package/dist/cli/effects-registry.cjs.map +1 -1
  28. package/dist/cli/effects-registry.d.ts +1 -4
  29. package/dist/cli/effects-registry.mjs +26 -26
  30. package/dist/cli/effects-registry.mjs.map +1 -1
  31. package/dist/cli/repl.cjs +1 -1
  32. package/dist/cli/repl.cjs.map +1 -1
  33. package/dist/cli/repl.mjs +132 -132
  34. package/dist/cli/repl.mjs.map +1 -1
  35. package/dist/cli/replay.cjs +1 -1
  36. package/dist/cli/replay.cjs.map +1 -1
  37. package/dist/cli/replay.mjs +38 -38
  38. package/dist/cli/replay.mjs.map +1 -1
  39. package/dist/context.d.ts +5 -0
  40. package/dist/effects.cjs +1 -1
  41. package/dist/effects.cjs.map +1 -1
  42. package/dist/effects.d.ts +13 -4
  43. package/dist/effects.mjs +79 -67
  44. package/dist/effects.mjs.map +1 -1
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.d.ts +4 -1
  47. package/dist/index.mjs +22 -20
  48. package/dist/playback.cjs +1 -1
  49. package/dist/playback.cjs.map +1 -1
  50. package/dist/playback.d.ts +102 -18
  51. package/dist/playback.mjs +144 -63
  52. package/dist/playback.mjs.map +1 -1
  53. package/dist/processors/fdn-reverb-core.cjs +2 -0
  54. package/dist/processors/fdn-reverb-core.cjs.map +1 -0
  55. package/dist/processors/fdn-reverb-core.mjs +8 -0
  56. package/dist/processors/fdn-reverb-core.mjs.map +1 -0
  57. package/dist/reflections.cjs +2 -0
  58. package/dist/reflections.cjs.map +1 -0
  59. package/dist/reflections.d.ts +38 -0
  60. package/dist/reflections.mjs +78 -0
  61. package/dist/reflections.mjs.map +1 -0
  62. package/dist/routableSource.cjs +1 -1
  63. package/dist/routableSource.cjs.map +1 -1
  64. package/dist/routableSource.d.ts +2 -0
  65. package/dist/routableSource.mjs +3 -3
  66. package/dist/routableSource.mjs.map +1 -1
  67. package/dist/sound.cjs +1 -1
  68. package/dist/sound.cjs.map +1 -1
  69. package/dist/sound.mjs +3 -5
  70. package/dist/sound.mjs.map +1 -1
  71. package/docs/assets/hierarchy.js +1 -1
  72. package/docs/assets/navigation.js +1 -1
  73. package/docs/assets/search.js +1 -1
  74. package/docs/classes/AudioCache.html +4 -4
  75. package/docs/classes/AudioSprite.html +7 -7
  76. package/docs/classes/BarberpoleEffect.html +7 -7
  77. package/docs/classes/BiquadEffect.html +3 -3
  78. package/docs/classes/Bus.html +21 -21
  79. package/docs/classes/Cacophony.html +92 -92
  80. package/docs/classes/DynamicsEffect.html +7 -7
  81. package/docs/classes/FdnReverbEffect.html +19 -16
  82. package/docs/classes/FoaDecoder.html +5 -5
  83. package/docs/classes/FoaDecoderEffect.html +3 -3
  84. package/docs/classes/FrequencyShifterEffect.html +7 -7
  85. package/docs/classes/Group.html +33 -33
  86. package/docs/classes/HarmonizerEffect.html +7 -7
  87. package/docs/classes/ImpulseResponseEffect.html +3 -3
  88. package/docs/classes/KWeightingFilter.html +4 -4
  89. package/docs/classes/LoudnessMeter.html +11 -11
  90. package/docs/classes/MediaStreamPlayback.html +103 -73
  91. package/docs/classes/MediaStreamSound.html +55 -53
  92. package/docs/classes/MicrophoneStream.html +56 -54
  93. package/docs/classes/ModulatedDelayEffect.html +7 -7
  94. package/docs/classes/PcmStreamPlayback.html +103 -73
  95. package/docs/classes/PcmStreamSound.html +65 -63
  96. package/docs/classes/PhaserEffect.html +7 -7
  97. package/docs/classes/Playback.html +270 -143
  98. package/docs/classes/ReverbEffect.html +7 -7
  99. package/docs/classes/Scheduler.html +3 -3
  100. package/docs/classes/ShareEffect.html +3 -3
  101. package/docs/classes/Sound.html +76 -74
  102. package/docs/classes/SpectralFreezeEffect.html +7 -7
  103. package/docs/classes/StereoWidenerEffect.html +3 -3
  104. package/docs/classes/Synth.html +66 -64
  105. package/docs/classes/SynthGroup.html +28 -28
  106. package/docs/classes/TremoloEffect.html +7 -7
  107. package/docs/classes/TruePeakDetector.html +8 -8
  108. package/docs/classes/WaveshaperEffect.html +7 -7
  109. package/docs/functions/encodeMonoToFoaSN3D.html +1 -1
  110. package/docs/functions/integratedLoudness.html +1 -1
  111. package/docs/functions/integratedUngatedLoudness.html +1 -1
  112. package/docs/functions/loudnessRange.html +1 -1
  113. package/docs/functions/timeStretch.html +1 -1
  114. package/docs/functions/timeStretchChannels.html +1 -1
  115. package/docs/functions/truePeakDb.html +1 -1
  116. package/docs/hierarchy.html +30 -29
  117. package/docs/index.html +49 -24
  118. package/docs/interfaces/AudioBuffer.html +8 -8
  119. package/docs/interfaces/AudioBufferSourceNode.html +22 -22
  120. package/docs/interfaces/AudioEventCallbacks.html +2 -2
  121. package/docs/interfaces/AudioListener.html +12 -12
  122. package/docs/interfaces/AudioNode.html +15 -14
  123. package/docs/interfaces/AudioParam.html +7 -7
  124. package/docs/interfaces/AudioWorklet.html +2 -2
  125. package/docs/interfaces/AudioWorkletNode.html +16 -16
  126. package/docs/interfaces/BarberpoleOptions.html +5 -5
  127. package/docs/interfaces/BaseContext.html +43 -27
  128. package/docs/interfaces/BaseSound.html +16 -16
  129. package/docs/interfaces/BiquadCoefficients.html +6 -6
  130. package/docs/interfaces/BiquadFilterNode.html +20 -20
  131. package/docs/interfaces/BuiltEffectGraph.html +6 -6
  132. package/docs/interfaces/CacheErrorEvent.html +5 -5
  133. package/docs/interfaces/CacheHitEvent.html +4 -4
  134. package/docs/interfaces/CacheMissEvent.html +4 -4
  135. package/docs/interfaces/CacophonyEffect.html +2 -2
  136. package/docs/interfaces/CacophonyLogger.html +4 -4
  137. package/docs/interfaces/ChannelMergerNode.html +14 -14
  138. package/docs/interfaces/ChannelSplitterNode.html +14 -14
  139. package/docs/interfaces/ConvolverNode.html +16 -16
  140. package/docs/interfaces/CreateSpriteOptions.html +3 -3
  141. package/docs/interfaces/DelayNode.html +248 -0
  142. package/docs/interfaces/DeviceChangeEvent.html +3 -3
  143. package/docs/interfaces/DynamicsOptions.html +7 -7
  144. package/docs/interfaces/FadeStartEvent.html +4 -4
  145. package/docs/interfaces/FdnReverbOptions.html +15 -19
  146. package/docs/interfaces/FoaDecoderOptions.html +2 -2
  147. package/docs/interfaces/FrequencyShifterOptions.html +3 -3
  148. package/docs/interfaces/GainNode.html +15 -15
  149. package/docs/interfaces/GlobalPlaybackEvent.html +3 -3
  150. package/docs/interfaces/HarmonizerOptions.html +6 -6
  151. package/docs/interfaces/ImpulseResponseOptions.html +5 -5
  152. package/docs/interfaces/LoadingCompleteEvent.html +5 -5
  153. package/docs/interfaces/LoadingErrorEvent.html +5 -5
  154. package/docs/interfaces/LoadingProgressEvent.html +6 -6
  155. package/docs/interfaces/LoadingStartEvent.html +3 -3
  156. package/docs/interfaces/LoudnessChannelInput.html +3 -3
  157. package/docs/interfaces/LoudnessReading.html +5 -5
  158. package/docs/interfaces/MediaElementSourceNode.html +15 -15
  159. package/docs/interfaces/MediaStreamAudioSourceNode.html +15 -15
  160. package/docs/interfaces/MediaStreamSoundOptions.html +5 -5
  161. package/docs/interfaces/MicrophoneStreamOptions.html +8 -8
  162. package/docs/interfaces/ModulatedDelayOptions.html +8 -8
  163. package/docs/interfaces/OfflineOptions.html +5 -5
  164. package/docs/interfaces/OscillatorNode.html +20 -20
  165. package/docs/interfaces/PannerNode.html +28 -28
  166. package/docs/interfaces/PcmStreamBufferEvent.html +2 -2
  167. package/docs/interfaces/PcmStreamSoundOptions.html +6 -6
  168. package/docs/interfaces/PhaserOptions.html +7 -7
  169. package/docs/interfaces/PlayOptions.html +13 -13
  170. package/docs/interfaces/PlaybackErrorEvent.html +5 -5
  171. package/docs/interfaces/PrepareSeekOptions.html +3 -3
  172. package/docs/interfaces/ReflectionImage.html +84 -0
  173. package/docs/interfaces/ReverbOptions.html +13 -13
  174. package/docs/interfaces/RuntimeOptions.html +8 -8
  175. package/docs/interfaces/ScheduledCallbackHandle.html +2 -2
  176. package/docs/interfaces/SendGainOptions.html +3 -3
  177. package/docs/interfaces/SoundCleanupHoldings.html +4 -4
  178. package/docs/interfaces/SoundErrorEvent.html +6 -6
  179. package/docs/interfaces/SpectralFreezeOptions.html +4 -4
  180. package/docs/interfaces/SpriteRegion.html +4 -4
  181. package/docs/interfaces/StereoPannerNode.html +15 -15
  182. package/docs/interfaces/StereoToBFormatOptions.html +2 -2
  183. package/docs/interfaces/StereoWidenerOptions.html +4 -4
  184. package/docs/interfaces/StreamCapabilities.html +5 -5
  185. package/docs/interfaces/TimeStretchOptions.html +5 -5
  186. package/docs/interfaces/TremoloOptions.html +5 -5
  187. package/docs/interfaces/WaveshaperOptions.html +5 -5
  188. package/docs/modules.html +4 -4
  189. package/docs/types/AudioSinkId.html +1 -1
  190. package/docs/types/BaseAudioEvents.html +11 -11
  191. package/docs/types/BuiltEffect.html +1 -1
  192. package/docs/types/BusConnectionTarget.html +1 -1
  193. package/docs/types/CacheEventCallback.html +1 -1
  194. package/docs/types/CacophonyEvents.html +20 -20
  195. package/docs/types/ErrorEventCallback.html +1 -1
  196. package/docs/types/FadeType.html +1 -1
  197. package/docs/types/HrtfPannerOptions.html +1 -1
  198. package/docs/types/ImpulseResponseSource.html +1 -1
  199. package/docs/types/LoadingEventCallback.html +1 -1
  200. package/docs/types/LoopCount.html +1 -1
  201. package/docs/types/LoudnessChannel.html +1 -1
  202. package/docs/types/Orientation.html +3 -3
  203. package/docs/types/PanCloneOverrides.html +6 -6
  204. package/docs/types/PanType.html +1 -1
  205. package/docs/types/PcmStreamEvents.html +6 -6
  206. package/docs/types/PcmStreamState.html +1 -1
  207. package/docs/types/PlaybackEvents.html +1 -1
  208. package/docs/types/Position.html +1 -1
  209. package/docs/types/SoundEvents.html +1 -1
  210. package/docs/types/SoundType.html +1 -1
  211. package/docs/types/SourceNode.html +1 -1
  212. package/docs/types/SpriteMap.html +1 -1
  213. package/docs/types/SynthEvents.html +1 -1
  214. package/docs/types/ThreeDOptions.html +1 -1
  215. package/docs/types/WebCodecsStreamSound.html +1 -1
  216. package/docs/variables/CHANNEL_WEIGHTS.html +1 -1
  217. package/docs/variables/K_WEIGHTING_STAGE1_48K.html +1 -1
  218. package/docs/variables/K_WEIGHTING_STAGE2_48K.html +1 -1
  219. package/docs/variables/MAX_REFLECTION_DELAY.html +35 -0
  220. package/docs/variables/OCTAVE_BAND_CENTERS.html +35 -0
  221. package/docs/variables/OCTAVE_BAND_COUNT.html +35 -0
  222. package/docs/variables/consoleLogger.html +1 -1
  223. package/docs/variables/noopLogger.html +1 -1
  224. package/package.json +1 -1
  225. package/dist/occlusion.cjs +0 -2
  226. package/dist/occlusion.cjs.map +0 -1
  227. package/dist/occlusion.d.ts +0 -19
  228. package/dist/occlusion.mjs +0 -41
  229. package/dist/occlusion.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -17,6 +17,28 @@ someone upgrading, not as a commit message. `npm version` stamps the release; se
17
17
 
18
18
  ## [Unreleased]
19
19
 
20
+ ## [0.39.0] - 2026-11-29
21
+
22
+ ### Changed
23
+ - `Playback.outputNode` is now a unity node after the volume node rather than the volume node itself; it still carries the full voice (direct sound and early-reflection images) and is what `connect`, `disconnect` and primary routes use. Volume and fades now apply ahead of the band stage and panner, which changes nothing in steady state; in Chromium a fade reaches the output after the HRTF panner's latency (about 6 ms).
24
+
25
+ ### Fixed
26
+ - Aux sends (`routeTo(bus, gain)`) no longer carry a voice's early-reflection images. They carry the direct path after volume, fades, band gains and panning, so a room reverb on a send is driven by the direct sound only, while the images stay heard dry. Before, the images were fed into the reverb as well as heard: in a 3.8 x 5.1 x 2.4 m room the tail was up to 9.5 dB too loud in some octave bands and kept the listener's early-reflection comb for its whole length.
27
+
28
+ ## [0.38.0] - 2026-11-28
29
+
30
+ ### ⚠ Breaking
31
+ - `Playback.setOcclusion(amount, duration)` and `Playback.occlusion` are removed, together with their fixed curve (a low-pass closing to 800 Hz with up to -18 dB). Use `Playback.setBandGains(gains, durationMs)`, which takes one linear gain per octave band and has no attenuation floor; `Playback.bandGains` reports the last request. A flat obstruction of the old maximum level is `setBandGains(new Array(8).fill(10 ** (-18 / 20)))`.
32
+ - `createFdnReverb` takes `decayTimes`, eight reverberation times in seconds (0.001 to 20), one per octave band of `OCTAVE_BAND_CENTERS`, instead of `decayTime` and `damping`. A former `{ decayTime: 2 }` is `{ decayTimes: new Array(8).fill(2) }`; shorten the high bands for the darker tail `damping` used to give. Values outside the range or of the wrong length throw `RangeError`. The worklet's `decayTime` and `damping` AudioParams are replaced by `decayTime125` … `decayTime16000`.
33
+ - The CLI `reverb` effect takes `decay` (every band) and `decay125` … `decay16000` (one band) instead of `decayTime` and `damping`.
34
+
35
+ ### Added
36
+ - `OCTAVE_BAND_CENTERS` (125 Hz to 16 kHz) and `OCTAVE_BAND_COUNT`, the band set used by every band-gain and band-decay API.
37
+ - `Playback.setBandGains(gains, durationMs = 50)` renders per-band attenuation for one voice, such as air absorption or a wall, within 1 dB at each band center above -30 dB, gliding without zipper noise.
38
+ - `createFdnReverb({ decayTimes })` decays each octave band at its own rate: every delay line's absorption filter is designed so each band loses 60 dB over its own reverberation time (Schlecht and Habets, 2017). Measured decay times are within 10% of the request for profiles spanning 20:1 across the bands.
39
+ - `Playback.setPlaybackRate(rate, durationMs = 0)` glides a decoded buffer's rate linearly while `currentTime` stays exact. The `playbackRate` setter is the immediate form.
40
+ - `Playback.setReflections(images, durationMs = 50)` adds early reflections: delayed, filtered copies of a voice, each panned from its own position. `MAX_REFLECTION_DELAY` (1 s) bounds the delay, and the `ReflectionImage` type describes one image.
41
+
20
42
  ## [0.37.0] - 2026-10-18
21
43
 
22
44
  ### Added
@@ -1451,7 +1473,9 @@ _0.1.0–0.1.2 were published to npm but not tagged; this block covers everythin
1451
1473
  - Sounds loaded from URLs are cached with the browser Cache API (`CacheManager`), and concurrent loads of the same URL are de-duplicated.
1452
1474
  - `Playback.fadeIn()` and `Playback.fadeOut()` with `'linear'` or `'exponential'` fades.
1453
1475
 
1454
- [Unreleased]: https://github.com/ctoth/cacophony/compare/v0.37.0...HEAD
1476
+ [Unreleased]: https://github.com/ctoth/cacophony/compare/v0.39.0...HEAD
1477
+ [0.39.0]: https://github.com/ctoth/cacophony/compare/v0.38.0...v0.39.0
1478
+ [0.38.0]: https://github.com/ctoth/cacophony/compare/v0.37.0...v0.38.0
1455
1479
  [0.37.0]: https://github.com/ctoth/cacophony/compare/v0.36.0...v0.37.0
1456
1480
  [0.36.0]: https://github.com/ctoth/cacophony/compare/v0.35.0...v0.36.0
1457
1481
  [0.35.0]: https://github.com/ctoth/cacophony/compare/v0.34.0...v0.35.0
package/README.md CHANGED
@@ -81,36 +81,66 @@ async function audioDemo() {
81
81
  audioDemo();
82
82
  ```
83
83
 
84
- ## Per-playback occlusion
84
+ ## Per-playback band gains
85
85
 
86
- Apply obstruction to an individual `Playback` using a normalized amount:
86
+ Shape an individual `Playback` with one linear gain per octave band, for example
87
+ air absorption over the path or transmission through an obstacle:
87
88
 
88
89
  ```typescript
90
+ import { OCTAVE_BAND_CENTERS } from 'cacophony'; // [125, 250, 500, 1000, 2000, 4000, 8000, 16000]
91
+
89
92
  const [voice] = sound.play({ panType: 'HRTF', position: [5, 0, 0] });
90
- voice.setOcclusion(0.7); // Smooth transition over 50 ms by default.
91
- voice.setOcclusion(0, 100); // Restore the clear path over 100 ms.
92
- console.log(voice.occlusion); // Last requested amount, independent of transition progress.
93
+ voice.setBandGains([1, 1, 1, 0.94, 0.89, 0.71, 0.3, 0.015]); // Glides over 50 ms by default.
94
+ voice.setBandGains(new Array(8).fill(0.056), 100); // -25 dB in every band over 100 ms.
95
+ console.log(voice.bandGains); // Last requested gains, independent of transition progress.
93
96
  ```
94
97
 
95
- The caller computes the amount and owns geometry, materials, and policy.
96
- Cacophony renders it with a dedicated low-pass and attenuation stage after user
97
- effects and before the panner. Finite amounts clamp to `[0, 1]`; non-finite
98
- amounts throw `RangeError`. The optional transition duration is in milliseconds:
99
- `0` applies immediately; negative or non-finite durations throw `RangeError`.
100
-
101
- At `0`, the low-pass opens to the context's Nyquist frequency and attenuation
102
- returns to unity, restoring the unobstructed response. At `1`, the low-pass
103
- cutoff is 800 Hz (limited to Nyquist on lower-rate contexts) and attenuation is
104
- -18 dB. Intermediate amounts map logarithmically to cutoff and linearly in
105
- decibels to attenuation. The filter has a Butterworth response without a resonant
106
- peak. Changes use linear AudioParam ramps, cancelling and re-anchoring any prior
107
- occlusion transition at its current value.
108
-
109
- Occlusion leaves ordinary volume and fades independent. Each voice starts clear;
110
- updates affect only that voice. Pause/resume and panner changes retain its
111
- occlusion, and `Playback.clone()` copies the requested amount into independent
112
- nodes. One lazily allocated filter/gain pair is reused even after resetting to
113
- `0`, then disconnected on cleanup. Updating a cleaned-up playback throws.
98
+ The caller computes the gains and owns geometry, materials, and policy.
99
+ `gains` holds exactly eight finite values in `[0, 1]`, one per band of
100
+ `OCTAVE_BAND_CENTERS`; anything else throws `RangeError`, as does a negative or
101
+ non-finite duration (milliseconds, `0` applies immediately).
102
+
103
+ Cacophony renders the gains after user effects and before the panner with a
104
+ broadband gain carrying the common level and a cascade of a low shelf, six
105
+ peaking filters and a high shelf. The section gains are solved on every call so
106
+ the response at each band center is within 1 dB of the target wherever the
107
+ target is above -30 dB (an interaction-corrected cascade graphic equalizer after
108
+ Välimäki and Liski, 2017); bands at or below -30 dB render at or below -30 dB.
109
+ Below 125 Hz and above 16 kHz the response follows the end shelves instead of
110
+ returning to unity. Changes use linear AudioParam ramps, re-anchored at their
111
+ current values when interrupted.
112
+
113
+ Band gains leave ordinary volume and fades independent. Each voice starts with
114
+ all gains at 1; the stage is allocated on the first call with any other gain,
115
+ reused after a return to all ones (which is transparent), kept through
116
+ pause/resume and panner changes, copied into independent nodes by
117
+ `Playback.clone()`, and disconnected on cleanup.
118
+
119
+ ## Per-playback early reflections
120
+
121
+ Add mirrored copies of a voice, each heard from its own position after its own
122
+ delay, with its own gain and band gains:
123
+
124
+ ```typescript
125
+ voice.setReflections([
126
+ { position: [5, 0, -6], delay: 0.012, gain: 0.4, bandGains: [0.95, 0.93, 0.9, 0.88, 0.85, 0.8, 0.7, 0.5] },
127
+ { position: [-3, 0, 2], delay: 0.018, gain: 0.3, bandGains: [0.9, 0.9, 0.85, 0.8, 0.75, 0.7, 0.6, 0.5] },
128
+ ]);
129
+ voice.setReflections([]); // Remove them.
130
+ ```
131
+
132
+ Each image taps the voice after its effects and before its band stage and
133
+ panner, then passes a delay (0 to `MAX_REFLECTION_DELAY`, 1 s), the same band
134
+ cascade as `setBandGains` with `gain` as an extra broadband factor, and its own
135
+ `PannerNode`, and joins the voice's output, so volume and fades apply. Aux sends
136
+ (`routeTo(bus, gain)`) carry the direct path only: the images are heard dry and
137
+ never feed a reverb bus, so a room reverb is driven by the direct sound, as a
138
+ real room's reverberant field is driven by the source. The image
139
+ panner applies no distance attenuation; `gain` carries it. Positions use the same
140
+ frame as the listener and the voice. Image panners take the voice's panning
141
+ model when it is HRTF-panned and equal-power panning otherwise. An update with
142
+ the same image count ramps delays, positions and gains in place; a different
143
+ count rebuilds the images. Each image costs a delay, eight biquads and a panner.
114
144
 
115
145
  ## Mobile Autoplay Handling
116
146
 
@@ -462,8 +492,13 @@ sound.playbackRate = 0.5; // Half speed (lower pitch)
462
492
  // Apply to individual playback
463
493
  const [playback] = sound.play();
464
494
  playback.playbackRate = 1.25;
495
+ playback.setPlaybackRate(1.5, 200); // Glide to 1.5 over 200 ms (decoded buffers).
465
496
  ```
466
497
 
498
+ `setPlaybackRate(rate, durationMs)` ramps a decoded buffer's rate linearly;
499
+ `currentTime`, pause and looping integrate the rate through the ramp, so the
500
+ reported position stays exact. HTML media sources take the new rate at once.
501
+
467
502
  ### Looping
468
503
 
469
504
  ```typescript
@@ -925,8 +960,9 @@ function draw() {
925
960
 
926
961
  ### Architecture Notes
927
962
 
928
- - **Internal chain**: `source → panner → [filters] → gainNode`
929
- - **outputNode** exposes the final `gainNode` in this chain
963
+ - **Internal chain**: `source → [filters/effects] → gainNode (volume, fades) → [band stage] → panner → direct tap → output`; early-reflection images branch after `gainNode` and join `output`
964
+ - **outputNode** exposes `output`, the full voice (direct sound and images)
965
+ - Aux sends (`routeTo(bus, gain)`) tap the direct path after volume, fades, band stage and panner, without the images
930
966
  - Default routing: `outputNode → globalGainNode → destination`
931
967
  - Calling `disconnect()` breaks the default routing, allowing full manual control
932
968
 
@@ -0,0 +1,2 @@
1
+ const e=require("./bandGains.cjs");var t=class{context;params;start;target;startTime=0;endTime=0;constructor(e,t,n){this.context=e,this.params=t,this.start=Float64Array.from(n),this.target=Float64Array.from(n),t.forEach((e,t)=>{e.value=n[t]})}current(){let e=this.context.currentTime,t=this.endTime<=e?1:Math.max(0,(e-this.startTime)/(this.endTime-this.startTime));return this.start.map((e,n)=>e+(this.target[n]-e)*t)}rampTo(e,t){let n=this.context.currentTime,r=this.current();this.start.set(r),this.target.set(Array.from(e)),this.startTime=n,this.endTime=n+t/1e3,this.params.forEach((e,i)=>{e.cancelScheduledValues(n),t<=0?e.setValueAtTime(this.target[i],n):(e.setValueAtTime(r[i],n),e.linearRampToValueAtTime(this.target[i],this.endTime))})}cancel(){let e=this.context.currentTime;for(let t of this.params)t.cancelScheduledValues(e)}},n=class{context;input;filters;ramps;sectionGainsDb=new Float64Array(8);output;constructor(n,r){this.context=n,this.input=n.createGain(),this.filters=e.BAND_SECTIONS.map(e=>{let t=n.createBiquadFilter();return t.type=e.type,t.frequency.value=Math.min(e.frequency,n.sampleRate/2),t.Q.value=e.Q,t});let i=this.input;for(let e of this.filters)i.connect(e),i=e;this.ramps=new t(n,[this.input.gain,...this.filters.map(e=>e.gain)],[1,...this.sectionGainsDb]),r&&this.setOutput(r)}get tail(){return this.filters[this.filters.length-1]}setOutput(e){e!==this.output&&(this.output&&this.tail.disconnect(this.output),this.output=e,this.tail.connect(e))}setGains(t,n,r=1){let i=e.designBandGains(t.map(t=>e.linearToDb(t*r)),this.context.sampleRate,-36,this.sectionGainsDb);this.sectionGainsDb=i.sectionGainsDb;let a=i.levelDb===-1/0?0:10**(i.levelDb/20);this.ramps.rampTo([a,...i.sectionGainsDb],n)}destroy(){this.ramps.cancel(),this.input.disconnect();for(let e of this.filters)e.disconnect()}};exports.BandGainStage=n,exports.TrackedRamps=t;
2
+ //# sourceMappingURL=bandGainStage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bandGainStage.cjs","names":[],"sources":["../src/bandGainStage.ts"],"sourcesContent":["import { BAND_SECTIONS, designBandGains, linearToDb, OCTAVE_BAND_COUNT } from \"./bandGains\";\nimport type { AudioNode, AudioParam, BaseContext, BiquadFilterNode, GainNode } from \"./context\";\n\n/**\n * Rendered response at a band whose target is at or below -30 dB is designed at\n * this level, so it stays at or below -30 dB while section gains stay bounded.\n */\nexport const BAND_FLOOR_DB = -36;\n\n/**\n * @internal Owned linear ramps of several AudioParams that can be interrupted.\n * cancelScheduledValues removes a ramp's endpoint and AudioParam.value cannot\n * reliably recover an interrupted ramp, so start and target values are tracked.\n */\nexport class TrackedRamps {\n private readonly start: Float64Array;\n private readonly target: Float64Array;\n private startTime = 0;\n private endTime = 0;\n\n constructor(\n private readonly context: BaseContext,\n private readonly params: AudioParam[],\n initial: ArrayLike<number>,\n ) {\n this.start = Float64Array.from(initial);\n this.target = Float64Array.from(initial);\n params.forEach((param, i) => {\n param.value = initial[i];\n });\n }\n\n /** The value each param holds now on its current ramp. */\n current(): Float64Array {\n const now = this.context.currentTime;\n const fraction = this.endTime <= now ? 1 : Math.max(0, (now - this.startTime) / (this.endTime - this.startTime));\n return this.start.map((s, i) => s + (this.target[i] - s) * fraction);\n }\n\n /** Ramp every param from its current value to `values` over `durationMs` (0 = immediate). */\n rampTo(values: ArrayLike<number>, durationMs: number): void {\n const now = this.context.currentTime;\n const from = this.current();\n this.start.set(from);\n this.target.set(Array.from(values));\n this.startTime = now;\n this.endTime = now + durationMs / 1000;\n this.params.forEach((param, i) => {\n param.cancelScheduledValues(now);\n if (durationMs <= 0) {\n param.setValueAtTime(this.target[i], now);\n } else {\n param.setValueAtTime(from[i], now);\n param.linearRampToValueAtTime(this.target[i], this.endTime);\n }\n });\n }\n\n cancel(): void {\n const now = this.context.currentTime;\n for (const param of this.params) param.cancelScheduledValues(now);\n }\n}\n\n/**\n * @internal A broadband gain followed by the eight-section band cascade of\n * {@link designBandGains}. Section gains and the level glide with linear\n * AudioParam ramps (dB for sections, linear amplitude for the level).\n */\nexport class BandGainStage {\n /** Head of the stage; connect the signal here. */\n readonly input: GainNode;\n private readonly filters: BiquadFilterNode[];\n private readonly ramps: TrackedRamps;\n private sectionGainsDb = new Float64Array(OCTAVE_BAND_COUNT);\n private output?: AudioNode;\n\n constructor(\n private readonly context: BaseContext,\n output?: AudioNode,\n ) {\n this.input = context.createGain();\n this.filters = BAND_SECTIONS.map((section) => {\n const filter = context.createBiquadFilter();\n filter.type = section.type;\n filter.frequency.value = Math.min(section.frequency, context.sampleRate / 2);\n filter.Q.value = section.Q;\n return filter;\n });\n let previous: AudioNode = this.input;\n for (const filter of this.filters) {\n previous.connect(filter);\n previous = filter;\n }\n this.ramps = new TrackedRamps(\n context,\n [this.input.gain, ...this.filters.map((f) => f.gain)],\n [1, ...this.sectionGainsDb],\n );\n if (output) this.setOutput(output);\n }\n\n /** Tail of the stage (the last section). */\n get tail(): AudioNode {\n return this.filters[this.filters.length - 1];\n }\n\n setOutput(output: AudioNode): void {\n if (output === this.output) return;\n if (this.output) this.tail.disconnect(this.output);\n this.output = output;\n this.tail.connect(output);\n }\n\n /**\n * Render linear per-band gains (any non-negative values) over `durationMs`.\n * `scale` multiplies every band (an image's distance gain, for example).\n */\n setGains(gains: readonly number[], durationMs: number, scale = 1): void {\n const targetDb = gains.map((g) => linearToDb(g * scale));\n const design = designBandGains(targetDb, this.context.sampleRate, BAND_FLOOR_DB, this.sectionGainsDb);\n this.sectionGainsDb = design.sectionGainsDb;\n const level = design.levelDb === Number.NEGATIVE_INFINITY ? 0 : 10 ** (design.levelDb / 20);\n this.ramps.rampTo([level, ...design.sectionGainsDb], durationMs);\n }\n\n destroy(): void {\n this.ramps.cancel();\n this.input.disconnect();\n for (const filter of this.filters) filter.disconnect();\n }\n}\n"],"mappings":"mCAcA,IAAa,EAAb,KAA0B,CAOL,QACA,OAPnB,MACA,OACA,UAAoB,EACpB,QAAkB,EAElB,YACE,EACA,EACA,EACA,CAHiB,KAAA,QAAA,EACA,KAAA,OAAA,EAGjB,KAAK,MAAQ,aAAa,KAAK,CAAO,EACtC,KAAK,OAAS,aAAa,KAAK,CAAO,EACvC,EAAO,SAAS,EAAO,IAAM,CAC3B,EAAM,MAAQ,EAAQ,EACxB,CAAC,CACH,CAGA,SAAwB,CACtB,IAAM,EAAM,KAAK,QAAQ,YACnB,EAAW,KAAK,SAAW,EAAM,EAAI,KAAK,I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AAQ,IAAK,GAAM,EAAE,IAAI,CAAC,EACpD,CAAC,EAAG,GAAG,KAAK,cAAc,CAC5B,EACI,GAAQ,KAAK,UAAU,CAAM,CACnC,CAGA,IAAI,MAAkB,CACpB,OAAO,KAAK,QAAQ,KAAK,QAAQ,OAAS,EAC5C,CAEA,UAAU,EAAyB,CAC7B,IAAW,KAAK,SAChB,KAAK,QAAQ,KAAK,KAAK,WAAW,KAAK,MAAM,EACjD,KAAK,OAAS,EACd,KAAK,KAAK,QAAQ,CAAM,EAC1B,CAMA,SAAS,EAA0B,EAAoB,EAAQ,EAAS,CAEtE,IAAM,EAAS,EAAA,gBADE,EAAM,IAAK,GAAM,EAAA,WAAW,EAAI,CAAK,CACvB,EAAU,KAAK,QAAQ,WAAA,IAA2B,KAAK,cAAc,EACpG,KAAK,eAAiB,EAAO,eAC7B,IAAM,EAAQ,EAAO,UAAY,KAA2B,EAAI,KAAO,EAAO,QAAU,IACxF,KAAK,MAAM,OAAO,CAAC,EAAO,GAAG,EAAO,cAAc,EAAG,CAAU,CACjE,CAEA,SAAgB,CACd,KAAK,MAAM,OAAO,EAClB,KAAK,MAAM,WAAW,EACtB,IAAK,IAAM,KAAU,KAAK,QAAS,EAAO,WAAW,CACvD,CACF"}
@@ -0,0 +1,49 @@
1
+ import { AudioNode, AudioParam, BaseContext, GainNode } from './context';
2
+ /**
3
+ * Rendered response at a band whose target is at or below -30 dB is designed at
4
+ * this level, so it stays at or below -30 dB while section gains stay bounded.
5
+ */
6
+ export declare const BAND_FLOOR_DB = -36;
7
+ /**
8
+ * @internal Owned linear ramps of several AudioParams that can be interrupted.
9
+ * cancelScheduledValues removes a ramp's endpoint and AudioParam.value cannot
10
+ * reliably recover an interrupted ramp, so start and target values are tracked.
11
+ */
12
+ export declare class TrackedRamps {
13
+ private readonly context;
14
+ private readonly params;
15
+ private readonly start;
16
+ private readonly target;
17
+ private startTime;
18
+ private endTime;
19
+ constructor(context: BaseContext, params: AudioParam[], initial: ArrayLike<number>);
20
+ /** The value each param holds now on its current ramp. */
21
+ current(): Float64Array;
22
+ /** Ramp every param from its current value to `values` over `durationMs` (0 = immediate). */
23
+ rampTo(values: ArrayLike<number>, durationMs: number): void;
24
+ cancel(): void;
25
+ }
26
+ /**
27
+ * @internal A broadband gain followed by the eight-section band cascade of
28
+ * {@link designBandGains}. Section gains and the level glide with linear
29
+ * AudioParam ramps (dB for sections, linear amplitude for the level).
30
+ */
31
+ export declare class BandGainStage {
32
+ private readonly context;
33
+ /** Head of the stage; connect the signal here. */
34
+ readonly input: GainNode;
35
+ private readonly filters;
36
+ private readonly ramps;
37
+ private sectionGainsDb;
38
+ private output?;
39
+ constructor(context: BaseContext, output?: AudioNode);
40
+ /** Tail of the stage (the last section). */
41
+ get tail(): AudioNode;
42
+ setOutput(output: AudioNode): void;
43
+ /**
44
+ * Render linear per-band gains (any non-negative values) over `durationMs`.
45
+ * `scale` multiplies every band (an image's distance gain, for example).
46
+ */
47
+ setGains(gains: readonly number[], durationMs: number, scale?: number): void;
48
+ destroy(): void;
49
+ }
@@ -0,0 +1,64 @@
1
+ import { BAND_SECTIONS as e, designBandGains as t, linearToDb as n } from "./bandGains.mjs";
2
+ var r = class {
3
+ context;
4
+ params;
5
+ start;
6
+ target;
7
+ startTime = 0;
8
+ endTime = 0;
9
+ constructor(e, t, n) {
10
+ this.context = e, this.params = t, this.start = Float64Array.from(n), this.target = Float64Array.from(n), t.forEach((e, t) => {
11
+ e.value = n[t];
12
+ });
13
+ }
14
+ current() {
15
+ let e = this.context.currentTime, t = this.endTime <= e ? 1 : Math.max(0, (e - this.startTime) / (this.endTime - this.startTime));
16
+ return this.start.map((e, n) => e + (this.target[n] - e) * t);
17
+ }
18
+ rampTo(e, t) {
19
+ let n = this.context.currentTime, r = this.current();
20
+ this.start.set(r), this.target.set(Array.from(e)), this.startTime = n, this.endTime = n + t / 1e3, this.params.forEach((e, i) => {
21
+ e.cancelScheduledValues(n), t <= 0 ? e.setValueAtTime(this.target[i], n) : (e.setValueAtTime(r[i], n), e.linearRampToValueAtTime(this.target[i], this.endTime));
22
+ });
23
+ }
24
+ cancel() {
25
+ let e = this.context.currentTime;
26
+ for (let t of this.params) t.cancelScheduledValues(e);
27
+ }
28
+ }, i = class {
29
+ context;
30
+ input;
31
+ filters;
32
+ ramps;
33
+ sectionGainsDb = new Float64Array(8);
34
+ output;
35
+ constructor(t, n) {
36
+ this.context = t, this.input = t.createGain(), this.filters = e.map((e) => {
37
+ let n = t.createBiquadFilter();
38
+ return n.type = e.type, n.frequency.value = Math.min(e.frequency, t.sampleRate / 2), n.Q.value = e.Q, n;
39
+ });
40
+ let i = this.input;
41
+ for (let e of this.filters) i.connect(e), i = e;
42
+ this.ramps = new r(t, [this.input.gain, ...this.filters.map((e) => e.gain)], [1, ...this.sectionGainsDb]), n && this.setOutput(n);
43
+ }
44
+ get tail() {
45
+ return this.filters[this.filters.length - 1];
46
+ }
47
+ setOutput(e) {
48
+ e !== this.output && (this.output && this.tail.disconnect(this.output), this.output = e, this.tail.connect(e));
49
+ }
50
+ setGains(e, r, i = 1) {
51
+ let a = t(e.map((e) => n(e * i)), this.context.sampleRate, -36, this.sectionGainsDb);
52
+ this.sectionGainsDb = a.sectionGainsDb;
53
+ let o = a.levelDb === -Infinity ? 0 : 10 ** (a.levelDb / 20);
54
+ this.ramps.rampTo([o, ...a.sectionGainsDb], r);
55
+ }
56
+ destroy() {
57
+ this.ramps.cancel(), this.input.disconnect();
58
+ for (let e of this.filters) e.disconnect();
59
+ }
60
+ };
61
+ //#endregion
62
+ export { i as BandGainStage, r as TrackedRamps };
63
+
64
+ //# sourceMappingURL=bandGainStage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bandGainStage.mjs","names":[],"sources":["../src/bandGainStage.ts"],"sourcesContent":["import { BAND_SECTIONS, designBandGains, linearToDb, OCTAVE_BAND_COUNT } from \"./bandGains\";\nimport type { AudioNode, AudioParam, BaseContext, BiquadFilterNode, GainNode } from \"./context\";\n\n/**\n * Rendered response at a band whose target is at or below -30 dB is designed at\n * this level, so it stays at or below -30 dB while section gains stay bounded.\n */\nexport const BAND_FLOOR_DB = -36;\n\n/**\n * @internal Owned linear ramps of several AudioParams that can be interrupted.\n * cancelScheduledValues removes a ramp's endpoint and AudioParam.value cannot\n * reliably recover an interrupted ramp, so start and target values are tracked.\n */\nexport class TrackedRamps {\n private readonly start: Float64Array;\n private readonly target: Float64Array;\n private startTime = 0;\n private endTime = 0;\n\n constructor(\n private readonly context: BaseContext,\n private readonly params: AudioParam[],\n initial: ArrayLike<number>,\n ) {\n this.start = Float64Array.from(initial);\n this.target = Float64Array.from(initial);\n params.forEach((param, i) => {\n param.value = initial[i];\n });\n }\n\n /** The value each param holds now on its current ramp. */\n current(): Float64Array {\n const now = this.context.currentTime;\n const fraction = this.endTime <= now ? 1 : Math.max(0, (now - this.startTime) / (this.endTime - this.startTime));\n return this.start.map((s, i) => s + (this.target[i] - s) * fraction);\n }\n\n /** Ramp every param from its current value to `values` over `durationMs` (0 = immediate). */\n rampTo(values: ArrayLike<number>, durationMs: number): void {\n const now = this.context.currentTime;\n const from = this.current();\n this.start.set(from);\n this.target.set(Array.from(values));\n this.startTime = now;\n this.endTime = now + durationMs / 1000;\n this.params.forEach((param, i) => {\n param.cancelScheduledValues(now);\n if (durationMs <= 0) {\n param.setValueAtTime(this.target[i], now);\n } else {\n param.setValueAtTime(from[i], now);\n param.linearRampToValueAtTime(this.target[i], this.endTime);\n }\n });\n }\n\n cancel(): void {\n const now = this.context.currentTime;\n for (const param of this.params) param.cancelScheduledValues(now);\n }\n}\n\n/**\n * @internal A broadband gain followed by the eight-section band cascade of\n * {@link designBandGains}. Section gains and the level glide with linear\n * AudioParam ramps (dB for sections, linear amplitude for the level).\n */\nexport class BandGainStage {\n /** Head of the stage; connect the signal here. */\n readonly input: GainNode;\n private readonly filters: BiquadFilterNode[];\n private readonly ramps: TrackedRamps;\n private sectionGainsDb = new Float64Array(OCTAVE_BAND_COUNT);\n private output?: AudioNode;\n\n constructor(\n private readonly context: BaseContext,\n output?: AudioNode,\n ) {\n this.input = context.createGain();\n this.filters = BAND_SECTIONS.map((section) => {\n const filter = context.createBiquadFilter();\n filter.type = section.type;\n filter.frequency.value = Math.min(section.frequency, context.sampleRate / 2);\n filter.Q.value = section.Q;\n return filter;\n });\n let previous: AudioNode = this.input;\n for (const filter of this.filters) {\n previous.connect(filter);\n previous = filter;\n }\n this.ramps = new TrackedRamps(\n context,\n [this.input.gain, ...this.filters.map((f) => f.gain)],\n [1, ...this.sectionGainsDb],\n );\n if (output) this.setOutput(output);\n }\n\n /** Tail of the stage (the last section). */\n get tail(): AudioNode {\n return this.filters[this.filters.length - 1];\n }\n\n setOutput(output: AudioNode): void {\n if (output === this.output) return;\n if (this.output) this.tail.disconnect(this.output);\n this.output = output;\n this.tail.connect(output);\n }\n\n /**\n * Render linear per-band gains (any non-negative values) over `durationMs`.\n * `scale` multiplies every band (an image's distance gain, for example).\n */\n setGains(gains: readonly number[], durationMs: number, scale = 1): void {\n const targetDb = gains.map((g) => linearToDb(g * scale));\n const design = designBandGains(targetDb, this.context.sampleRate, BAND_FLOOR_DB, this.sectionGainsDb);\n this.sectionGainsDb = design.sectionGainsDb;\n const level = design.levelDb === Number.NEGATIVE_INFINITY ? 0 : 10 ** (design.levelDb / 20);\n this.ramps.rampTo([level, ...design.sectionGainsDb], durationMs);\n }\n\n destroy(): void {\n this.ramps.cancel();\n this.input.disconnect();\n for (const filter of this.filters) filter.disconnect();\n }\n}\n"],"mappings":";AAcA,IAAa,IAAb,MAA0B;CAOL;CACA;CAPnB;CACA;CACA,YAAoB;CACpB,UAAkB;CAElB,YACE,GACA,GACA,GACA;EAGA,AANiB,KAAA,UAAA,GACA,KAAA,SAAA,GAGjB,KAAK,QAAQ,aAAa,KAAK,CAAO,GACtC,KAAK,SAAS,aAAa,KAAK,CAAO,GACvC,EAAO,SAAS,GAAO,MAAM;GAC3B,EAAM,QAAQ,EAAQ;EACxB,CAAC;CACH;CA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EAAS,QAAQ,CAAM,GACvB,IAAW;EAOb,AALA,KAAK,QAAQ,IAAI,EACf,GACA,CAAC,KAAK,MAAM,MAAM,GAAG,KAAK,QAAQ,KAAK,MAAM,EAAE,IAAI,CAAC,GACpD,CAAC,GAAG,GAAG,KAAK,cAAc,CAC5B,GACI,KAAQ,KAAK,UAAU,CAAM;CACnC;CAGA,IAAI,OAAkB;EACpB,OAAO,KAAK,QAAQ,KAAK,QAAQ,SAAS;CAC5C;CAEA,UAAU,GAAyB;EAC7B,MAAW,KAAK,WAChB,KAAK,UAAQ,KAAK,KAAK,WAAW,KAAK,MAAM,GACjD,KAAK,SAAS,GACd,KAAK,KAAK,QAAQ,CAAM;CAC1B;CAMA,SAAS,GAA0B,GAAoB,IAAQ,GAAS;EAEtE,IAAM,IAAS,EADE,EAAM,KAAK,MAAM,EAAW,IAAI,CAAK,CACvB,GAAU,KAAK,QAAQ,YAAA,KAA2B,KAAK,cAAc;EACpG,KAAK,iBAAiB,EAAO;EAC7B,IAAM,IAAQ,EAAO,YAAY,YAA2B,IAAI,OAAO,EAAO,UAAU;EACxF,KAAK,MAAM,OAAO,CAAC,GAAO,GAAG,EAAO,cAAc,GAAG,CAAU;CACjE;CAEA,UAAgB;EAEd,AADA,KAAK,MAAM,OAAO,GAClB,KAAK,MAAM,WAAW;EACtB,KAAK,IAAM,KAAU,KAAK,SAAS,EAAO,WAAW;CACvD;AACF"}
@@ -0,0 +1,2 @@
1
+ var e=Object.freeze([125,250,500,1e3,2e3,4e3,8e3,16e3]),t=8,n=1,r=Math.SQRT2,i=Object.freeze(e.map((e,t)=>t===0?{type:`lowshelf`,frequency:r*e,Q:n}:t===7?{type:`highshelf`,frequency:e/r,Q:n}:{type:`peaking`,frequency:e,Q:n}));function a(e,t,n){let r=10**(t/40),i=2*Math.PI*Math.min(e.frequency,n/2)/n,a=Math.cos(i),o=Math.sin(i),s,c,l,u,d,f;if(e.type===`peaking`){let t=o/(2*e.Q);s=1+t*r,c=-2*a,l=1-t*r,u=1+t/r,d=-2*a,f=1-t/r}else{let t=2*Math.sqrt(r)*(o/Math.SQRT2);e.type===`lowshelf`?(s=r*(r+1-(r-1)*a+t),c=2*r*(r-1-(r+1)*a),l=r*(r+1-(r-1)*a-t),u=r+1+(r-1)*a+t,d=-2*(r-1+(r+1)*a),f=r+1+(r-1)*a-t):(s=r*(r+1+(r-1)*a+t),c=-2*r*(r-1+(r+1)*a),l=r*(r+1+(r-1)*a-t),u=r+1-(r-1)*a+t,d=2*(r-1-(r+1)*a),f=r+1-(r-1)*a-t)}return[s/u,c/u,l/u,d/u,f/u]}function o(e,t){let n=Math.cos(t),r=Math.sin(t),i=Math.cos(2*t),a=Math.sin(2*t),o=e[0]+e[1]*n+e[2]*i,s=e[1]*r+e[2]*a,c=1+e[3]*n+e[4]*i,l=e[3]*r+e[4]*a;return 10*Math.log10((o*o+s*s)/(c*c+l*l))}var s=.45,c=.005,l=40,u=.25;function d(t,n,r,d){if(t.length!==8)throw RangeError(`Band targets need exactly 8 values, got ${t.length}`);let p=-1/0;for(let e=0;e<8;e++)p=Math.max(p,t[e]);let m=new Float64Array(8);if(p===-1/0)return{levelDb:p,sectionGainsDb:m};let h=[];for(let e=0;e<8;e++)i[e].frequency<s*n&&h.push(e);let g=new Float64Array(8),_=Math.min(r,p);for(let e=0;e<8;e++)g[e]=Math.max(t[e],_)-p;if(h.every(e=>g[e]===0))return{levelDb:p,sectionGainsDb:m};let v=h.length,y=h.map(t=>2*Math.PI*Math.min(e[t],n/2)/n);for(let e=0;e<v;e++)m[h[e]]=d?d[h[e]]:0;let b=(e,t)=>{let r=new Float64Array(v);if(t===0)return r;let s=a(i[h[e]],t,n);for(let e=0;e<v;e++)r[e]=o(s,y[e]);return r},x=e=>{let t=new Float64Array(v);for(let n=0;n<v;n++){let r=0;for(let t=0;t<v;t++)r+=e[t][n];t[n]=g[h[n]]-r}return t},S=e=>e.reduce((e,t)=>Math.max(e,Math.abs(t)),0),C=h.map((e,t)=>b(t,m[h[t]])),w=x(C),T=S(w);for(let e=0;e<l&&T>c;e++){let e=Array.from({length:v},()=>Array(v).fill(0));for(let t=0;t<v;t++){let n=m[h[t]],r=b(t,n+u),i=b(t,n-u);for(let n=0;n<v;n++)e[n][t]=(r[n]-i[n])/(2*u)}let t=f(e,Array.from(w)),n=1,r=!1;for(let e=0;e<12;e++){let e=h.map((e,r)=>m[e]+n*t[r]),i=e.map((e,t)=>b(t,e)),a=x(i),o=S(a);if(o<T){for(let t=0;t<v;t++)m[h[t]]=e[t];C=i,w=a,T=o,r=!0;break}n/=2}if(!r)break}return{levelDb:p,sectionGainsDb:m}}function f(e,t){let n=t.length,r=e.map((e,n)=>[...e,t[n]]);for(let e=0;e<n;e++){let t=e;for(let i=e+1;i<n;i++)Math.abs(r[i][e])>Math.abs(r[t][e])&&(t=i);[r[e],r[t]]=[r[t],r[e]];let i=r[e][e];if(i!==0)for(let t=0;t<n;t++){if(t===e)continue;let a=r[t][e]/i;if(a!==0)for(let i=e;i<=n;i++)r[t][i]-=a*r[e][i]}}return r.map((e,t)=>e[t]===0?0:e[n]/e[t])}function p(e,t){if(!Array.isArray(e)||e.length!==8)throw RangeError(`${t} needs exactly 8 band gains`);for(let n of e)if(typeof n!=`number`||!Number.isFinite(n)||n<0||n>1)throw RangeError(`${t} band gains must be finite numbers in [0, 1]`);return Object.freeze([...e])}function m(e){return e>0?20*Math.log10(e):-1/0}exports.BAND_SECTIONS=i,exports.OCTAVE_BAND_CENTERS=e,exports.OCTAVE_BAND_COUNT=t,exports.designBandGains=d,exports.linearToDb=m,exports.validateBandGains=p;
2
+ //# sourceMappingURL=bandGains.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bandGains.cjs","names":[],"sources":["../src/bandGains.ts"],"sourcesContent":["/**\n * Octave-band gain design shared by the per-voice band stage, early-reflection\n * images and the FDN reverb's per-line absorption filters.\n *\n * A fixed cascade of second-order sections renders eight octave-band gains:\n * a low shelf with its corner between the first two bands, peaking filters on\n * the six middle band centers, and a high shelf with its corner between the\n * last two bands.\n * Below the lowest and above the highest band center the response continues on\n * the shelf slopes toward the shelves' full gains; it does not climb back to\n * unity the way a peaking filter on an end band would. The extension can differ\n * from the end band's own gain by several dB when neighbouring bands differ\n * sharply (about 6 dB below 125 Hz for a 12 dB step between 125 and 250 Hz). Section gains (dB) are\n * solved per update so the cascade's magnitude at every band center equals the\n * target: the \"interaction-corrected\" cascade graphic equalizer of\n * V. Välimäki and J. Liski, \"Accurate Cascade Graphic Equalizer\", IEEE Signal\n * Processing Letters 24(2), 2017. Their least-squares solve against the\n * interaction matrix is the first Newton step from flat gains here; further\n * Newton steps re-linearize at the current gains until the error at every\n * band center is below 0.005 dB, which also covers steep and deep targets that\n * a single linear solve misses.\n *\n * Coefficients follow the Web Audio API BiquadFilterNode formulas (Audio EQ\n * Cookbook, shelves with slope 1), so the design matches what the native nodes\n * render. Pure math: no audio-context or worklet globals.\n */\n\n/** Center frequencies (Hz) of the eight octave bands every band-gain API uses. */\nexport const OCTAVE_BAND_CENTERS: readonly [125, 250, 500, 1000, 2000, 4000, 8000, 16000] = Object.freeze([\n 125, 250, 500, 1000, 2000, 4000, 8000, 16000,\n] as const);\n\n/** Number of octave bands, the length of every band-gain or band-decay array. */\nexport const OCTAVE_BAND_COUNT = 8;\n\n/** @internal Biquad section type rendered by the cascade. */\nexport type BandSectionType = \"lowshelf\" | \"peaking\" | \"highshelf\";\n\n/** @internal One second-order section of the cascade. */\nexport interface BandSection {\n readonly type: BandSectionType;\n /** Corner (shelf) or center (peaking) frequency in Hz. */\n readonly frequency: number;\n /** Peaking-filter Q; Web Audio shelves ignore Q. */\n readonly Q: number;\n}\n\n/** Peaking-filter Q of the middle sections (octave spacing). */\nconst PEAKING_Q = 1;\n\n/**\n * Shelf corners sit half an octave inside the end bands (177 Hz and 11.3 kHz).\n * Measured against octave corners (250 Hz, 8 kHz): between band centers the\n * response follows a log-log interpolation of steep decay profiles within 6%\n * instead of 18% (in T60 terms, within a sixth of an octave of each center),\n * at the cost of larger section gains on pathological targets (52 vs 41 dB).\n */\nconst SHELF_CORNER_RATIO = Math.SQRT2;\n\n/** @internal The fixed section layout, one section per band. */\nexport const BAND_SECTIONS: readonly BandSection[] = Object.freeze(\n OCTAVE_BAND_CENTERS.map((frequency, band): BandSection => {\n if (band === 0) return { type: \"lowshelf\", frequency: SHELF_CORNER_RATIO * frequency, Q: PEAKING_Q };\n if (band === OCTAVE_BAND_COUNT - 1) {\n return { type: \"highshelf\", frequency: frequency / SHELF_CORNER_RATIO, Q: PEAKING_Q };\n }\n return { type: \"peaking\", frequency, Q: PEAKING_Q };\n }),\n);\n\n/** Normalized biquad coefficients [b0, b1, b2, a1, a2] with a0 = 1. */\nexport type BiquadCoefficients = [number, number, number, number, number];\n\n/**\n * @internal Coefficients of one section at `gainDb`, exactly as the Web Audio\n * BiquadFilterNode computes them (spec §BiquadFilterNode, Audio EQ Cookbook).\n */\nexport function sectionCoefficients(section: BandSection, gainDb: number, sampleRate: number): BiquadCoefficients {\n const A = 10 ** (gainDb / 40);\n const w0 = (2 * Math.PI * Math.min(section.frequency, sampleRate / 2)) / sampleRate;\n const cos = Math.cos(w0);\n const sin = Math.sin(w0);\n let b0: number;\n let b1: number;\n let b2: number;\n let a0: number;\n let a1: number;\n let a2: number;\n if (section.type === \"peaking\") {\n const alpha = sin / (2 * section.Q);\n b0 = 1 + alpha * A;\n b1 = -2 * cos;\n b2 = 1 - alpha * A;\n a0 = 1 + alpha / A;\n a1 = -2 * cos;\n a2 = 1 - alpha / A;\n } else {\n // Shelf slope S = 1: alpha = sin(w0)/2 · sqrt(2).\n const twoSqrtAAlpha = 2 * Math.sqrt(A) * (sin / Math.SQRT2);\n if (section.type === \"lowshelf\") {\n b0 = A * (A + 1 - (A - 1) * cos + twoSqrtAAlpha);\n b1 = 2 * A * (A - 1 - (A + 1) * cos);\n b2 = A * (A + 1 - (A - 1) * cos - twoSqrtAAlpha);\n a0 = A + 1 + (A - 1) * cos + twoSqrtAAlpha;\n a1 = -2 * (A - 1 + (A + 1) * cos);\n a2 = A + 1 + (A - 1) * cos - twoSqrtAAlpha;\n } else {\n b0 = A * (A + 1 + (A - 1) * cos + twoSqrtAAlpha);\n b1 = -2 * A * (A - 1 + (A + 1) * cos);\n b2 = A * (A + 1 + (A - 1) * cos - twoSqrtAAlpha);\n a0 = A + 1 - (A - 1) * cos + twoSqrtAAlpha;\n a1 = 2 * (A - 1 - (A + 1) * cos);\n a2 = A + 1 - (A - 1) * cos - twoSqrtAAlpha;\n }\n }\n return [b0 / a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0];\n}\n\n/** Magnitude in dB of normalized coefficients at angular frequency `w` (rad/sample). */\nexport function biquadMagnitudeDb(c: BiquadCoefficients, w: number): number {\n const c1 = Math.cos(w);\n const s1 = Math.sin(w);\n const c2 = Math.cos(2 * w);\n const s2 = Math.sin(2 * w);\n const nr = c[0] + c[1] * c1 + c[2] * c2;\n const ni = c[1] * s1 + c[2] * s2;\n const dr = 1 + c[3] * c1 + c[4] * c2;\n const di = c[3] * s1 + c[4] * s2;\n return 10 * Math.log10((nr * nr + ni * ni) / (dr * dr + di * di));\n}\n\n/** Magnitude in dB of the cascade with section gains `gainsDb` at frequency `hz`. */\nexport function cascadeMagnitudeDb(gainsDb: ArrayLike<number>, hz: number, sampleRate: number): number {\n const w = (2 * Math.PI * Math.min(hz, sampleRate / 2)) / sampleRate;\n let total = 0;\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) {\n if (gainsDb[k] === 0) continue;\n total += biquadMagnitudeDb(sectionCoefficients(BAND_SECTIONS[k], gainsDb[k], sampleRate), w);\n }\n return total;\n}\n\n/** Result of {@link designBandGains}. */\nexport interface BandGainDesign {\n /** Broadband level in dB carried by a gain stage (-Infinity for silence). */\n levelDb: number;\n /** Gain in dB of each cascade section, in {@link BAND_SECTIONS} order. */\n sectionGainsDb: Float64Array;\n}\n\n/** Sections whose frequency is at or above this fraction of the sample rate are left flat. */\nconst MAX_SECTION_FRACTION = 0.45;\nconst DESIGN_TOLERANCE_DB = 0.005;\nconst MAX_ITERATIONS = 40;\nconst JACOBIAN_STEP_DB = 0.25;\n\n/**\n * Solve the section gains for `targetDb` (one value per band, dB, -Infinity\n * allowed). The common level (the largest target) goes to `levelDb`; the\n * cascade renders the remainder relative to it. Targets below `floorDb` are\n * designed at `floorDb`, so the rendered response at those bands is at or below\n * the floor while the section gains stay bounded.\n *\n * Bands whose section frequency is at or above 0.45·fs cannot be shaped at that\n * sample rate; their sections stay flat and their targets are not constrained.\n *\n * @param previous Optional section gains to start the iteration from (the last\n * design of the same stage), which usually converges in one or two steps.\n */\nexport function designBandGains(\n targetDb: ArrayLike<number>,\n sampleRate: number,\n floorDb: number,\n previous?: ArrayLike<number>,\n): BandGainDesign {\n if (targetDb.length !== OCTAVE_BAND_COUNT) {\n throw new RangeError(`Band targets need exactly ${OCTAVE_BAND_COUNT} values, got ${targetDb.length}`);\n }\n let levelDb = Number.NEGATIVE_INFINITY;\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) levelDb = Math.max(levelDb, targetDb[k]);\n const gains = new Float64Array(OCTAVE_BAND_COUNT);\n if (levelDb === Number.NEGATIVE_INFINITY) return { levelDb, sectionGainsDb: gains };\n\n const active: number[] = [];\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) {\n if (BAND_SECTIONS[k].frequency < MAX_SECTION_FRACTION * sampleRate) active.push(k);\n }\n const relative = new Float64Array(OCTAVE_BAND_COUNT);\n const floor = Math.min(floorDb, levelDb);\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) relative[k] = Math.max(targetDb[k], floor) - levelDb;\n if (active.every((k) => relative[k] === 0)) return { levelDb, sectionGainsDb: gains };\n\n const n = active.length;\n const w = active.map((k) => (2 * Math.PI * Math.min(OCTAVE_BAND_CENTERS[k], sampleRate / 2)) / sampleRate);\n for (let i = 0; i < n; i++) gains[active[i]] = previous ? previous[active[i]] : 0;\n\n // contribution[s][i]: section s's magnitude (dB) at band i for its current gain.\n const contribution = (s: number, gainDb: number): Float64Array => {\n const out = new Float64Array(n);\n if (gainDb === 0) return out;\n const c = sectionCoefficients(BAND_SECTIONS[active[s]], gainDb, sampleRate);\n for (let i = 0; i < n; i++) out[i] = biquadMagnitudeDb(c, w[i]);\n return out;\n };\n const errorOf = (cols: Float64Array[]): Float64Array => {\n const e = new Float64Array(n);\n for (let i = 0; i < n; i++) {\n let r = 0;\n for (let s = 0; s < n; s++) r += cols[s][i];\n e[i] = relative[active[i]] - r;\n }\n return e;\n };\n const maxAbs = (e: Float64Array) => e.reduce((m, x) => Math.max(m, Math.abs(x)), 0);\n\n let cols = active.map((_, s) => contribution(s, gains[active[s]]));\n let error = errorOf(cols);\n let worst = maxAbs(error);\n for (let iteration = 0; iteration < MAX_ITERATIONS && worst > DESIGN_TOLERANCE_DB; iteration++) {\n // Each band's response is a sum over sections, so column s of the Jacobian\n // depends on section s alone.\n const jacobian: number[][] = Array.from({ length: n }, () => new Array<number>(n).fill(0));\n for (let s = 0; s < n; s++) {\n const g = gains[active[s]];\n const up = contribution(s, g + JACOBIAN_STEP_DB);\n const down = contribution(s, g - JACOBIAN_STEP_DB);\n for (let i = 0; i < n; i++) jacobian[i][s] = (up[i] - down[i]) / (2 * JACOBIAN_STEP_DB);\n }\n const step = solveLinear(jacobian, Array.from(error));\n // Damped Newton: halve the step until the worst error decreases.\n let scale = 1;\n let accepted = false;\n for (let attempt = 0; attempt < 12; attempt++) {\n const trial = active.map((k, s) => gains[k] + scale * step[s]);\n const trialCols = trial.map((g, s) => contribution(s, g));\n const trialError = errorOf(trialCols);\n const trialWorst = maxAbs(trialError);\n if (trialWorst < worst) {\n for (let s = 0; s < n; s++) gains[active[s]] = trial[s];\n cols = trialCols;\n error = trialError;\n worst = trialWorst;\n accepted = true;\n break;\n }\n scale /= 2;\n }\n if (!accepted) break;\n }\n return { levelDb, sectionGainsDb: gains };\n}\n\n/** Gaussian elimination with partial pivoting; returns x with A·x = b. */\nfunction solveLinear(a: number[][], b: number[]): number[] {\n const n = b.length;\n const m = a.map((row, i) => [...row, b[i]]);\n for (let col = 0; col < n; col++) {\n let pivot = col;\n for (let r = col + 1; r < n; r++) if (Math.abs(m[r][col]) > Math.abs(m[pivot][col])) pivot = r;\n [m[col], m[pivot]] = [m[pivot], m[col]];\n const p = m[col][col];\n if (p === 0) continue;\n for (let r = 0; r < n; r++) {\n if (r === col) continue;\n const factor = m[r][col] / p;\n if (factor === 0) continue;\n for (let c = col; c <= n; c++) m[r][c] -= factor * m[col][c];\n }\n }\n return m.map((row, i) => (row[i] === 0 ? 0 : row[n] / row[i]));\n}\n\n/**\n * @internal Validate a public band-gain array: exactly eight finite linear\n * gains in [0, 1]. Returns a frozen copy.\n */\nexport function validateBandGains(gains: readonly number[], label: string): readonly number[] {\n if (!Array.isArray(gains) || gains.length !== OCTAVE_BAND_COUNT) {\n throw new RangeError(`${label} needs exactly ${OCTAVE_BAND_COUNT} band gains`);\n }\n for (const gain of gains) {\n if (typeof gain !== \"number\" || !Number.isFinite(gain) || gain < 0 || gain > 1) {\n throw new RangeError(`${label} band gains must be finite numbers in [0, 1]`);\n }\n }\n return Object.freeze([...gains]);\n}\n\n/** @internal Linear gain to dB, with 0 mapping to -Infinity. */\nexport function linearToDb(gain: number): number {\n return gain > 0 ? 20 * Math.log10(gain) : Number.NEGATIVE_INFINITY;\n}\n"],"mappings":"AA4BA,IAAa,EAA+E,OAAO,OAAO,CACxG,IAAK,IAAK,IAAK,IAAM,IAAM,IAAM,IAAM,IACzC,CAAU,EAGG,EAAoB,EAe3B,EAAY,EASZ,EAAqB,KAAK,MAGnB,EAAwC,OAAO,OAC1D,EAAoB,KAAK,EAAW,IAC9B,IAAS,EAAU,CAAE,KAAM,WAAY,UAAW,EAAqB,EAAW,EAAG,CAAU,EAC/F,IAAA,EACK,CAAE,KAAM,YAAa,UAAW,EAAY,EAAoB,EAAG,CAAU,EAE/E,CAAE,KAAM,UAAW,YAAW,EAAG,CAAU,CACnD,CACH,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,OAAO,EAAE,KAAK,EAAK,IAAO,EAAI,KAAO,EAAI,EAAI,EAAI,GAAK,EAAI,EAAG,CAC/D,CAMA,SAAgB,EAAkB,EAA0B,EAAkC,CAC5F,GAAI,CAAC,MAAM,QAAQ,CAAK,GAAK,EAAM,SAAA,EACjC,MAAU,WAAW,GAAG,EAAM,4BAA+C,EAE/E,IAAK,IAAM,KAAQ,EACjB,GAAI,OAAO,GAAS,UAAY,CAAC,OAAO,SAAS,CAAI,GAAK,EAAO,GAAK,EAAO,EAC3E,MAAU,WAAW,GAAG,EAAM,6CAA6C,EAG/E,OAAO,OAAO,OAAO,CAAC,GAAG,CAAK,CAAC,CACjC,CAGA,SAAgB,EAAW,EAAsB,CAC/C,OAAO,EAAO,EAAI,GAAK,KAAK,MAAM,CAAI,EAAI,IAC5C"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Octave-band gain design shared by the per-voice band stage, early-reflection
3
+ * images and the FDN reverb's per-line absorption filters.
4
+ *
5
+ * A fixed cascade of second-order sections renders eight octave-band gains:
6
+ * a low shelf with its corner between the first two bands, peaking filters on
7
+ * the six middle band centers, and a high shelf with its corner between the
8
+ * last two bands.
9
+ * Below the lowest and above the highest band center the response continues on
10
+ * the shelf slopes toward the shelves' full gains; it does not climb back to
11
+ * unity the way a peaking filter on an end band would. The extension can differ
12
+ * from the end band's own gain by several dB when neighbouring bands differ
13
+ * sharply (about 6 dB below 125 Hz for a 12 dB step between 125 and 250 Hz). Section gains (dB) are
14
+ * solved per update so the cascade's magnitude at every band center equals the
15
+ * target: the "interaction-corrected" cascade graphic equalizer of
16
+ * V. Välimäki and J. Liski, "Accurate Cascade Graphic Equalizer", IEEE Signal
17
+ * Processing Letters 24(2), 2017. Their least-squares solve against the
18
+ * interaction matrix is the first Newton step from flat gains here; further
19
+ * Newton steps re-linearize at the current gains until the error at every
20
+ * band center is below 0.005 dB, which also covers steep and deep targets that
21
+ * a single linear solve misses.
22
+ *
23
+ * Coefficients follow the Web Audio API BiquadFilterNode formulas (Audio EQ
24
+ * Cookbook, shelves with slope 1), so the design matches what the native nodes
25
+ * render. Pure math: no audio-context or worklet globals.
26
+ */
27
+ /** Center frequencies (Hz) of the eight octave bands every band-gain API uses. */
28
+ export declare const OCTAVE_BAND_CENTERS: readonly [125, 250, 500, 1000, 2000, 4000, 8000, 16000];
29
+ /** Number of octave bands, the length of every band-gain or band-decay array. */
30
+ export declare const OCTAVE_BAND_COUNT = 8;
31
+ /** @internal Biquad section type rendered by the cascade. */
32
+ export type BandSectionType = "lowshelf" | "peaking" | "highshelf";
33
+ /** @internal One second-order section of the cascade. */
34
+ export interface BandSection {
35
+ readonly type: BandSectionType;
36
+ /** Corner (shelf) or center (peaking) frequency in Hz. */
37
+ readonly frequency: number;
38
+ /** Peaking-filter Q; Web Audio shelves ignore Q. */
39
+ readonly Q: number;
40
+ }
41
+ /** @internal The fixed section layout, one section per band. */
42
+ export declare const BAND_SECTIONS: readonly BandSection[];
43
+ /** Normalized biquad coefficients [b0, b1, b2, a1, a2] with a0 = 1. */
44
+ export type BiquadCoefficients = [number, number, number, number, number];
45
+ /**
46
+ * @internal Coefficients of one section at `gainDb`, exactly as the Web Audio
47
+ * BiquadFilterNode computes them (spec §BiquadFilterNode, Audio EQ Cookbook).
48
+ */
49
+ export declare function sectionCoefficients(section: BandSection, gainDb: number, sampleRate: number): BiquadCoefficients;
50
+ /** Magnitude in dB of normalized coefficients at angular frequency `w` (rad/sample). */
51
+ export declare function biquadMagnitudeDb(c: BiquadCoefficients, w: number): number;
52
+ /** Magnitude in dB of the cascade with section gains `gainsDb` at frequency `hz`. */
53
+ export declare function cascadeMagnitudeDb(gainsDb: ArrayLike<number>, hz: number, sampleRate: number): number;
54
+ /** Result of {@link designBandGains}. */
55
+ export interface BandGainDesign {
56
+ /** Broadband level in dB carried by a gain stage (-Infinity for silence). */
57
+ levelDb: number;
58
+ /** Gain in dB of each cascade section, in {@link BAND_SECTIONS} order. */
59
+ sectionGainsDb: Float64Array;
60
+ }
61
+ /**
62
+ * Solve the section gains for `targetDb` (one value per band, dB, -Infinity
63
+ * allowed). The common level (the largest target) goes to `levelDb`; the
64
+ * cascade renders the remainder relative to it. Targets below `floorDb` are
65
+ * designed at `floorDb`, so the rendered response at those bands is at or below
66
+ * the floor while the section gains stay bounded.
67
+ *
68
+ * Bands whose section frequency is at or above 0.45·fs cannot be shaped at that
69
+ * sample rate; their sections stay flat and their targets are not constrained.
70
+ *
71
+ * @param previous Optional section gains to start the iteration from (the last
72
+ * design of the same stage), which usually converges in one or two steps.
73
+ */
74
+ export declare function designBandGains(targetDb: ArrayLike<number>, sampleRate: number, floorDb: number, previous?: ArrayLike<number>): BandGainDesign;
75
+ /**
76
+ * @internal Validate a public band-gain array: exactly eight finite linear
77
+ * gains in [0, 1]. Returns a frozen copy.
78
+ */
79
+ export declare function validateBandGains(gains: readonly number[], label: string): readonly number[];
80
+ /** @internal Linear gain to dB, with 0 mapping to -Infinity. */
81
+ export declare function linearToDb(gain: number): number;
@@ -0,0 +1,129 @@
1
+ //#region src/bandGains.ts
2
+ var e = Object.freeze([
3
+ 125,
4
+ 250,
5
+ 500,
6
+ 1e3,
7
+ 2e3,
8
+ 4e3,
9
+ 8e3,
10
+ 16e3
11
+ ]), t = 8, n = 1, r = Math.SQRT2, i = Object.freeze(e.map((e, t) => t === 0 ? {
12
+ type: "lowshelf",
13
+ frequency: r * e,
14
+ Q: n
15
+ } : t === 7 ? {
16
+ type: "highshelf",
17
+ frequency: e / r,
18
+ Q: n
19
+ } : {
20
+ type: "peaking",
21
+ frequency: e,
22
+ Q: n
23
+ }));
24
+ function a(e, t, n) {
25
+ let r = 10 ** (t / 40), i = 2 * Math.PI * Math.min(e.frequency, n / 2) / n, a = Math.cos(i), o = Math.sin(i), s, c, l, u, d, f;
26
+ if (e.type === "peaking") {
27
+ let t = o / (2 * e.Q);
28
+ s = 1 + t * r, c = -2 * a, l = 1 - t * r, u = 1 + t / r, d = -2 * a, f = 1 - t / r;
29
+ } else {
30
+ let t = 2 * Math.sqrt(r) * (o / Math.SQRT2);
31
+ e.type === "lowshelf" ? (s = r * (r + 1 - (r - 1) * a + t), c = 2 * r * (r - 1 - (r + 1) * a), l = r * (r + 1 - (r - 1) * a - t), u = r + 1 + (r - 1) * a + t, d = -2 * (r - 1 + (r + 1) * a), f = r + 1 + (r - 1) * a - t) : (s = r * (r + 1 + (r - 1) * a + t), c = -2 * r * (r - 1 + (r + 1) * a), l = r * (r + 1 + (r - 1) * a - t), u = r + 1 - (r - 1) * a + t, d = 2 * (r - 1 - (r + 1) * a), f = r + 1 - (r - 1) * a - t);
32
+ }
33
+ return [
34
+ s / u,
35
+ c / u,
36
+ l / u,
37
+ d / u,
38
+ f / u
39
+ ];
40
+ }
41
+ function o(e, t) {
42
+ let n = Math.cos(t), r = Math.sin(t), i = Math.cos(2 * t), a = Math.sin(2 * t), o = e[0] + e[1] * n + e[2] * i, s = e[1] * r + e[2] * a, c = 1 + e[3] * n + e[4] * i, l = e[3] * r + e[4] * a;
43
+ return 10 * Math.log10((o * o + s * s) / (c * c + l * l));
44
+ }
45
+ var s = .45, c = .005, l = 40, u = .25;
46
+ function d(t, n, r, d) {
47
+ if (t.length !== 8) throw RangeError(`Band targets need exactly 8 values, got ${t.length}`);
48
+ let p = -Infinity;
49
+ for (let e = 0; e < 8; e++) p = Math.max(p, t[e]);
50
+ let m = new Float64Array(8);
51
+ if (p === -Infinity) return {
52
+ levelDb: p,
53
+ sectionGainsDb: m
54
+ };
55
+ let h = [];
56
+ for (let e = 0; e < 8; e++) i[e].frequency < s * n && h.push(e);
57
+ let g = new Float64Array(8), _ = Math.min(r, p);
58
+ for (let e = 0; e < 8; e++) g[e] = Math.max(t[e], _) - p;
59
+ if (h.every((e) => g[e] === 0)) return {
60
+ levelDb: p,
61
+ sectionGainsDb: m
62
+ };
63
+ let v = h.length, y = h.map((t) => 2 * Math.PI * Math.min(e[t], n / 2) / n);
64
+ for (let e = 0; e < v; e++) m[h[e]] = d ? d[h[e]] : 0;
65
+ let b = (e, t) => {
66
+ let r = new Float64Array(v);
67
+ if (t === 0) return r;
68
+ let s = a(i[h[e]], t, n);
69
+ for (let e = 0; e < v; e++) r[e] = o(s, y[e]);
70
+ return r;
71
+ }, x = (e) => {
72
+ let t = new Float64Array(v);
73
+ for (let n = 0; n < v; n++) {
74
+ let r = 0;
75
+ for (let t = 0; t < v; t++) r += e[t][n];
76
+ t[n] = g[h[n]] - r;
77
+ }
78
+ return t;
79
+ }, S = (e) => e.reduce((e, t) => Math.max(e, Math.abs(t)), 0), C = h.map((e, t) => b(t, m[h[t]])), w = x(C), T = S(w);
80
+ for (let e = 0; e < l && T > c; e++) {
81
+ let e = Array.from({ length: v }, () => Array(v).fill(0));
82
+ for (let t = 0; t < v; t++) {
83
+ let n = m[h[t]], r = b(t, n + u), i = b(t, n - u);
84
+ for (let n = 0; n < v; n++) e[n][t] = (r[n] - i[n]) / (2 * u);
85
+ }
86
+ let t = f(e, Array.from(w)), n = 1, r = !1;
87
+ for (let e = 0; e < 12; e++) {
88
+ let e = h.map((e, r) => m[e] + n * t[r]), i = e.map((e, t) => b(t, e)), a = x(i), o = S(a);
89
+ if (o < T) {
90
+ for (let t = 0; t < v; t++) m[h[t]] = e[t];
91
+ C = i, w = a, T = o, r = !0;
92
+ break;
93
+ }
94
+ n /= 2;
95
+ }
96
+ if (!r) break;
97
+ }
98
+ return {
99
+ levelDb: p,
100
+ sectionGainsDb: m
101
+ };
102
+ }
103
+ function f(e, t) {
104
+ let n = t.length, r = e.map((e, n) => [...e, t[n]]);
105
+ for (let e = 0; e < n; e++) {
106
+ let t = e;
107
+ for (let i = e + 1; i < n; i++) Math.abs(r[i][e]) > Math.abs(r[t][e]) && (t = i);
108
+ [r[e], r[t]] = [r[t], r[e]];
109
+ let i = r[e][e];
110
+ if (i !== 0) for (let t = 0; t < n; t++) {
111
+ if (t === e) continue;
112
+ let a = r[t][e] / i;
113
+ if (a !== 0) for (let i = e; i <= n; i++) r[t][i] -= a * r[e][i];
114
+ }
115
+ }
116
+ return r.map((e, t) => e[t] === 0 ? 0 : e[n] / e[t]);
117
+ }
118
+ function p(e, t) {
119
+ if (!Array.isArray(e) || e.length !== 8) throw RangeError(`${t} needs exactly 8 band gains`);
120
+ for (let n of e) if (typeof n != "number" || !Number.isFinite(n) || n < 0 || n > 1) throw RangeError(`${t} band gains must be finite numbers in [0, 1]`);
121
+ return Object.freeze([...e]);
122
+ }
123
+ function m(e) {
124
+ return e > 0 ? 20 * Math.log10(e) : -Infinity;
125
+ }
126
+ //#endregion
127
+ export { i as BAND_SECTIONS, e as OCTAVE_BAND_CENTERS, t as OCTAVE_BAND_COUNT, d as designBandGains, m as linearToDb, p as validateBandGains };
128
+
129
+ //# sourceMappingURL=bandGains.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bandGains.mjs","names":[],"sources":["../src/bandGains.ts"],"sourcesContent":["/**\n * Octave-band gain design shared by the per-voice band stage, early-reflection\n * images and the FDN reverb's per-line absorption filters.\n *\n * A fixed cascade of second-order sections renders eight octave-band gains:\n * a low shelf with its corner between the first two bands, peaking filters on\n * the six middle band centers, and a high shelf with its corner between the\n * last two bands.\n * Below the lowest and above the highest band center the response continues on\n * the shelf slopes toward the shelves' full gains; it does not climb back to\n * unity the way a peaking filter on an end band would. The extension can differ\n * from the end band's own gain by several dB when neighbouring bands differ\n * sharply (about 6 dB below 125 Hz for a 12 dB step between 125 and 250 Hz). Section gains (dB) are\n * solved per update so the cascade's magnitude at every band center equals the\n * target: the \"interaction-corrected\" cascade graphic equalizer of\n * V. Välimäki and J. Liski, \"Accurate Cascade Graphic Equalizer\", IEEE Signal\n * Processing Letters 24(2), 2017. Their least-squares solve against the\n * interaction matrix is the first Newton step from flat gains here; further\n * Newton steps re-linearize at the current gains until the error at every\n * band center is below 0.005 dB, which also covers steep and deep targets that\n * a single linear solve misses.\n *\n * Coefficients follow the Web Audio API BiquadFilterNode formulas (Audio EQ\n * Cookbook, shelves with slope 1), so the design matches what the native nodes\n * render. Pure math: no audio-context or worklet globals.\n */\n\n/** Center frequencies (Hz) of the eight octave bands every band-gain API uses. */\nexport const OCTAVE_BAND_CENTERS: readonly [125, 250, 500, 1000, 2000, 4000, 8000, 16000] = Object.freeze([\n 125, 250, 500, 1000, 2000, 4000, 8000, 16000,\n] as const);\n\n/** Number of octave bands, the length of every band-gain or band-decay array. */\nexport const OCTAVE_BAND_COUNT = 8;\n\n/** @internal Biquad section type rendered by the cascade. */\nexport type BandSectionType = \"lowshelf\" | \"peaking\" | \"highshelf\";\n\n/** @internal One second-order section of the cascade. */\nexport interface BandSection {\n readonly type: BandSectionType;\n /** Corner (shelf) or center (peaking) frequency in Hz. */\n readonly frequency: number;\n /** Peaking-filter Q; Web Audio shelves ignore Q. */\n readonly Q: number;\n}\n\n/** Peaking-filter Q of the middle sections (octave spacing). */\nconst PEAKING_Q = 1;\n\n/**\n * Shelf corners sit half an octave inside the end bands (177 Hz and 11.3 kHz).\n * Measured against octave corners (250 Hz, 8 kHz): between band centers the\n * response follows a log-log interpolation of steep decay profiles within 6%\n * instead of 18% (in T60 terms, within a sixth of an octave of each center),\n * at the cost of larger section gains on pathological targets (52 vs 41 dB).\n */\nconst SHELF_CORNER_RATIO = Math.SQRT2;\n\n/** @internal The fixed section layout, one section per band. */\nexport const BAND_SECTIONS: readonly BandSection[] = Object.freeze(\n OCTAVE_BAND_CENTERS.map((frequency, band): BandSection => {\n if (band === 0) return { type: \"lowshelf\", frequency: SHELF_CORNER_RATIO * frequency, Q: PEAKING_Q };\n if (band === OCTAVE_BAND_COUNT - 1) {\n return { type: \"highshelf\", frequency: frequency / SHELF_CORNER_RATIO, Q: PEAKING_Q };\n }\n return { type: \"peaking\", frequency, Q: PEAKING_Q };\n }),\n);\n\n/** Normalized biquad coefficients [b0, b1, b2, a1, a2] with a0 = 1. */\nexport type BiquadCoefficients = [number, number, number, number, number];\n\n/**\n * @internal Coefficients of one section at `gainDb`, exactly as the Web Audio\n * BiquadFilterNode computes them (spec §BiquadFilterNode, Audio EQ Cookbook).\n */\nexport function sectionCoefficients(section: BandSection, gainDb: number, sampleRate: number): BiquadCoefficients {\n const A = 10 ** (gainDb / 40);\n const w0 = (2 * Math.PI * Math.min(section.frequency, sampleRate / 2)) / sampleRate;\n const cos = Math.cos(w0);\n const sin = Math.sin(w0);\n let b0: number;\n let b1: number;\n let b2: number;\n let a0: number;\n let a1: number;\n let a2: number;\n if (section.type === \"peaking\") {\n const alpha = sin / (2 * section.Q);\n b0 = 1 + alpha * A;\n b1 = -2 * cos;\n b2 = 1 - alpha * A;\n a0 = 1 + alpha / A;\n a1 = -2 * cos;\n a2 = 1 - alpha / A;\n } else {\n // Shelf slope S = 1: alpha = sin(w0)/2 · sqrt(2).\n const twoSqrtAAlpha = 2 * Math.sqrt(A) * (sin / Math.SQRT2);\n if (section.type === \"lowshelf\") {\n b0 = A * (A + 1 - (A - 1) * cos + twoSqrtAAlpha);\n b1 = 2 * A * (A - 1 - (A + 1) * cos);\n b2 = A * (A + 1 - (A - 1) * cos - twoSqrtAAlpha);\n a0 = A + 1 + (A - 1) * cos + twoSqrtAAlpha;\n a1 = -2 * (A - 1 + (A + 1) * cos);\n a2 = A + 1 + (A - 1) * cos - twoSqrtAAlpha;\n } else {\n b0 = A * (A + 1 + (A - 1) * cos + twoSqrtAAlpha);\n b1 = -2 * A * (A - 1 + (A + 1) * cos);\n b2 = A * (A + 1 + (A - 1) * cos - twoSqrtAAlpha);\n a0 = A + 1 - (A - 1) * cos + twoSqrtAAlpha;\n a1 = 2 * (A - 1 - (A + 1) * cos);\n a2 = A + 1 - (A - 1) * cos - twoSqrtAAlpha;\n }\n }\n return [b0 / a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0];\n}\n\n/** Magnitude in dB of normalized coefficients at angular frequency `w` (rad/sample). */\nexport function biquadMagnitudeDb(c: BiquadCoefficients, w: number): number {\n const c1 = Math.cos(w);\n const s1 = Math.sin(w);\n const c2 = Math.cos(2 * w);\n const s2 = Math.sin(2 * w);\n const nr = c[0] + c[1] * c1 + c[2] * c2;\n const ni = c[1] * s1 + c[2] * s2;\n const dr = 1 + c[3] * c1 + c[4] * c2;\n const di = c[3] * s1 + c[4] * s2;\n return 10 * Math.log10((nr * nr + ni * ni) / (dr * dr + di * di));\n}\n\n/** Magnitude in dB of the cascade with section gains `gainsDb` at frequency `hz`. */\nexport function cascadeMagnitudeDb(gainsDb: ArrayLike<number>, hz: number, sampleRate: number): number {\n const w = (2 * Math.PI * Math.min(hz, sampleRate / 2)) / sampleRate;\n let total = 0;\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) {\n if (gainsDb[k] === 0) continue;\n total += biquadMagnitudeDb(sectionCoefficients(BAND_SECTIONS[k], gainsDb[k], sampleRate), w);\n }\n return total;\n}\n\n/** Result of {@link designBandGains}. */\nexport interface BandGainDesign {\n /** Broadband level in dB carried by a gain stage (-Infinity for silence). */\n levelDb: number;\n /** Gain in dB of each cascade section, in {@link BAND_SECTIONS} order. */\n sectionGainsDb: Float64Array;\n}\n\n/** Sections whose frequency is at or above this fraction of the sample rate are left flat. */\nconst MAX_SECTION_FRACTION = 0.45;\nconst DESIGN_TOLERANCE_DB = 0.005;\nconst MAX_ITERATIONS = 40;\nconst JACOBIAN_STEP_DB = 0.25;\n\n/**\n * Solve the section gains for `targetDb` (one value per band, dB, -Infinity\n * allowed). The common level (the largest target) goes to `levelDb`; the\n * cascade renders the remainder relative to it. Targets below `floorDb` are\n * designed at `floorDb`, so the rendered response at those bands is at or below\n * the floor while the section gains stay bounded.\n *\n * Bands whose section frequency is at or above 0.45·fs cannot be shaped at that\n * sample rate; their sections stay flat and their targets are not constrained.\n *\n * @param previous Optional section gains to start the iteration from (the last\n * design of the same stage), which usually converges in one or two steps.\n */\nexport function designBandGains(\n targetDb: ArrayLike<number>,\n sampleRate: number,\n floorDb: number,\n previous?: ArrayLike<number>,\n): BandGainDesign {\n if (targetDb.length !== OCTAVE_BAND_COUNT) {\n throw new RangeError(`Band targets need exactly ${OCTAVE_BAND_COUNT} values, got ${targetDb.length}`);\n }\n let levelDb = Number.NEGATIVE_INFINITY;\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) levelDb = Math.max(levelDb, targetDb[k]);\n const gains = new Float64Array(OCTAVE_BAND_COUNT);\n if (levelDb === Number.NEGATIVE_INFINITY) return { levelDb, sectionGainsDb: gains };\n\n const active: number[] = [];\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) {\n if (BAND_SECTIONS[k].frequency < MAX_SECTION_FRACTION * sampleRate) active.push(k);\n }\n const relative = new Float64Array(OCTAVE_BAND_COUNT);\n const floor = Math.min(floorDb, levelDb);\n for (let k = 0; k < OCTAVE_BAND_COUNT; k++) relative[k] = Math.max(targetDb[k], floor) - levelDb;\n if (active.every((k) => relative[k] === 0)) return { levelDb, sectionGainsDb: gains };\n\n const n = active.length;\n const w = active.map((k) => (2 * Math.PI * Math.min(OCTAVE_BAND_CENTERS[k], sampleRate / 2)) / sampleRate);\n for (let i = 0; i < n; i++) gains[active[i]] = previous ? previous[active[i]] : 0;\n\n // contribution[s][i]: section s's magnitude (dB) at band i for its current gain.\n const contribution = (s: number, gainDb: number): Float64Array => {\n const out = new Float64Array(n);\n if (gainDb === 0) return out;\n const c = sectionCoefficients(BAND_SECTIONS[active[s]], gainDb, sampleRate);\n for (let i = 0; i < n; i++) out[i] = biquadMagnitudeDb(c, w[i]);\n return out;\n };\n const errorOf = (cols: Float64Array[]): Float64Array => {\n const e = new Float64Array(n);\n for (let i = 0; i < n; i++) {\n let r = 0;\n for (let s = 0; s < n; s++) r += cols[s][i];\n e[i] = relative[active[i]] - r;\n }\n return e;\n };\n const maxAbs = (e: Float64Array) => e.reduce((m, x) => Math.max(m, Math.abs(x)), 0);\n\n let cols = active.map((_, s) => contribution(s, gains[active[s]]));\n let error = errorOf(cols);\n let worst = maxAbs(error);\n for (let iteration = 0; iteration < MAX_ITERATIONS && worst > DESIGN_TOLERANCE_DB; iteration++) {\n // Each band's response is a sum over sections, so column s of the Jacobian\n // depends on section s alone.\n const jacobian: number[][] = Array.from({ length: n }, () => new Array<number>(n).fill(0));\n for (let s = 0; s < n; s++) {\n const g = gains[active[s]];\n const up = contribution(s, g + JACOBIAN_STEP_DB);\n const down = contribution(s, g - JACOBIAN_STEP_DB);\n for (let i = 0; i < n; i++) jacobian[i][s] = (up[i] - down[i]) / (2 * JACOBIAN_STEP_DB);\n }\n const step = solveLinear(jacobian, Array.from(error));\n // Damped Newton: halve the step until the worst error decreases.\n let scale = 1;\n let accepted = false;\n for (let attempt = 0; attempt < 12; attempt++) {\n const trial = active.map((k, s) => gains[k] + scale * step[s]);\n const trialCols = trial.map((g, s) => contribution(s, g));\n const trialError = errorOf(trialCols);\n const trialWorst = maxAbs(trialError);\n if (trialWorst < worst) {\n for (let s = 0; s < n; s++) gains[active[s]] = trial[s];\n cols = trialCols;\n error = trialError;\n worst = trialWorst;\n accepted = true;\n break;\n }\n scale /= 2;\n }\n if (!accepted) break;\n }\n return { levelDb, sectionGainsDb: gains };\n}\n\n/** Gaussian elimination with partial pivoting; returns x with A·x = b. */\nfunction solveLinear(a: number[][], b: number[]): number[] {\n const n = b.length;\n const m = a.map((row, i) => [...row, b[i]]);\n for (let col = 0; col < n; col++) {\n let pivot = col;\n for (let r = col + 1; r < n; r++) if (Math.abs(m[r][col]) > Math.abs(m[pivot][col])) pivot = r;\n [m[col], m[pivot]] = [m[pivot], m[col]];\n const p = m[col][col];\n if (p === 0) continue;\n for (let r = 0; r < n; r++) {\n if (r === col) continue;\n const factor = m[r][col] / p;\n if (factor === 0) continue;\n for (let c = col; c <= n; c++) m[r][c] -= factor * m[col][c];\n }\n }\n return m.map((row, i) => (row[i] === 0 ? 0 : row[n] / row[i]));\n}\n\n/**\n * @internal Validate a public band-gain array: exactly eight finite linear\n * gains in [0, 1]. Returns a frozen copy.\n */\nexport function validateBandGains(gains: readonly number[], label: string): readonly number[] {\n if (!Array.isArray(gains) || gains.length !== OCTAVE_BAND_COUNT) {\n throw new RangeError(`${label} needs exactly ${OCTAVE_BAND_COUNT} band gains`);\n }\n for (const gain of gains) {\n if (typeof gain !== \"number\" || !Number.isFinite(gain) || gain < 0 || gain > 1) {\n throw new RangeError(`${label} band gains must be finite numbers in [0, 1]`);\n }\n }\n return Object.freeze([...gains]);\n}\n\n/** @internal Linear gain to dB, with 0 mapping to -Infinity. */\nexport function linearToDb(gain: number): number {\n return gain > 0 ? 20 * Math.log10(gain) : Number.NEGATIVE_INFINITY;\n}\n"],"mappings":";AA4BA,IAAa,IAA+E,OAAO,OAAO;CACxG;CAAK;CAAK;CAAK;CAAM;CAAM;CAAM;CAAM;AACzC,CAAU,GAGG,IAAoB,GAe3B,IAAY,GASZ,IAAqB,KAAK,OAGnB,IAAwC,OAAO,OAC1D,EAAoB,KAAK,GAAW,MAC9B,MAAS,IAAU;CAAE,MAAM;CAAY,WAAW,IAAqB;CAAW,GAAG;AAAU,IAC/F,MAAA,IACK;CAAE,MAAM;CAAa,WAAW,IAAY;CAAoB,GAAG;AAAU,IAE/E;CAAE,MAAM;CAAW;CAAW,GAAG;AAAU,CACnD,CACH;AASA,SAAgB,EAAoB,GAAsB,GAAgB,GAAwC;CAChH,IAAM,IAAI,OAAO,IAAS,KACpB,IAAM,IAAI,KAAK,KAAK,KAAK,IAAI,EAAQ,WAAW,IAAa,CAAC,IAAK,GACnE,IAAM,KAAK,IAAI,CAAE,GACjB,IAAM,KAAK,IAAI,CAAE,GACnB,GACA,GACA,GACA,GACA,GACA;CACJ,IAAI,EAAQ,SAAS,WAAW;EAC9B,IAAM,IAAQ,KAAO,IAAI,EAAQ;EAMjC,AALA,IAAK,IAAI,IAAQ,GACjB,IAAK,KAAK,GACV,IAAK,IAAI,IAAQ,GACjB,IAAK,IAAI,IAAQ,GACjB,IAAK,KAAK,GACV,IAAK,IAAI,IAAQ;CACnB,OAAO;EAEL,IAAM,IAAgB,IAAI,KAAK,KAAK,CAAC,KAAK,IAAM,KAAK;EACrD,AAAI,EAAQ,S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