@woosh/meep-engine 3.74.0 → 3.75.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.
- package/CHANGELOG.md +20 -19
- package/package.json +1 -1
- package/src/core/geom/2d/hilbert/v2_hilbert_encode.d.ts +11 -0
- package/src/core/geom/2d/hilbert/v2_hilbert_encode.d.ts.map +1 -0
- package/src/core/geom/2d/hilbert/v2_hilbert_encode.js +46 -0
- package/src/engine/graphics/render/frame_graph/FrameGraph.d.ts +6 -0
- package/src/engine/graphics/render/frame_graph/FrameGraph.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/FrameGraph.js +9 -0
- package/src/engine/graphics3/GPUAcousticSystem.d.ts +29 -32
- package/src/engine/graphics3/GPUAcousticSystem.d.ts.map +1 -1
- package/src/engine/graphics3/GPUAcousticSystem.js +87 -162
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/engine/sound/ecs/audio/AudioEmitterSystem.d.ts.map +1 -1
- package/src/engine/sound/ecs/audio/AudioEmitterSystem.js +35 -17
- package/src/engine/sound/ecs/audio/LiveEmitterSet.d.ts.map +1 -1
- package/src/engine/sound/ecs/audio/LiveEmitterSet.js +2 -3
- package/src/engine/sound/simulation/AcousticSimulator.d.ts +7 -0
- package/src/engine/sound/simulation/AcousticSimulator.d.ts.map +1 -1
- package/src/engine/sound/simulation/AcousticSimulator.js +27 -0
- package/src/engine/sound/simulation/README.md +121 -107
- package/src/engine/sound/sopra/README.md +8 -3
- package/src/engine/sound/sopra/definition/effect/AcousticReverbEffect.d.ts +2 -2
- package/src/engine/sound/sopra/definition/effect/AcousticReverbEffect.d.ts.map +1 -1
- package/src/engine/sound/sopra/definition/effect/AcousticReverbEffect.js +4 -3
- package/src/engine/sound/sopra/runtime/AcousticReverbConvolution.d.ts +118 -0
- package/src/engine/sound/sopra/runtime/AcousticReverbConvolution.d.ts.map +1 -0
- package/src/engine/sound/sopra/runtime/AcousticReverbConvolution.js +472 -0
- package/src/engine/sound/sopra/runtime/AcousticReverbLines.d.ts +166 -0
- package/src/engine/sound/sopra/runtime/AcousticReverbLines.d.ts.map +1 -0
- package/src/engine/sound/sopra/runtime/AcousticReverbLines.js +447 -0
- package/src/engine/sound/sopra/runtime/AcousticReverbNetwork.d.ts +69 -113
- package/src/engine/sound/sopra/runtime/AcousticReverbNetwork.d.ts.map +1 -1
- package/src/engine/sound/sopra/runtime/AcousticReverbNetwork.js +143 -491
- package/src/engine/sound/sopra/runtime/AcousticSpeakers.d.ts +102 -0
- package/src/engine/sound/sopra/runtime/AcousticSpeakers.d.ts.map +1 -0
- package/src/engine/sound/sopra/runtime/AcousticSpeakers.js +232 -0
- package/src/engine/sound/sopra/runtime/BusGraph.d.ts +17 -3
- package/src/engine/sound/sopra/runtime/BusGraph.d.ts.map +1 -1
- package/src/engine/sound/sopra/runtime/BusGraph.js +55 -5
- package/src/engine/sound/sopra/runtime/EventInstance.d.ts +8 -6
- package/src/engine/sound/sopra/runtime/EventInstance.d.ts.map +1 -1
- package/src/engine/sound/sopra/runtime/EventInstance.js +113 -105
- package/src/engine/sound/sopra/runtime/acoustic_reverb_decay.d.ts +13 -0
- package/src/engine/sound/sopra/runtime/acoustic_reverb_decay.d.ts.map +1 -0
- package/src/engine/sound/sopra/runtime/acoustic_reverb_decay.js +15 -0
- package/src/generation/grid/generation/discrete/GridTaskConnectRooms.d.ts.map +1 -1
- package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +4 -6
- package/src/shade/playground/skinned_blas_refit/diff_traced_against_rasterized.d.ts.map +1 -1
- package/src/shade/playground/skinned_blas_refit/diff_traced_against_rasterized.js +4 -5
- package/src/shade/playground/skinned_blas_refit/main.d.ts.map +1 -1
- package/src/shade/playground/skinned_blas_refit/main.js +6 -12
- package/src/shade/playground/skinned_mesh_soup/main.d.ts.map +1 -1
- package/src/shade/playground/skinned_mesh_soup/main.js +1 -2
- package/src/shade/playground/vgeo_scene/README.md +12 -2
- package/src/shade/playground/vgeo_scene/main.js +1 -1
- package/src/shade/playground/volumetrics_froxel/README.md +191 -191
- package/src/shade/playground/volumetrics_froxel/measure.d.ts +3 -3
- package/src/shade/playground/volumetrics_froxel/measure.d.ts.map +1 -1
- package/src/shade/playground/volumetrics_froxel/measure.js +11 -13
- package/src/shade/playground/vsm/main.d.ts.map +1 -1
- package/src/shade/playground/vsm/main.js +5 -6
- package/src/shade/renderer/Renderer.d.ts.map +1 -1
- package/src/shade/renderer/Renderer.js +31 -8
- package/src/shade/renderer/acoustics/ACOUSTIC_LISTENER_RESOURCES.d.ts +28 -0
- package/src/shade/renderer/acoustics/ACOUSTIC_LISTENER_RESOURCES.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/ACOUSTIC_LISTENER_RESOURCES.js +42 -0
- package/src/shade/renderer/acoustics/ACOUSTIC_PROBE_DATABASE_SPEC.d.ts +58 -0
- package/src/shade/renderer/acoustics/ACOUSTIC_PROBE_DATABASE_SPEC.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/ACOUSTIC_PROBE_DATABASE_SPEC.js +108 -0
- package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +161 -0
- package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/GPUAcousticProbes.js +760 -0
- package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
- package/src/shade/renderer/acoustics/acoustic_listener_order.d.ts +12 -0
- package/src/shade/renderer/acoustics/acoustic_listener_order.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/acoustic_listener_order.js +56 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_direct.d.ts.map +1 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_direct.js +5 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_direct_cone.d.ts +57 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_direct_cone.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_direct_cone.js +314 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_finite.d.ts +15 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_finite.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_finite.js +21 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_gather.js +1 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_lean.d.ts +27 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_lean.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_lean.js +42 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_listener.d.ts +80 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_listener.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_listener.js +274 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_partials.d.ts +2 -2
- package/src/shade/renderer/acoustics/chunk_acoustic_partials.js +2 -2
- package/src/shade/renderer/acoustics/chunk_acoustic_phonon.d.ts +7 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_phonon.d.ts.map +1 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_phonon.js +24 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_resample.js +1 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_reservoir.js +1 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_through.d.ts +43 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_through.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_through.js +153 -0
- package/src/shade/renderer/acoustics/chunk_acoustic_trace.d.ts +3 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_trace.d.ts.map +1 -1
- package/src/shade/renderer/acoustics/chunk_acoustic_trace.js +10 -1
- package/src/shade/renderer/acoustics/shader_acoustic_combine.d.ts +7 -3
- package/src/shade/renderer/acoustics/shader_acoustic_combine.d.ts.map +1 -1
- package/src/shade/renderer/acoustics/shader_acoustic_combine.js +22 -6
- package/src/shade/renderer/acoustics/shader_acoustic_coupling.d.ts +14 -0
- package/src/shade/renderer/acoustics/shader_acoustic_coupling.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/shader_acoustic_coupling.js +102 -0
- package/src/shade/renderer/acoustics/shader_acoustic_listener.d.ts +12 -0
- package/src/shade/renderer/acoustics/shader_acoustic_listener.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/shader_acoustic_listener.js +80 -0
- package/src/shade/renderer/acoustics/shader_acoustic_receive.d.ts.map +1 -1
- package/src/shade/renderer/acoustics/shader_acoustic_receive.js +27 -6
- package/src/shade/renderer/acoustics/shader_acoustic_room.d.ts +11 -0
- package/src/shade/renderer/acoustics/shader_acoustic_room.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/shader_acoustic_room.js +111 -0
- package/src/shade/renderer/acoustics/shader_acoustic_source.d.ts +18 -0
- package/src/shade/renderer/acoustics/shader_acoustic_source.d.ts.map +1 -0
- package/src/shade/renderer/acoustics/shader_acoustic_source.js +130 -0
- package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
- package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
- package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -7
- package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
- package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
- package/src/shade/renderer/geometry/virtual/build/level/VGeoFrontier.d.ts +2 -2
- package/src/shade/renderer/geometry/virtual/build/level/VGeoFrontier.js +2 -2
- package/src/shade/renderer/geometry/virtual/build/level/VGeoLevelOptions.d.ts +5 -2
- package/src/shade/renderer/geometry/virtual/build/level/VGeoLevelOptions.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/build/level/VGeoLevelOptions.js +5 -2
- package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.d.ts +9 -2
- package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.js +48 -12
- package/src/shade/renderer/geometry/virtual/format/read/VGeoContainerReader.d.ts +0 -22
- package/src/shade/renderer/geometry/virtual/format/read/VGeoContainerReader.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/format/read/VGeoContainerReader.js +0 -42
- package/src/shade/renderer/geometry/virtual/format/read/VGeoReadOptions.d.ts +2 -18
- package/src/shade/renderer/geometry/virtual/format/read/VGeoReadOptions.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/format/read/VGeoReadOptions.js +2 -19
- package/src/shade/renderer/geometry/virtual/format/read/vgeo_page_worker_serve.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/format/read/vgeo_page_worker_serve.js +0 -1
- package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.d.ts +5 -4
- package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.js +3 -1
- package/src/shade/renderer/geometry/virtual/runtime/VGeoFeedbackLoop.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/runtime/VGeoFeedbackLoop.js +3 -1
- package/src/shade/renderer/geometry/virtual/runtime/VGeoPageFetcher.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/runtime/VGeoPageFetcher.js +0 -1
- package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.d.ts +60 -14
- package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.js +75 -39
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts +0 -9
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.js +45 -17
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts +7 -3
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +43 -7
- package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
- package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { biquad_magnitude_db, biquad_shelf_coefficients } from "../util/biquad_shelf.js";
|
|
2
|
+
import { LOW_MID_HZ, MID_HIGH_HZ } from "../util/reverb_band_tails.js";
|
|
3
|
+
import { acoustic_ramp } from "./acoustic_writes.js";
|
|
4
|
+
import { ACOUSTIC_REVERB_BAND_CENTRES, RT60_PER_CENTRE_TIME } from "./acoustic_reverb_decay.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The network's delay lines, in samples at 48 kHz: eight distinct primes from 25 to 59 ms, so no two lines share an
|
|
8
|
+
* echo and every line is many render quanta (128 frames) long, which a Web Audio cycle needs at least.
|
|
9
|
+
* @type {number[]}
|
|
10
|
+
*/
|
|
11
|
+
const LINE_SAMPLES_48K = [1201, 1433, 1667, 1913, 2129, 2357, 2621, 2851];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Delay lines of the network, `N`.
|
|
15
|
+
* @type {number}
|
|
16
|
+
*/
|
|
17
|
+
export const ACOUSTIC_REVERB_LINES = LINE_SAMPLES_48K.length;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The sign each line is heard with: the even lines go left and the odd right, and within each side they alternate,
|
|
21
|
+
* `+ + − − + + − −`, so that each side's signs sum to zero. The Householder matrix puts `−2/N` of every line's sum
|
|
22
|
+
* back into every line at once; at low frequencies, where the lines' delays differ by a fraction of a period, that
|
|
23
|
+
* common part stays in phase across the lines, and summed with one sign it added up coherently — 1.1 to 1.8 dB more
|
|
24
|
+
* tail than sent in the low band, measured. With the signs it cancels.
|
|
25
|
+
* @type {number[]}
|
|
26
|
+
*/
|
|
27
|
+
export const ACOUSTIC_REVERB_OUTPUT_SIGNS = Array.from({ length: LINE_SAMPLES_48K.length }, (_, i) => Math.floor(i / 2) % 2 === 0 ? 1 : -1);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The sign each line is summed with into the directional share: the first half straight, the second inverted. Within
|
|
31
|
+
* each side the signs it is heard with there ({@link ACOUSTIC_REVERB_OUTPUT_SIGNS}) and these are orthogonal, `+ − + −`
|
|
32
|
+
* against `+ + − −`, so the directional sum shares no signal with either side, and its energy and the diffuse pair's
|
|
33
|
+
* add whatever the lean. They sum to zero too, so the Householder matrix's common part cancels in it as in the
|
|
34
|
+
* sides.
|
|
35
|
+
* @type {number[]}
|
|
36
|
+
*/
|
|
37
|
+
export const ACOUSTIC_REVERB_DIRECTIONAL_SIGNS = Array.from({ length: LINE_SAMPLES_48K.length }, (_, i) => i < LINE_SAMPLES_48K.length / 2 ? 1 : -1);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Frames a Web Audio cycle adds to the delay in it, at the default render quantum: Chromium renders a `DelayNode` in a
|
|
41
|
+
* cycle a render quantum late, so a line set to `d` comes round in `d + 128` frames (a context with another quantum,
|
|
42
|
+
* `renderQuantumSize`, adds that). A line's node is set that much short, never below one quantum, so that it comes
|
|
43
|
+
* round in its delay. An engine that adds none would come round 2.7 ms early, and decay 4 to 11% fast. The lines are
|
|
44
|
+
* chosen for quanta well under the shortest of them (1201 frames at 48 kHz); a context rendering in quanta near that
|
|
45
|
+
* long cannot hold their lengths apart.
|
|
46
|
+
*
|
|
47
|
+
* Chromium adds the quantum only on the loop edges it reaches out of its processing order, so the edges through the
|
|
48
|
+
* Householder summing gain do not all see it, and the network Chrome plays is not exactly the one modelled here
|
|
49
|
+
* (`simulation/PATH_TRACED_RESEARCH.md`).
|
|
50
|
+
* @type {number}
|
|
51
|
+
*/
|
|
52
|
+
export const ACOUSTIC_REVERB_CYCLE_FRAMES = 128;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Each line's delay, seconds.
|
|
56
|
+
* @type {Float64Array}
|
|
57
|
+
*/
|
|
58
|
+
export const ACOUSTIC_REVERB_DELAYS = Float64Array.from(LINE_SAMPLES_48K, samples => samples / 48000);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The energy of the tail an impulse of unit amplitude into every line (±1) leaves, at centre time `T_s`, seconds:
|
|
62
|
+
* what an input gain of `1 / sqrt` of it turns into a tail of the energy sent.
|
|
63
|
+
*
|
|
64
|
+
* Every sample written to a line is read out once, then filtered and mixed back. Follow a unit of energy: read from
|
|
65
|
+
* line `i` (one unit out), it keeps `e_i = e^(−D_i / T_s)` of its energy through the line's filters (Jot's rule,
|
|
66
|
+
* squared), and the Householder matrix sends the share `A_ji²` of that into line `j`, which is `(1 − 2/N)²` back
|
|
67
|
+
* into its own line and `4/N²` into each other. What it reads out in all, from line `i`, is then
|
|
68
|
+
* `v_i = 1 + e_i Σ_j A_ji² v_j`, which with `α = 1 − 4/N` and `β = 4/N²` is
|
|
69
|
+
* `v_i = (1 + β e_i S) / (1 − α e_i)`, `S = Σ v_i`, and summing,
|
|
70
|
+
*
|
|
71
|
+
* S = Σ 1/(1 − α e_i) / (1 − β Σ e_i/(1 − α e_i))
|
|
72
|
+
*
|
|
73
|
+
* in expectation over the lines' phases, which a band of many modes averages over. Not `T_s` times a constant: a
|
|
74
|
+
* dead room loses most of a sample's energy in one pass, and a sample keeps to its own line half the time, so the
|
|
75
|
+
* read-out rate is not the lines' mean. Derived; pinned against the network rendered sample by sample.
|
|
76
|
+
*
|
|
77
|
+
* @param {number} centre_time seconds, above 0
|
|
78
|
+
* @returns {number}
|
|
79
|
+
*/
|
|
80
|
+
export function acoustic_reverb_tail_energy(centre_time) {
|
|
81
|
+
const N = ACOUSTIC_REVERB_LINES;
|
|
82
|
+
const alpha = 1 - 4 / N;
|
|
83
|
+
const beta = 4 / (N * N);
|
|
84
|
+
|
|
85
|
+
let open = 0;
|
|
86
|
+
let carried = 0;
|
|
87
|
+
|
|
88
|
+
for (let i = 0; i < N; i++) {
|
|
89
|
+
const e = Math.exp(-ACOUSTIC_REVERB_DELAYS[i] / centre_time);
|
|
90
|
+
const kept = 1 / (1 - alpha * e);
|
|
91
|
+
|
|
92
|
+
open += kept;
|
|
93
|
+
carried += e * kept;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return open / (1 - beta * carried);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Shelf gain, dB, the shelves' response is measured at to set them: small, where it scales with the gain. */
|
|
100
|
+
const CALIBRATION_DB = 1;
|
|
101
|
+
|
|
102
|
+
/** Scratch for a shelf's coefficients. */
|
|
103
|
+
const COEFFICIENTS = new Float64Array(5);
|
|
104
|
+
|
|
105
|
+
/** Scratch: a line's gain (linear) and its two shelves (dB), as sent and as they rest. */
|
|
106
|
+
const VALUES = new Float64Array(3);
|
|
107
|
+
const RESTS = new Float64Array(3);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A line's gain and shelves for the centre times `centre`: Jot's rule, `10^(−3d / RT60)` a pass per band, solved for
|
|
111
|
+
* the gain and the two shelves through the shelves' calibrated response; passive, the gain only loses and no shelf
|
|
112
|
+
* lifts its band above what the gain leaves.
|
|
113
|
+
*
|
|
114
|
+
* @param {Float64Array} solve the calibration's inverse, 3×3
|
|
115
|
+
* @param {ArrayLike<number>} centre centre times, seconds, per band
|
|
116
|
+
* @param {number} d the line's delay, seconds
|
|
117
|
+
* @param {Float64Array} out the gain, linear; the low shelf and the high, dB
|
|
118
|
+
*/
|
|
119
|
+
function line_values(solve, centre, d, out) {
|
|
120
|
+
const t0 = -60 * d / (RT60_PER_CENTRE_TIME * centre[0]);
|
|
121
|
+
const t1 = -60 * d / (RT60_PER_CENTRE_TIME * centre[1]);
|
|
122
|
+
const t2 = -60 * d / (RT60_PER_CENTRE_TIME * centre[2]);
|
|
123
|
+
|
|
124
|
+
const gain = Math.min(0, solve[0] * t0 + solve[1] * t1 + solve[2] * t2);
|
|
125
|
+
|
|
126
|
+
out[0] = Math.pow(10, gain / 20);
|
|
127
|
+
out[1] = Math.min(-gain, solve[3] * t0 + solve[4] * t1 + solve[5] * t2);
|
|
128
|
+
out[2] = Math.min(-gain, solve[6] * t0 + solve[7] * t1 + solve[8] * t2);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Invert a 3×3 matrix, row-major.
|
|
133
|
+
*
|
|
134
|
+
* @param {Float64Array} m nine numbers
|
|
135
|
+
* @param {Float64Array} out nine numbers
|
|
136
|
+
*/
|
|
137
|
+
function invert3(m, out) {
|
|
138
|
+
const a = m[0], b = m[1], c = m[2];
|
|
139
|
+
const d = m[3], e = m[4], f = m[5];
|
|
140
|
+
const g = m[6], h = m[7], i = m[8];
|
|
141
|
+
|
|
142
|
+
const A = e * i - f * h;
|
|
143
|
+
const B = f * g - d * i;
|
|
144
|
+
const C = d * h - e * g;
|
|
145
|
+
const inverse = 1 / (a * A + b * B + c * C);
|
|
146
|
+
|
|
147
|
+
out[0] = A * inverse;
|
|
148
|
+
out[1] = (c * h - b * i) * inverse;
|
|
149
|
+
out[2] = (b * f - c * e) * inverse;
|
|
150
|
+
out[3] = B * inverse;
|
|
151
|
+
out[4] = (a * i - c * g) * inverse;
|
|
152
|
+
out[5] = (c * d - a * f) * inverse;
|
|
153
|
+
out[6] = C * inverse;
|
|
154
|
+
out[7] = (b * g - a * h) * inverse;
|
|
155
|
+
out[8] = (a * e - b * d) * inverse;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* # A tank of the acoustic reverb: one feedback delay network
|
|
160
|
+
*
|
|
161
|
+
* GPU acoustics design, "The reverb: one feedback delay network" (F1). Not what `AcousticReverbEffect` builds now
|
|
162
|
+
* (that is `AcousticReverbConvolution`); kept, with its specs, for the path-traced acoustics it was made for
|
|
163
|
+
* (`simulation/PATH_TRACED_RESEARCH.md`): it decays as an `AudioParam` moves, with no impulse response to make, but its
|
|
164
|
+
* echo density is low (a diffuse tail only after half a second) and Chromium's uneven loop edges keep it from being
|
|
165
|
+
* exactly the network modelled here.
|
|
166
|
+
*
|
|
167
|
+
* **The network.** {@link ACOUSTIC_REVERB_LINES} `DelayNode`s ({@link ACOUSTIC_REVERB_DELAYS}, each set short by what the
|
|
168
|
+
* cycle adds, {@link ACOUSTIC_REVERB_CYCLE_FRAMES}). Each line's output passes a lowshelf at 250 Hz, a highshelf at
|
|
169
|
+
* 2,500 Hz and a gain, and returns to every line through a Householder matrix, `I − (2/N)·11ᵀ`: to its own line whole,
|
|
170
|
+
* and to all of them through one summing gain of `−2/N`. The matrix is orthogonal, so the loop loses only what the
|
|
171
|
+
* lines' filters take. Fed from {@link input}, to the even lines as it is and to the odd ones inverted.
|
|
172
|
+
*
|
|
173
|
+
* **Decay (Jot's rule).** A line `d` seconds long is attenuated by `10^(−3d / RT60_b)` a pass in band `b`, so that
|
|
174
|
+
* every path through the network falls by 60 dB in `RT60_b` whatever lines it took. Jot and Chaigne's attenuation rule,
|
|
175
|
+
* here derived as stated rather than read from their paper. The three bands' per-pass gains are realised by the
|
|
176
|
+
* shelves and the gain together, solved at each band's centre ({@link ACOUSTIC_REVERB_BAND_CENTRES}) from the shelves'
|
|
177
|
+
* response there, which at a few dB scales with their gain. Shelves, not a crossover, because a crossover's bands
|
|
178
|
+
* overshoot near its edges and a gain above one in a feedback loop runs away; a shelf's response lies between its two
|
|
179
|
+
* gains. The solution is held passive: no shelf lifts a band above the gain the others leave it.
|
|
180
|
+
*
|
|
181
|
+
* **Level.** A send of energy `E` is scaled by one over the root of {@link acoustic_reverb_tail_energy} at its band's
|
|
182
|
+
* `T_s` ({@link send_gain}), so it leaves a tail of energy `E` at any decay time.
|
|
183
|
+
*
|
|
184
|
+
* **Outputs.** The lines go to a stereo pair, the even lines left and the odd right, each with its sign
|
|
185
|
+
* ({@link ACOUSTIC_REVERB_OUTPUT_SIGNS}), and are summed with other signs, orthogonal to both sides'
|
|
186
|
+
* ({@link ACOUSTIC_REVERB_DIRECTIONAL_SIGNS}), into {@link mono}, the directional share.
|
|
187
|
+
*/
|
|
188
|
+
export class AcousticReverbLines {
|
|
189
|
+
/**
|
|
190
|
+
* Where the scaled send enters: it feeds the even lines, and its inversion the odd.
|
|
191
|
+
* @type {GainNode}
|
|
192
|
+
*/
|
|
193
|
+
input;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The diffuse pair.
|
|
197
|
+
* @type {ChannelMergerNode}
|
|
198
|
+
*/
|
|
199
|
+
stereo;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The directional sum: every line with its sign of {@link ACOUSTIC_REVERB_DIRECTIONAL_SIGNS}.
|
|
203
|
+
* @type {GainNode}
|
|
204
|
+
*/
|
|
205
|
+
mono;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The shortest centre time the network can play, seconds: its first echo, as soon as it can answer.
|
|
209
|
+
* @type {number}
|
|
210
|
+
*/
|
|
211
|
+
shortest = ACOUSTIC_REVERB_DELAYS[0];
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The lines, and each line's lowshelf, highshelf and gain, by line: for inspection; {@link set_decay} moves them.
|
|
215
|
+
* @type {DelayNode[]}
|
|
216
|
+
*/
|
|
217
|
+
delays = [];
|
|
218
|
+
|
|
219
|
+
/** @type {BiquadFilterNode[]} */
|
|
220
|
+
lowShelves = [];
|
|
221
|
+
|
|
222
|
+
/** @type {BiquadFilterNode[]} */
|
|
223
|
+
highShelves = [];
|
|
224
|
+
|
|
225
|
+
/** @type {GainNode[]} */
|
|
226
|
+
lineGains = [];
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The Householder matrix's summing gain, `−2/N`. For inspection.
|
|
230
|
+
* @type {GainNode}
|
|
231
|
+
*/
|
|
232
|
+
householder;
|
|
233
|
+
|
|
234
|
+
/** The input's inversion, which feeds the odd lines. */
|
|
235
|
+
#inverted;
|
|
236
|
+
|
|
237
|
+
/** The lines' outputs summed inverted into {@link mono}. */
|
|
238
|
+
#monoInverted;
|
|
239
|
+
|
|
240
|
+
/** Each side's lines heard inverted, left and right. */
|
|
241
|
+
#inverts = [];
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The matrix that turns a line's per-pass gains at the band centres, dB, into its gain, lowshelf and highshelf, dB.
|
|
245
|
+
* @type {Float64Array}
|
|
246
|
+
*/
|
|
247
|
+
#solve = new Float64Array(9);
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @param {BaseAudioContext} ctx
|
|
251
|
+
*/
|
|
252
|
+
constructor(ctx) {
|
|
253
|
+
const N = ACOUSTIC_REVERB_LINES;
|
|
254
|
+
|
|
255
|
+
const feed = ctx.createGain();
|
|
256
|
+
const inverted = ctx.createGain();
|
|
257
|
+
|
|
258
|
+
inverted.gain.setValueAtTime(-1, 0);
|
|
259
|
+
feed.connect(inverted);
|
|
260
|
+
|
|
261
|
+
this.input = feed;
|
|
262
|
+
this.#inverted = inverted;
|
|
263
|
+
|
|
264
|
+
const householder = ctx.createGain();
|
|
265
|
+
|
|
266
|
+
householder.gain.setValueAtTime(-2 / N, 0);
|
|
267
|
+
this.householder = householder;
|
|
268
|
+
|
|
269
|
+
const stereo = ctx.createChannelMerger(2);
|
|
270
|
+
const mono = ctx.createGain();
|
|
271
|
+
const mono_inverted = ctx.createGain();
|
|
272
|
+
|
|
273
|
+
mono_inverted.gain.setValueAtTime(-1, 0);
|
|
274
|
+
mono_inverted.connect(mono);
|
|
275
|
+
|
|
276
|
+
this.stereo = stereo;
|
|
277
|
+
this.mono = mono;
|
|
278
|
+
this.#monoInverted = mono_inverted;
|
|
279
|
+
|
|
280
|
+
for (let side = 0; side < 2; side++) {
|
|
281
|
+
const invert = ctx.createGain();
|
|
282
|
+
|
|
283
|
+
invert.gain.setValueAtTime(-1, 0);
|
|
284
|
+
invert.connect(stereo, 0, side);
|
|
285
|
+
|
|
286
|
+
this.#inverts.push(invert);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const sample_rate = ctx.sampleRate;
|
|
290
|
+
|
|
291
|
+
// what a cycle adds: the context's render quantum where it says, else the default; and never a line shorter than
|
|
292
|
+
// a quantum, which a cycle cannot have
|
|
293
|
+
const quantum = ctx.renderQuantumSize > 0 ? ctx.renderQuantumSize : ACOUSTIC_REVERB_CYCLE_FRAMES;
|
|
294
|
+
|
|
295
|
+
for (let i = 0; i < N; i++) {
|
|
296
|
+
const delay = ctx.createDelay(ACOUSTIC_REVERB_DELAYS[i]);
|
|
297
|
+
|
|
298
|
+
// a whole number of frames at the context's rate, which a delay reads without interpolating, less what the
|
|
299
|
+
// cycle adds
|
|
300
|
+
delay.delayTime.setValueAtTime(Math.max(quantum, Math.round(ACOUSTIC_REVERB_DELAYS[i] * sample_rate) - quantum) / sample_rate, 0);
|
|
301
|
+
|
|
302
|
+
const low = ctx.createBiquadFilter();
|
|
303
|
+
|
|
304
|
+
low.type = 'lowshelf';
|
|
305
|
+
low.frequency.setValueAtTime(LOW_MID_HZ, 0);
|
|
306
|
+
low.gain.setValueAtTime(0, 0);
|
|
307
|
+
|
|
308
|
+
const high = ctx.createBiquadFilter();
|
|
309
|
+
|
|
310
|
+
high.type = 'highshelf';
|
|
311
|
+
high.frequency.setValueAtTime(MID_HIGH_HZ, 0);
|
|
312
|
+
high.gain.setValueAtTime(0, 0);
|
|
313
|
+
|
|
314
|
+
// silent until the first decay is sent: nothing circulates before it
|
|
315
|
+
const gain = ctx.createGain();
|
|
316
|
+
|
|
317
|
+
gain.gain.setValueAtTime(0, 0);
|
|
318
|
+
|
|
319
|
+
(i % 2 === 0 ? feed : inverted).connect(delay);
|
|
320
|
+
|
|
321
|
+
delay.connect(low);
|
|
322
|
+
low.connect(high);
|
|
323
|
+
high.connect(gain);
|
|
324
|
+
|
|
325
|
+
// the Householder matrix: the line's own share whole, every line's through the summing gain
|
|
326
|
+
gain.connect(delay);
|
|
327
|
+
gain.connect(householder);
|
|
328
|
+
|
|
329
|
+
// the even lines left, the odd right, each with its sign; all of them to the directional sum, with theirs
|
|
330
|
+
if (ACOUSTIC_REVERB_OUTPUT_SIGNS[i] > 0) {
|
|
331
|
+
delay.connect(stereo, 0, i % 2);
|
|
332
|
+
} else {
|
|
333
|
+
delay.connect(this.#inverts[i % 2]);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
delay.connect(ACOUSTIC_REVERB_DIRECTIONAL_SIGNS[i] > 0 ? mono : mono_inverted);
|
|
337
|
+
|
|
338
|
+
this.delays.push(delay);
|
|
339
|
+
this.lowShelves.push(low);
|
|
340
|
+
this.highShelves.push(high);
|
|
341
|
+
this.lineGains.push(gain);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
for (let i = 0; i < N; i++) {
|
|
345
|
+
householder.connect(this.delays[i]);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this.#calibrate(sample_rate);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* The shelves' response at the band centres, as a share of their gain, at this sample rate: the matrix a line's
|
|
353
|
+
* targets are solved through.
|
|
354
|
+
*
|
|
355
|
+
* @param {number} sample_rate
|
|
356
|
+
*/
|
|
357
|
+
#calibrate(sample_rate) {
|
|
358
|
+
const m = new Float64Array(9);
|
|
359
|
+
|
|
360
|
+
for (let k = 0; k < 3; k++) {
|
|
361
|
+
const f = ACOUSTIC_REVERB_BAND_CENTRES[k];
|
|
362
|
+
|
|
363
|
+
m[3 * k] = 1;
|
|
364
|
+
m[3 * k + 1] = biquad_magnitude_db(biquad_shelf_coefficients(COEFFICIENTS, false, LOW_MID_HZ, CALIBRATION_DB, sample_rate), f, sample_rate) / CALIBRATION_DB;
|
|
365
|
+
m[3 * k + 2] = biquad_magnitude_db(biquad_shelf_coefficients(COEFFICIENTS, true, MID_HIGH_HZ, CALIBRATION_DB, sample_rate), f, sample_rate) / CALIBRATION_DB;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
invert3(m, this.#solve);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The amplitude a band's send enters at for a tail of the energy sent: one over the root of
|
|
373
|
+
* {@link acoustic_reverb_tail_energy}.
|
|
374
|
+
*
|
|
375
|
+
* @param {number} centre_time seconds
|
|
376
|
+
* @returns {number}
|
|
377
|
+
*/
|
|
378
|
+
send_gain(centre_time) {
|
|
379
|
+
return 1 / Math.sqrt(acoustic_reverb_tail_energy(centre_time));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Set the decay: each line's gain and shelves, at once where `interval` is 0, else as a ramp over it.
|
|
384
|
+
*
|
|
385
|
+
* @param {ArrayLike<number>} centre centre times, seconds, per band
|
|
386
|
+
* @param {ArrayLike<number>} sent the centre times last set, per band; read where `resting`
|
|
387
|
+
* @param {number} now context time
|
|
388
|
+
* @param {number} interval seconds the write ramps over; 0 sets it at once
|
|
389
|
+
* @param {boolean} resting whether the last write has arrived, so the params rest at what `sent` set
|
|
390
|
+
*/
|
|
391
|
+
set_decay(centre, sent, now, interval, resting) {
|
|
392
|
+
const solve = this.#solve;
|
|
393
|
+
|
|
394
|
+
for (let i = 0; i < ACOUSTIC_REVERB_LINES; i++) {
|
|
395
|
+
const d = ACOUSTIC_REVERB_DELAYS[i];
|
|
396
|
+
|
|
397
|
+
if (resting) {
|
|
398
|
+
line_values(solve, sent, d, RESTS);
|
|
399
|
+
} else {
|
|
400
|
+
RESTS.fill(NaN);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
line_values(solve, centre, d, VALUES);
|
|
404
|
+
|
|
405
|
+
if (interval === 0) {
|
|
406
|
+
this.lineGains[i].gain.setValueAtTime(VALUES[0], now);
|
|
407
|
+
this.lowShelves[i].gain.setValueAtTime(VALUES[1], now);
|
|
408
|
+
this.highShelves[i].gain.setValueAtTime(VALUES[2], now);
|
|
409
|
+
} else {
|
|
410
|
+
acoustic_ramp(this.lineGains[i].gain, VALUES[0], now, interval, RESTS[0]);
|
|
411
|
+
acoustic_ramp(this.lowShelves[i].gain, VALUES[1], now, interval, RESTS[1]);
|
|
412
|
+
acoustic_ramp(this.highShelves[i].gain, VALUES[2], now, interval, RESTS[2]);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Each frame: nothing, since the lines' params carry the decay as it is set.
|
|
419
|
+
*
|
|
420
|
+
* @param {number} now context time
|
|
421
|
+
* @param {number} interval seconds
|
|
422
|
+
*/
|
|
423
|
+
update(now, interval) {
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Unwire the tank.
|
|
428
|
+
*/
|
|
429
|
+
disconnect() {
|
|
430
|
+
this.input.disconnect();
|
|
431
|
+
this.#inverted.disconnect();
|
|
432
|
+
this.mono.disconnect();
|
|
433
|
+
this.#monoInverted.disconnect();
|
|
434
|
+
this.#inverts[0].disconnect();
|
|
435
|
+
this.#inverts[1].disconnect();
|
|
436
|
+
|
|
437
|
+
for (let i = 0; i < ACOUSTIC_REVERB_LINES; i++) {
|
|
438
|
+
this.delays[i].disconnect();
|
|
439
|
+
this.lowShelves[i].disconnect();
|
|
440
|
+
this.highShelves[i].disconnect();
|
|
441
|
+
this.lineGains[i].disconnect();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
this.householder.disconnect();
|
|
445
|
+
this.stereo.disconnect();
|
|
446
|
+
}
|
|
447
|
+
}
|