@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
|
@@ -1,106 +1,20 @@
|
|
|
1
|
-
import { LOW_MID_HZ, MID_HIGH_HZ } from "../util/reverb_band_tails.js";
|
|
2
|
-
import { biquad_magnitude_db, biquad_shelf_coefficients } from "../util/biquad_shelf.js";
|
|
3
1
|
import { build3BandSplit, build3BandTaps, ramp3BandGains, set3BandGains } from "../util/three_band_split.js";
|
|
4
2
|
import {
|
|
5
3
|
ACOUSTIC_DECAY_DEADBAND,
|
|
6
|
-
ACOUSTIC_DIRECTION_DEADBAND,
|
|
7
4
|
acoustic_gains_moved,
|
|
8
5
|
acoustic_ramp,
|
|
9
6
|
acoustic_resting
|
|
10
7
|
} from "./acoustic_writes.js";
|
|
8
|
+
import { AcousticSpeakerFeed, AcousticSpeakers } from "./AcousticSpeakers.js";
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @type {number[]}
|
|
11
|
+
* @typedef {import("./AcousticReverbConvolution.js").AcousticReverbConvolution} AcousticReverbConvolution
|
|
12
|
+
* @typedef {import("./AcousticReverbLines.js").AcousticReverbLines} AcousticReverbLines
|
|
16
13
|
*/
|
|
17
|
-
const LINE_SAMPLES_48K = [1201, 1433, 1667, 1913, 2129, 2357, 2621, 2851];
|
|
18
14
|
|
|
19
15
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export const ACOUSTIC_REVERB_LINES = LINE_SAMPLES_48K.length;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The sign each line is heard with: the even lines go left and the odd right, and within each side they alternate,
|
|
27
|
-
* `+ + − − + + − −`, so that each side's signs sum to zero. The Householder matrix puts `−2/N` of every line's sum
|
|
28
|
-
* back into every line at once; at low frequencies, where the lines' delays differ by a fraction of a period, that
|
|
29
|
-
* common part stays in phase across the lines, and summed with one sign it added up coherently — 1.1 to 1.8 dB more
|
|
30
|
-
* tail than sent in the low band, measured. With the signs it cancels.
|
|
31
|
-
* @type {number[]}
|
|
32
|
-
*/
|
|
33
|
-
export const ACOUSTIC_REVERB_OUTPUT_SIGNS = Array.from({ length: LINE_SAMPLES_48K.length }, (_, i) => Math.floor(i / 2) % 2 === 0 ? 1 : -1);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Each line's delay, seconds.
|
|
37
|
-
* @type {Float64Array}
|
|
38
|
-
*/
|
|
39
|
-
export const ACOUSTIC_REVERB_DELAYS = Float64Array.from(LINE_SAMPLES_48K, samples => samples / 48000);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The energy of the tail an impulse of unit amplitude into every line (±1) leaves, at centre time `T_s`, seconds:
|
|
43
|
-
* what an input gain of `1 / sqrt` of it turns into a tail of the energy sent.
|
|
44
|
-
*
|
|
45
|
-
* Every sample written to a line is read out once, then filtered and mixed back. Follow a unit of energy: read from
|
|
46
|
-
* 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,
|
|
47
|
-
* squared), and the Householder matrix sends the share `A_ji²` of that into line `j`, which is `(1 − 2/N)²` back
|
|
48
|
-
* into its own line and `4/N²` into each other. What it reads out in all, from line `i`, is then
|
|
49
|
-
* `v_i = 1 + e_i Σ_j A_ji² v_j`, which with `α = 1 − 4/N` and `β = 4/N²` is
|
|
50
|
-
* `v_i = (1 + β e_i S) / (1 − α e_i)`, `S = Σ v_i`, and summing,
|
|
51
|
-
*
|
|
52
|
-
* S = Σ 1/(1 − α e_i) / (1 − β Σ e_i/(1 − α e_i))
|
|
53
|
-
*
|
|
54
|
-
* in expectation over the lines' phases, which a band of many modes averages over. Not `T_s` times a constant: a
|
|
55
|
-
* 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
|
|
56
|
-
* read-out rate is not the lines' mean. Derived; pinned against the network rendered sample by sample.
|
|
57
|
-
*
|
|
58
|
-
* @param {number} centre_time seconds, above 0
|
|
59
|
-
* @returns {number}
|
|
60
|
-
*/
|
|
61
|
-
export function acoustic_reverb_tail_energy(centre_time) {
|
|
62
|
-
const N = ACOUSTIC_REVERB_LINES;
|
|
63
|
-
const alpha = 1 - 4 / N;
|
|
64
|
-
const beta = 4 / (N * N);
|
|
65
|
-
|
|
66
|
-
let open = 0;
|
|
67
|
-
let carried = 0;
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < N; i++) {
|
|
70
|
-
const e = Math.exp(-ACOUSTIC_REVERB_DELAYS[i] / centre_time);
|
|
71
|
-
const kept = 1 / (1 - alpha * e);
|
|
72
|
-
|
|
73
|
-
open += kept;
|
|
74
|
-
carried += e * kept;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return open / (1 - beta * carried);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Reverberation time over centre time for an exponential tail: the energy falls by 60 dB in `6 ln 10` of its time
|
|
82
|
-
* constants, and the centre time of an exponential is its time constant.
|
|
83
|
-
* @type {number}
|
|
84
|
-
*/
|
|
85
|
-
export const RT60_PER_CENTRE_TIME = 6 * Math.LN10;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The frequencies each band's decay is set at: the geometric centres of 31.25–250 Hz, 250–2,500 Hz and 2.5–20 kHz,
|
|
89
|
-
* the outer bands closed at the audible range's ends.
|
|
90
|
-
* @type {number[]}
|
|
91
|
-
*/
|
|
92
|
-
export const ACOUSTIC_REVERB_BAND_CENTRES = [Math.sqrt(31.25 * LOW_MID_HZ), Math.sqrt(LOW_MID_HZ * MID_HIGH_HZ), Math.sqrt(MID_HIGH_HZ * 20000)];
|
|
93
|
-
|
|
94
|
-
/** Shelf gain, dB, the shelves' response is measured at to set them: small, where it scales with the gain. */
|
|
95
|
-
const CALIBRATION_DB = 1;
|
|
96
|
-
|
|
97
|
-
/** Scratch for a shelf's coefficients. */
|
|
98
|
-
const COEFFICIENTS = new Float64Array(5);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Scratch: the lean's unit direction on its way to the panner, handed over in an array rather than as arguments,
|
|
103
|
-
* which would box each into a new heap number a frame.
|
|
16
|
+
* Scratch: the lean's direction on its way to the speakers, handed over in an array rather than as arguments, which
|
|
17
|
+
* would box each into a new heap number a frame.
|
|
104
18
|
*/
|
|
105
19
|
const TOWARD = new Float64Array(3);
|
|
106
20
|
|
|
@@ -108,34 +22,10 @@ const TOWARD = new Float64Array(3);
|
|
|
108
22
|
const RAMP_DECAY = 0;
|
|
109
23
|
const RAMP_OUTPUT = 1;
|
|
110
24
|
const RAMP_SHARES = 2;
|
|
111
|
-
const RAMP_PANNER = 3;
|
|
112
25
|
|
|
113
|
-
/** Scratch:
|
|
114
|
-
const VALUES = new Float64Array(3);
|
|
26
|
+
/** Scratch: the input's band gains as they rest. */
|
|
115
27
|
const RESTS = new Float64Array(3);
|
|
116
28
|
|
|
117
|
-
/**
|
|
118
|
-
* A line's gain and shelves for the centre times `centre`: Jot's rule, `10^(−3d / RT60)` a pass per band, solved for
|
|
119
|
-
* the gain and the two shelves through the shelves' calibrated response; passive, the gain only loses and no shelf
|
|
120
|
-
* lifts its band above what the gain leaves.
|
|
121
|
-
*
|
|
122
|
-
* @param {Float64Array} solve the calibration's inverse, 3×3
|
|
123
|
-
* @param {ArrayLike<number>} centre centre times, seconds, per band
|
|
124
|
-
* @param {number} d the line's delay, seconds
|
|
125
|
-
* @param {Float64Array} out the gain, linear; the low shelf and the high, dB
|
|
126
|
-
*/
|
|
127
|
-
function line_values(solve, centre, d, out) {
|
|
128
|
-
const t0 = -60 * d / (RT60_PER_CENTRE_TIME * centre[0]);
|
|
129
|
-
const t1 = -60 * d / (RT60_PER_CENTRE_TIME * centre[1]);
|
|
130
|
-
const t2 = -60 * d / (RT60_PER_CENTRE_TIME * centre[2]);
|
|
131
|
-
|
|
132
|
-
const gain = Math.min(0, solve[0] * t0 + solve[1] * t1 + solve[2] * t2);
|
|
133
|
-
|
|
134
|
-
out[0] = Math.pow(10, gain / 20);
|
|
135
|
-
out[1] = Math.min(-gain, solve[3] * t0 + solve[4] * t1 + solve[5] * t2);
|
|
136
|
-
out[2] = Math.min(-gain, solve[6] * t0 + solve[7] * t1 + solve[8] * t2);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
29
|
/** Scratch: the diffuse and directional gains on their way to the write rule. */
|
|
140
30
|
const SHARES = new Float64Array(2);
|
|
141
31
|
|
|
@@ -149,80 +39,44 @@ const DECAY_FIRST = 1;
|
|
|
149
39
|
const DECAY_MOVED = 2;
|
|
150
40
|
|
|
151
41
|
/**
|
|
152
|
-
*
|
|
42
|
+
* # The acoustic reverb
|
|
153
43
|
*
|
|
154
|
-
*
|
|
155
|
-
* @
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const a = m[0], b = m[1], c = m[2];
|
|
159
|
-
const d = m[3], e = m[4], f = m[5];
|
|
160
|
-
const g = m[6], h = m[7], i = m[8];
|
|
161
|
-
|
|
162
|
-
const A = e * i - f * h;
|
|
163
|
-
const B = f * g - d * i;
|
|
164
|
-
const C = d * h - e * g;
|
|
165
|
-
const inverse = 1 / (a * A + b * B + c * C);
|
|
166
|
-
|
|
167
|
-
out[0] = A * inverse;
|
|
168
|
-
out[1] = (c * h - b * i) * inverse;
|
|
169
|
-
out[2] = (b * f - c * e) * inverse;
|
|
170
|
-
out[3] = B * inverse;
|
|
171
|
-
out[4] = (a * i - c * g) * inverse;
|
|
172
|
-
out[5] = (c * d - a * f) * inverse;
|
|
173
|
-
out[6] = C * inverse;
|
|
174
|
-
out[7] = (b * g - a * h) * inverse;
|
|
175
|
-
out[8] = (a * e - b * d) * inverse;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* # The acoustic reverb: one feedback delay network
|
|
180
|
-
*
|
|
181
|
-
* GPU acoustics design, "The reverb: one feedback delay network" (F1, F4). The reverberant energy of every acoustic
|
|
182
|
-
* source sent to it, rendered with a decay per band that follows the simulation every frame without clicks, without
|
|
183
|
-
* allocation and without work off the audio thread: the decay is a set of `AudioParam`s.
|
|
44
|
+
* GPU acoustics design, "The reverb" (F1, F4). The reverberant energy of every acoustic source sent to it, played by a
|
|
45
|
+
* tank whose decay per band follows the senders: {@link AcousticReverbConvolution}, a decaying noise, as
|
|
46
|
+
* `AcousticReverbEffect` builds it, or {@link AcousticReverbLines}, a feedback delay network. What is here is the same
|
|
47
|
+
* for either: what the senders add up to, and the gains around the tank.
|
|
184
48
|
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* even lines as it is and to the odd ones inverted.
|
|
49
|
+
* A tank has an `input` the scaled send enters, a `stereo` pair (the diffuse share) and a `mono` sum uncorrelated
|
|
50
|
+
* with it (the directional share), the `shortest` centre time it plays, `send_gain(τ)`, the amplitude a band's send
|
|
51
|
+
* enters at for a tail of the energy sent, `set_decay(centre, sent, now, interval, resting)`, `update(now, interval)`
|
|
52
|
+
* once a frame, and `disconnect()`.
|
|
190
53
|
*
|
|
191
|
-
* **
|
|
192
|
-
*
|
|
193
|
-
* requested rate (`RT60 = 6 ln 10 · T_s`, {@link RT60_PER_CENTRE_TIME}). Jot and Chaigne's attenuation rule, here
|
|
194
|
-
* derived as stated rather than read from their paper. The three bands' per-pass gains are realised by the shelves
|
|
195
|
-
* and the gain together, solved at each band's centre ({@link ACOUSTIC_REVERB_BAND_CENTRES}) from the shelves'
|
|
196
|
-
* response there, which at a few dB scales with their gain: the decay is the requested one at those frequencies,
|
|
197
|
-
* and between them follows the shelves. Shelves, not a crossover, because a crossover's bands overshoot near its
|
|
198
|
-
* edges and a gain above one in a feedback loop runs away; a shelf's response lies between its two gains. The
|
|
199
|
-
* solution is held passive: no shelf lifts a band above the gain the others leave it.
|
|
54
|
+
* **Level.** What is sent is split by band (the 3-band split the instances' paths use) and scaled by the tank's
|
|
55
|
+
* `send_gain` at the band's `T_s`, so a send of energy `E` leaves a tail of energy `E` at any decay time.
|
|
200
56
|
*
|
|
201
|
-
* **
|
|
202
|
-
*
|
|
203
|
-
*
|
|
57
|
+
* **One decay for what is audible (F4).** Each frame the decay's `T_s` per band is the energy-weighted mean of the
|
|
58
|
+
* centre times of the sources sending to it, weighted by what each sends and how loud it plays ({@link accumulate}): a
|
|
59
|
+
* dry source sends nothing and has no say. A frame nothing was sent in keeps the decay it had.
|
|
204
60
|
*
|
|
205
|
-
* **
|
|
206
|
-
*
|
|
207
|
-
*
|
|
61
|
+
* **Lean.** The diffuse pair, and the mono sum played from the senders' aggregate direction through six speakers that
|
|
62
|
+
* stand still around the listener, by gains (`AcousticSpeakers`) — the directional share, the length of that
|
|
63
|
+
* direction, energy-weighted as the decay is. A panner moved after a direction estimated afresh each frame would carry
|
|
64
|
+
* the estimate's wander across the head; gains on panners that stand still carry it as a little level.
|
|
208
65
|
*
|
|
209
|
-
* **
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
66
|
+
* **Memory.** The tail rings with what it was sent for its decay time. That is right when a source goes quiet, and
|
|
67
|
+
* wrong when its send drops because the listener has left the room: the level heard there is the new send's now, not
|
|
68
|
+
* after the tail has decayed to it. So each source keeps a gain model of what its propagation has put in the tail,
|
|
69
|
+
* `Ê ← Ê·e^(−Δ/τ) + E·(1 − e^(−Δ/τ))` per band for its send `E` without its own loudness and the reverb's `τ`
|
|
70
|
+
* ({@link centre_time}), and hands it over with the send ({@link accumulate}). The output passes a correction of
|
|
71
|
+
* `√min(1, Σ ℓE / Σ ℓÊ)` per band over the senders heard, `ℓ` each one's loudness (the same 3-band split the input
|
|
72
|
+
* uses): a step down in what the propagation sends is heard at the next write, a step up is left to the tail, which
|
|
73
|
+
* builds from the signal as it would in a room. A source turned down, fading or stopping changes both sums alike, so
|
|
74
|
+
* what it put in the tail rings out and no other source's tail is corrected for it; a frame no source is heard in
|
|
75
|
+
* corrects nothing. Never above one: the correction loses energy, never invents it.
|
|
213
76
|
*
|
|
214
|
-
* **
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* `L ← L·e^(−Δ/τ) + S·(1 − e^(−Δ/τ))` per band for the frame's send `S` and the network's own `τ`, and its output
|
|
218
|
-
* passes a correction of `√min(1, S / L)` per band (the same 3-band split the input uses): a step down in what is
|
|
219
|
-
* sent is heard at the next write, a step up is left to the tail, which builds from the signal as it would in a
|
|
220
|
-
* room, and a frame nothing was sent in corrects nothing, so a source that stops rings out. Never above one: the
|
|
221
|
-
* correction loses energy, never invents it.
|
|
222
|
-
*
|
|
223
|
-
* **Writes** follow the acoustic render's rule (`acoustic_writes.js`): a decay is sent when a band's moved more than
|
|
224
|
-
* 2.5%, a gain more than half a decibel, the panner when its direction turned more than a degree, each as a ramp over
|
|
225
|
-
* the interval between updates; the first decay and the first placement at once.
|
|
77
|
+
* **Writes** follow the acoustic render's rule (`acoustic_writes.js`): a decay is asked of the tank when a band's moved
|
|
78
|
+
* more than 2.5%, a gain is sent when it moved more than half a decibel, the speakers' gains alike, each as a ramp over
|
|
79
|
+
* the interval between updates; the first decay and the first lean at once.
|
|
226
80
|
*/
|
|
227
81
|
export class AcousticReverbNetwork {
|
|
228
82
|
/**
|
|
@@ -243,39 +97,11 @@ export class AcousticReverbNetwork {
|
|
|
243
97
|
/** @type {{lowTap:GainNode, midTap:GainNode, dryTap:GainNode}} */
|
|
244
98
|
#input;
|
|
245
99
|
|
|
246
|
-
/** What the input taps sum into, and its inversion, which feed the even and the odd lines. */
|
|
247
|
-
#feed;
|
|
248
|
-
#inverted;
|
|
249
|
-
|
|
250
|
-
/** The lines' outputs summed, for the directional share. */
|
|
251
|
-
#mono;
|
|
252
|
-
|
|
253
|
-
/** Each side's lines heard inverted, left and right. */
|
|
254
|
-
#inverts = [];
|
|
255
|
-
|
|
256
100
|
/**
|
|
257
|
-
*
|
|
258
|
-
* @type {
|
|
101
|
+
* What plays the tail: its decay is set from the senders'. For inspection.
|
|
102
|
+
* @type {AcousticReverbConvolution|AcousticReverbLines}
|
|
259
103
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
/** @type {BiquadFilterNode[]} */
|
|
263
|
-
lowShelves = [];
|
|
264
|
-
|
|
265
|
-
/** @type {BiquadFilterNode[]} */
|
|
266
|
-
highShelves = [];
|
|
267
|
-
|
|
268
|
-
/** @type {GainNode[]} */
|
|
269
|
-
lineGains = [];
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* The Householder matrix's summing gain, `−2/N`. For inspection.
|
|
273
|
-
* @type {GainNode}
|
|
274
|
-
*/
|
|
275
|
-
householder;
|
|
276
|
-
|
|
277
|
-
/** @type {ChannelMergerNode} */
|
|
278
|
-
#stereo;
|
|
104
|
+
tank;
|
|
279
105
|
|
|
280
106
|
/** @type {GainNode} */
|
|
281
107
|
#diffuse;
|
|
@@ -283,20 +109,27 @@ export class AcousticReverbNetwork {
|
|
|
283
109
|
/** @type {GainNode} */
|
|
284
110
|
#directional;
|
|
285
111
|
|
|
286
|
-
/**
|
|
287
|
-
|
|
112
|
+
/**
|
|
113
|
+
* The six panners the directional share is played through, around the listener. For inspection.
|
|
114
|
+
* @type {AcousticSpeakers}
|
|
115
|
+
*/
|
|
116
|
+
speakers;
|
|
288
117
|
|
|
289
118
|
/**
|
|
290
|
-
* The
|
|
291
|
-
* @type {
|
|
119
|
+
* The directional sum into {@link speakers}, by the lean's direction. For inspection.
|
|
120
|
+
* @type {AcousticSpeakerFeed}
|
|
292
121
|
*/
|
|
293
|
-
|
|
122
|
+
leanFeed;
|
|
123
|
+
|
|
124
|
+
/** Whether a lean has been played yet: the first is written at once. */
|
|
125
|
+
#leaned = false;
|
|
294
126
|
|
|
295
127
|
/*
|
|
296
128
|
What the frame's senders have sent so far: energy per band, energy times centre time per band, and the
|
|
297
129
|
broadband energy times the direction.
|
|
298
130
|
*/
|
|
299
|
-
#
|
|
131
|
+
#say = new Float64Array(3);
|
|
132
|
+
#holding = new Float64Array(3);
|
|
300
133
|
#moment = new Float64Array(3);
|
|
301
134
|
#lean = new Float64Array(4);
|
|
302
135
|
|
|
@@ -318,20 +151,11 @@ export class AcousticReverbNetwork {
|
|
|
318
151
|
/** The diffuse and directional gains last sent. */
|
|
319
152
|
#sentShare = new Float64Array([1, 0]);
|
|
320
153
|
|
|
321
|
-
/** Where the panner was last placed; NaN before it was. */
|
|
322
|
-
#placed = new Float64Array([NaN, NaN, NaN]);
|
|
323
|
-
|
|
324
154
|
/** Scratch: the frame's centre times. */
|
|
325
155
|
#centre = new Float64Array(3);
|
|
326
156
|
|
|
327
|
-
/**
|
|
328
|
-
|
|
329
|
-
* send's.
|
|
330
|
-
*/
|
|
331
|
-
#held = new Float64Array(3);
|
|
332
|
-
|
|
333
|
-
/** When the last write to the lines and the input, the output, the shares and the panner arrives (`acoustic_resting`). */
|
|
334
|
-
#rampEnds = new Float64Array(4);
|
|
157
|
+
/** When the last write to the tank and the input, the output and the shares arrives (`acoustic_resting`). */
|
|
158
|
+
#rampEnds = new Float64Array(3);
|
|
335
159
|
|
|
336
160
|
/** The output correction per band last sent; 1 is none. */
|
|
337
161
|
#sentOutput = new Float64Array([1, 1, 1]);
|
|
@@ -358,98 +182,16 @@ export class AcousticReverbNetwork {
|
|
|
358
182
|
|
|
359
183
|
/**
|
|
360
184
|
* @param {BaseAudioContext} ctx
|
|
185
|
+
* @param {AcousticReverbConvolution|AcousticReverbLines} tank what plays the tail, made on `ctx`
|
|
361
186
|
*/
|
|
362
|
-
constructor(ctx) {
|
|
363
|
-
const N = ACOUSTIC_REVERB_LINES;
|
|
364
|
-
|
|
187
|
+
constructor(ctx, tank) {
|
|
365
188
|
this.output = ctx.createGain();
|
|
366
189
|
this.side = ctx.createGain();
|
|
190
|
+
this.tank = tank;
|
|
367
191
|
|
|
368
192
|
// what is sent, split by band and scaled to the decay; silent until something has been sent
|
|
369
193
|
this.#split = build3BandSplit(ctx, this.side);
|
|
370
|
-
|
|
371
|
-
const feed = ctx.createGain();
|
|
372
|
-
const inverted = ctx.createGain();
|
|
373
|
-
|
|
374
|
-
inverted.gain.setValueAtTime(-1, 0);
|
|
375
|
-
feed.connect(inverted);
|
|
376
|
-
|
|
377
|
-
this.#feed = feed;
|
|
378
|
-
this.#inverted = inverted;
|
|
379
|
-
|
|
380
|
-
this.#input = build3BandTaps(ctx, this.#split, feed);
|
|
381
|
-
|
|
382
|
-
const householder = ctx.createGain();
|
|
383
|
-
|
|
384
|
-
householder.gain.setValueAtTime(-2 / N, 0);
|
|
385
|
-
this.householder = householder;
|
|
386
|
-
|
|
387
|
-
const stereo = ctx.createChannelMerger(2);
|
|
388
|
-
const mono = ctx.createGain();
|
|
389
|
-
|
|
390
|
-
this.#mono = mono;
|
|
391
|
-
|
|
392
|
-
for (let side = 0; side < 2; side++) {
|
|
393
|
-
const invert = ctx.createGain();
|
|
394
|
-
|
|
395
|
-
invert.gain.setValueAtTime(-1, 0);
|
|
396
|
-
invert.connect(stereo, 0, side);
|
|
397
|
-
invert.connect(mono);
|
|
398
|
-
|
|
399
|
-
this.#inverts.push(invert);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
for (let i = 0; i < N; i++) {
|
|
403
|
-
const delay = ctx.createDelay(ACOUSTIC_REVERB_DELAYS[i]);
|
|
404
|
-
|
|
405
|
-
delay.delayTime.setValueAtTime(ACOUSTIC_REVERB_DELAYS[i], 0);
|
|
406
|
-
|
|
407
|
-
const low = ctx.createBiquadFilter();
|
|
408
|
-
|
|
409
|
-
low.type = 'lowshelf';
|
|
410
|
-
low.frequency.setValueAtTime(LOW_MID_HZ, 0);
|
|
411
|
-
low.gain.setValueAtTime(0, 0);
|
|
412
|
-
|
|
413
|
-
const high = ctx.createBiquadFilter();
|
|
414
|
-
|
|
415
|
-
high.type = 'highshelf';
|
|
416
|
-
high.frequency.setValueAtTime(MID_HIGH_HZ, 0);
|
|
417
|
-
high.gain.setValueAtTime(0, 0);
|
|
418
|
-
|
|
419
|
-
// silent until the first decay is sent: nothing circulates before it
|
|
420
|
-
const gain = ctx.createGain();
|
|
421
|
-
|
|
422
|
-
gain.gain.setValueAtTime(0, 0);
|
|
423
|
-
|
|
424
|
-
(i % 2 === 0 ? feed : inverted).connect(delay);
|
|
425
|
-
|
|
426
|
-
delay.connect(low);
|
|
427
|
-
low.connect(high);
|
|
428
|
-
high.connect(gain);
|
|
429
|
-
|
|
430
|
-
// the Householder matrix: the line's own share whole, every line's through the summing gain
|
|
431
|
-
gain.connect(delay);
|
|
432
|
-
gain.connect(householder);
|
|
433
|
-
|
|
434
|
-
// the even lines left, the odd right, each with its sign; all of them to the directional sum
|
|
435
|
-
if (ACOUSTIC_REVERB_OUTPUT_SIGNS[i] > 0) {
|
|
436
|
-
delay.connect(stereo, 0, i % 2);
|
|
437
|
-
delay.connect(mono);
|
|
438
|
-
} else {
|
|
439
|
-
delay.connect(this.#inverts[i % 2]);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
this.delays.push(delay);
|
|
443
|
-
this.lowShelves.push(low);
|
|
444
|
-
this.highShelves.push(high);
|
|
445
|
-
this.lineGains.push(gain);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
for (let i = 0; i < N; i++) {
|
|
449
|
-
householder.connect(this.delays[i]);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
this.#stereo = stereo;
|
|
194
|
+
this.#input = build3BandTaps(ctx, this.#split, tank.input);
|
|
453
195
|
|
|
454
196
|
const diffuse = ctx.createGain();
|
|
455
197
|
|
|
@@ -461,65 +203,46 @@ export class AcousticReverbNetwork {
|
|
|
461
203
|
set3BandGains(this.#outputTaps, 1, 1, 1, 0);
|
|
462
204
|
|
|
463
205
|
diffuse.gain.setValueAtTime(1, 0);
|
|
464
|
-
stereo.connect(diffuse);
|
|
206
|
+
tank.stereo.connect(diffuse);
|
|
465
207
|
diffuse.connect(tail);
|
|
466
208
|
this.#diffuse = diffuse;
|
|
467
209
|
|
|
468
210
|
const directional = ctx.createGain();
|
|
469
211
|
|
|
470
212
|
directional.gain.setValueAtTime(0, 0);
|
|
471
|
-
mono.connect(directional);
|
|
213
|
+
tank.mono.connect(directional);
|
|
472
214
|
this.#directional = directional;
|
|
473
215
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
panner.rolloffFactor = 0;
|
|
478
|
-
directional.connect(panner);
|
|
479
|
-
panner.connect(tail);
|
|
480
|
-
this.panner = panner;
|
|
481
|
-
|
|
482
|
-
this.#calibrate(ctx.sampleRate);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* The shelves' response at the band centres, as a share of their gain, at this sample rate: the matrix a line's
|
|
487
|
-
* targets are solved through.
|
|
488
|
-
*
|
|
489
|
-
* @param {number} sample_rate
|
|
490
|
-
*/
|
|
491
|
-
#calibrate(sample_rate) {
|
|
492
|
-
const m = new Float64Array(9);
|
|
493
|
-
|
|
494
|
-
for (let k = 0; k < 3; k++) {
|
|
495
|
-
const f = ACOUSTIC_REVERB_BAND_CENTRES[k];
|
|
496
|
-
|
|
497
|
-
m[3 * k] = 1;
|
|
498
|
-
m[3 * k + 1] = biquad_magnitude_db(biquad_shelf_coefficients(COEFFICIENTS, false, LOW_MID_HZ, CALIBRATION_DB, sample_rate), f, sample_rate) / CALIBRATION_DB;
|
|
499
|
-
m[3 * k + 2] = biquad_magnitude_db(biquad_shelf_coefficients(COEFFICIENTS, true, MID_HIGH_HZ, CALIBRATION_DB, sample_rate), f, sample_rate) / CALIBRATION_DB;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
invert3(m, this.#solve);
|
|
216
|
+
// equal-power: the lean weighs the tail between the sides; it carries no ears' filters
|
|
217
|
+
this.speakers = new AcousticSpeakers(ctx, tail, 'equalpower');
|
|
218
|
+
this.leanFeed = new AcousticSpeakerFeed(ctx, directional, this.speakers);
|
|
503
219
|
}
|
|
504
220
|
|
|
505
221
|
/**
|
|
506
|
-
* A source's reverberant send this frame:
|
|
507
|
-
* distance gain squared times what its wet taps carry), with its centre time per band and its lean
|
|
222
|
+
* A source's reverberant send this frame: its energy per band as its propagation and its distance make it (the
|
|
223
|
+
* instance's distance gain squared times what its wet taps carry), with its centre time per band and its lean, and
|
|
224
|
+
* how loud the source itself plays, `loudness`, its level squared, 0 while it plays no voice; and what its
|
|
225
|
+
* propagation has put in the tail by its own model, `held` (**Memory**). The energy times the loudness is the
|
|
226
|
+
* source's say in the decay, the lean and the correction, as much as it is heard.
|
|
508
227
|
*
|
|
509
228
|
* @param {ArrayLike<number>} energy per band
|
|
510
229
|
* @param {ArrayLike<number>} centre_time seconds, per band
|
|
511
230
|
* @param {ArrayLike<number>} direction a vector of length at most 1
|
|
231
|
+
* @param {number} loudness at least 0
|
|
232
|
+
* @param {ArrayLike<number>} held per band
|
|
512
233
|
*/
|
|
513
|
-
accumulate(energy, centre_time, direction) {
|
|
514
|
-
const
|
|
234
|
+
accumulate(energy, centre_time, direction, loudness, held = energy) {
|
|
235
|
+
const say = this.#say;
|
|
236
|
+
const holding = this.#holding;
|
|
515
237
|
const moment = this.#moment;
|
|
516
238
|
|
|
517
239
|
for (let b = 0; b < 3; b++) {
|
|
518
|
-
|
|
519
|
-
|
|
240
|
+
say[b] += energy[b] * loudness;
|
|
241
|
+
holding[b] += held[b] * loudness;
|
|
242
|
+
moment[b] += energy[b] * loudness * centre_time[b];
|
|
520
243
|
}
|
|
521
244
|
|
|
522
|
-
const broadband = (energy[0] + energy[1] + energy[2]) / 3;
|
|
245
|
+
const broadband = loudness * (energy[0] + energy[1] + energy[2]) / 3;
|
|
523
246
|
const lean = this.#lean;
|
|
524
247
|
|
|
525
248
|
lean[0] += broadband * direction[0];
|
|
@@ -531,10 +254,12 @@ export class AcousticReverbNetwork {
|
|
|
531
254
|
|
|
532
255
|
/**
|
|
533
256
|
* Take the frame's senders: the decay and the lean they add up to, written as the rule says, and nothing kept
|
|
534
|
-
* for the next frame
|
|
257
|
+
* for the next frame; and, once there is a lean to hear, stand the speakers around the listener, where the tail is
|
|
258
|
+
* heard from whether or not anything was sent. A frame nothing was sent in writes nothing else, and before the
|
|
259
|
+
* first lean nothing at all.
|
|
535
260
|
*
|
|
536
261
|
* @param {number} now context time
|
|
537
|
-
* @param {ArrayLike<number>|null} listener world position,
|
|
262
|
+
* @param {ArrayLike<number>|null} listener world position, what the speakers stand around
|
|
538
263
|
*/
|
|
539
264
|
update(now, listener) {
|
|
540
265
|
// the interval between updates, what a write ramps over (`acoustic_ramp`): measured here, not handed in,
|
|
@@ -547,27 +272,32 @@ export class AcousticReverbNetwork {
|
|
|
547
272
|
this.#lastGap = gap;
|
|
548
273
|
this.#lastUpdate = now;
|
|
549
274
|
|
|
550
|
-
const
|
|
275
|
+
const say = this.#say;
|
|
551
276
|
const moment = this.#moment;
|
|
552
|
-
const sent =
|
|
277
|
+
const sent = say[0] + say[1] + say[2] > 0;
|
|
278
|
+
|
|
279
|
+
if (sent || this.#leaned) {
|
|
280
|
+
this.speakers.follow(now, listener);
|
|
281
|
+
}
|
|
553
282
|
|
|
554
283
|
if (sent) {
|
|
555
284
|
const centre = this.#centre;
|
|
556
|
-
const shortest =
|
|
285
|
+
const shortest = this.tank.shortest;
|
|
557
286
|
|
|
558
287
|
for (let b = 0; b < 3; b++) {
|
|
559
|
-
// a band no sender put energy in keeps its decay; none shorter than the
|
|
560
|
-
|
|
561
|
-
centre[b] = weight[b] > 0 ? Math.max(shortest, moment[b] / weight[b]) : this.#sentCentre[b];
|
|
288
|
+
// a band no heard sender put energy in keeps its decay; none shorter than the tank can play
|
|
289
|
+
centre[b] = say[b] > 0 ? Math.max(shortest, moment[b] / say[b]) : this.#sentCentre[b];
|
|
562
290
|
}
|
|
563
291
|
|
|
564
292
|
this.#send_decay(now);
|
|
565
|
-
this.#send_lean(now
|
|
293
|
+
this.#send_lean(now);
|
|
566
294
|
}
|
|
567
295
|
|
|
568
296
|
this.#hold(sent);
|
|
297
|
+
this.tank.update(now, this.#interval);
|
|
569
298
|
|
|
570
|
-
|
|
299
|
+
say.fill(0);
|
|
300
|
+
this.#holding.fill(0);
|
|
571
301
|
moment.fill(0);
|
|
572
302
|
this.#lean.fill(0);
|
|
573
303
|
|
|
@@ -580,6 +310,15 @@ export class AcousticReverbNetwork {
|
|
|
580
310
|
* is solved.
|
|
581
311
|
* @returns {number}
|
|
582
312
|
*/
|
|
313
|
+
/**
|
|
314
|
+
* The decay the network plays, as centre times per band, seconds: what a sender's model of what it holds decays
|
|
315
|
+
* by (**Memory**). NaN in a band no decay has been sent for yet.
|
|
316
|
+
* @returns {Float64Array}
|
|
317
|
+
*/
|
|
318
|
+
get centre_time() {
|
|
319
|
+
return this.#sentCentre;
|
|
320
|
+
}
|
|
321
|
+
|
|
583
322
|
get epoch() {
|
|
584
323
|
return this.#epoch;
|
|
585
324
|
}
|
|
@@ -590,18 +329,22 @@ export class AcousticReverbNetwork {
|
|
|
590
329
|
* @param {ArrayLike<number>} energy per band
|
|
591
330
|
* @param {ArrayLike<number>} centre_time seconds, per band
|
|
592
331
|
* @param {ArrayLike<number>} direction a vector of length at most 1
|
|
332
|
+
* @param {number} loudness
|
|
333
|
+
* @param {ArrayLike<number>} held
|
|
593
334
|
*/
|
|
594
|
-
retract(energy, centre_time, direction) {
|
|
595
|
-
const
|
|
335
|
+
retract(energy, centre_time, direction, loudness, held = energy) {
|
|
336
|
+
const say = this.#say;
|
|
337
|
+
const holding = this.#holding;
|
|
596
338
|
const moment = this.#moment;
|
|
597
339
|
|
|
598
340
|
for (let b = 0; b < 3; b++) {
|
|
599
341
|
// what rounding leaves of a send taken back is nothing sent
|
|
600
|
-
|
|
601
|
-
|
|
342
|
+
say[b] = Math.max(0, say[b] - energy[b] * loudness);
|
|
343
|
+
holding[b] = Math.max(0, holding[b] - held[b] * loudness);
|
|
344
|
+
moment[b] = Math.max(0, moment[b] - energy[b] * loudness * centre_time[b]);
|
|
602
345
|
}
|
|
603
346
|
|
|
604
|
-
const broadband = (energy[0] + energy[1] + energy[2]) / 3;
|
|
347
|
+
const broadband = loudness * (energy[0] + energy[1] + energy[2]) / 3;
|
|
605
348
|
const lean = this.#lean;
|
|
606
349
|
|
|
607
350
|
lean[0] -= broadband * direction[0];
|
|
@@ -612,37 +355,23 @@ export class AcousticReverbNetwork {
|
|
|
612
355
|
}
|
|
613
356
|
|
|
614
357
|
/**
|
|
615
|
-
*
|
|
616
|
-
*
|
|
358
|
+
* Send the output correction the frame's senders call for (**Memory**), if the rule says to. Kept apart from the
|
|
359
|
+
* writes, as the decay's check is, and handed no number.
|
|
617
360
|
*
|
|
618
361
|
* @param {boolean} sent whether anything was sent this frame
|
|
619
362
|
*/
|
|
620
363
|
#hold(sent) {
|
|
621
|
-
const held = this.#held;
|
|
622
|
-
const weight = this.#weight;
|
|
623
|
-
const decay = this.#sentCentre;
|
|
624
|
-
const interval = this.#lastGap;
|
|
625
|
-
|
|
626
|
-
for (let b = 0; b < 3; b++) {
|
|
627
|
-
const tau = decay[b];
|
|
628
|
-
|
|
629
|
-
// no decay yet, nothing held
|
|
630
|
-
if (tau > 0) {
|
|
631
|
-
const keep = Math.exp(-interval / tau);
|
|
632
|
-
|
|
633
|
-
held[b] = held[b] * keep + weight[b] * (1 - keep);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
364
|
if (!sent) {
|
|
638
|
-
//
|
|
365
|
+
// no source heard: what is in the tail rings out, nothing to correct toward
|
|
639
366
|
return;
|
|
640
367
|
}
|
|
641
368
|
|
|
369
|
+
const say = this.#say;
|
|
370
|
+
const holding = this.#holding;
|
|
642
371
|
const output = this.#output;
|
|
643
372
|
|
|
644
373
|
for (let b = 0; b < 3; b++) {
|
|
645
|
-
output[b] =
|
|
374
|
+
output[b] = holding[b] > 0 ? Math.sqrt(Math.min(1, say[b] / holding[b])) : 1;
|
|
646
375
|
}
|
|
647
376
|
|
|
648
377
|
if (acoustic_gains_moved(this.#sentOutput, output, 3)) {
|
|
@@ -710,45 +439,27 @@ export class AcousticReverbNetwork {
|
|
|
710
439
|
#write_decay(now, first) {
|
|
711
440
|
const centre = this.#centre;
|
|
712
441
|
const sent = this.#sentCentre;
|
|
713
|
-
const
|
|
442
|
+
const tank = this.tank;
|
|
714
443
|
const interval = first ? 0 : this.#interval;
|
|
715
444
|
|
|
716
|
-
// where the
|
|
445
|
+
// where the tank and the input rest, if their last write has arrived: at what the centre times last sent set
|
|
717
446
|
const resting = acoustic_resting(this.#rampEnds, RAMP_DECAY, now, interval) && !first;
|
|
718
447
|
|
|
719
|
-
|
|
720
|
-
const d = ACOUSTIC_REVERB_DELAYS[i];
|
|
448
|
+
tank.set_decay(centre, sent, now, interval, resting);
|
|
721
449
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
RESTS.fill(NaN);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
line_values(solve, centre, d, VALUES);
|
|
729
|
-
|
|
730
|
-
if (first) {
|
|
731
|
-
this.lineGains[i].gain.setValueAtTime(VALUES[0], now);
|
|
732
|
-
this.lowShelves[i].gain.setValueAtTime(VALUES[1], now);
|
|
733
|
-
this.highShelves[i].gain.setValueAtTime(VALUES[2], now);
|
|
734
|
-
} else {
|
|
735
|
-
acoustic_ramp(this.lineGains[i].gain, VALUES[0], now, interval, RESTS[0]);
|
|
736
|
-
acoustic_ramp(this.lowShelves[i].gain, VALUES[1], now, interval, RESTS[1]);
|
|
737
|
-
acoustic_ramp(this.highShelves[i].gain, VALUES[2], now, interval, RESTS[2]);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
const gLow = 1 / Math.sqrt(acoustic_reverb_tail_energy(centre[0]));
|
|
742
|
-
const gMid = 1 / Math.sqrt(acoustic_reverb_tail_energy(centre[1]));
|
|
743
|
-
const gHigh = 1 / Math.sqrt(acoustic_reverb_tail_energy(centre[2]));
|
|
450
|
+
const gLow = tank.send_gain(centre[0]);
|
|
451
|
+
const gMid = tank.send_gain(centre[1]);
|
|
452
|
+
const gHigh = tank.send_gain(centre[2]);
|
|
744
453
|
|
|
745
454
|
if (first) {
|
|
746
455
|
set3BandGains(this.#input, gLow, gMid, gHigh, now);
|
|
747
456
|
} else {
|
|
748
457
|
if (resting) {
|
|
749
|
-
RESTS[0] =
|
|
750
|
-
RESTS[1] =
|
|
751
|
-
RESTS[2] =
|
|
458
|
+
RESTS[0] = tank.send_gain(sent[0]);
|
|
459
|
+
RESTS[1] = tank.send_gain(sent[1]);
|
|
460
|
+
RESTS[2] = tank.send_gain(sent[2]);
|
|
461
|
+
} else {
|
|
462
|
+
RESTS.fill(NaN);
|
|
752
463
|
}
|
|
753
464
|
|
|
754
465
|
ramp3BandGains(this.#input, gLow, gMid, gHigh, now, interval, RESTS, resting);
|
|
@@ -760,10 +471,11 @@ export class AcousticReverbNetwork {
|
|
|
760
471
|
}
|
|
761
472
|
|
|
762
473
|
/**
|
|
474
|
+
* The frame's lean: its share and the rest as gains, and its direction into the speakers.
|
|
475
|
+
*
|
|
763
476
|
* @param {number} now
|
|
764
|
-
* @param {ArrayLike<number>|null} listener
|
|
765
477
|
*/
|
|
766
|
-
#send_lean(now
|
|
478
|
+
#send_lean(now) {
|
|
767
479
|
const lean = this.#lean;
|
|
768
480
|
const total = lean[3];
|
|
769
481
|
|
|
@@ -794,62 +506,14 @@ export class AcousticReverbNetwork {
|
|
|
794
506
|
sent[1] = shares[1];
|
|
795
507
|
}
|
|
796
508
|
|
|
797
|
-
if (share > 0
|
|
798
|
-
TOWARD[0] = x
|
|
799
|
-
TOWARD[1] = y
|
|
800
|
-
TOWARD[2] = z
|
|
801
|
-
|
|
802
|
-
this.#aim(now, listener, TOWARD);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Place the panner a metre from the listener along a unit direction, unless the direction it is heard from now is
|
|
808
|
-
* within a degree of it.
|
|
809
|
-
*
|
|
810
|
-
* @param {number} now
|
|
811
|
-
* @param {ArrayLike<number>} listener
|
|
812
|
-
* @param {Float64Array} toward unit length
|
|
813
|
-
*/
|
|
814
|
-
#aim(now, listener, toward) {
|
|
815
|
-
const ux = toward[0];
|
|
816
|
-
const uy = toward[1];
|
|
817
|
-
const uz = toward[2];
|
|
818
|
-
|
|
819
|
-
const placed = this.#placed;
|
|
820
|
-
const first = Number.isNaN(placed[0]);
|
|
821
|
-
|
|
822
|
-
if (!first) {
|
|
823
|
-
const hx = placed[0] - listener[0];
|
|
824
|
-
const hy = placed[1] - listener[1];
|
|
825
|
-
const hz = placed[2] - listener[2];
|
|
826
|
-
const heard = Math.sqrt(hx * hx + hy * hy + hz * hz);
|
|
827
|
-
|
|
828
|
-
if (heard > 0 && (hx * ux + hy * uy + hz * uz) >= ACOUSTIC_DIRECTION_DEADBAND * heard) {
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
const x = listener[0] + ux;
|
|
834
|
-
const y = listener[1] + uy;
|
|
835
|
-
const z = listener[2] + uz;
|
|
836
|
-
const panner = this.panner;
|
|
509
|
+
if (share > 0) {
|
|
510
|
+
TOWARD[0] = x;
|
|
511
|
+
TOWARD[1] = y;
|
|
512
|
+
TOWARD[2] = z;
|
|
837
513
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
panner.positionY.setValueAtTime(y, now);
|
|
841
|
-
panner.positionZ.setValueAtTime(z, now);
|
|
842
|
-
} else {
|
|
843
|
-
const resting = acoustic_resting(this.#rampEnds, RAMP_PANNER, now, this.#interval);
|
|
844
|
-
|
|
845
|
-
acoustic_ramp(panner.positionX, x, now, this.#interval, resting ? placed[0] : NaN);
|
|
846
|
-
acoustic_ramp(panner.positionY, y, now, this.#interval, resting ? placed[1] : NaN);
|
|
847
|
-
acoustic_ramp(panner.positionZ, z, now, this.#interval, resting ? placed[2] : NaN);
|
|
514
|
+
this.leanFeed.aim(TOWARD, now, this.#leaned ? this.#interval : 0);
|
|
515
|
+
this.#leaned = true;
|
|
848
516
|
}
|
|
849
|
-
|
|
850
|
-
placed[0] = x;
|
|
851
|
-
placed[1] = y;
|
|
852
|
-
placed[2] = z;
|
|
853
517
|
}
|
|
854
518
|
|
|
855
519
|
/**
|
|
@@ -862,24 +526,12 @@ export class AcousticReverbNetwork {
|
|
|
862
526
|
this.#input.lowTap.disconnect();
|
|
863
527
|
this.#input.midTap.disconnect();
|
|
864
528
|
this.#input.dryTap.disconnect();
|
|
865
|
-
this
|
|
866
|
-
this.#inverted.disconnect();
|
|
867
|
-
this.#mono.disconnect();
|
|
868
|
-
this.#inverts[0].disconnect();
|
|
869
|
-
this.#inverts[1].disconnect();
|
|
870
|
-
|
|
871
|
-
for (let i = 0; i < ACOUSTIC_REVERB_LINES; i++) {
|
|
872
|
-
this.delays[i].disconnect();
|
|
873
|
-
this.lowShelves[i].disconnect();
|
|
874
|
-
this.highShelves[i].disconnect();
|
|
875
|
-
this.lineGains[i].disconnect();
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
this.householder.disconnect();
|
|
879
|
-
this.#stereo.disconnect();
|
|
529
|
+
this.tank.disconnect();
|
|
880
530
|
this.#diffuse.disconnect();
|
|
881
531
|
this.#directional.disconnect();
|
|
882
|
-
this.
|
|
532
|
+
this.leanFeed.disconnect();
|
|
533
|
+
this.speakers.disconnect();
|
|
534
|
+
this.tail.disconnect();
|
|
883
535
|
this.output.disconnect();
|
|
884
536
|
}
|
|
885
537
|
}
|