summaryrefslogtreecommitdiff
path: root/client/lib/hall.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/lib/hall.js')
-rw-r--r--client/lib/hall.js68
1 files changed, 48 insertions, 20 deletions
diff --git a/client/lib/hall.js b/client/lib/hall.js
index b1fa699..6ac6c7c 100644
--- a/client/lib/hall.js
+++ b/client/lib/hall.js
@@ -4,8 +4,13 @@ import { clamp, choice } from './util'
const SPEED_OF_SOUND = 0.0029154519 // ms/m
-const reverb = new Tone.Freeverb({
- roomSize: 0.8,
+const farReverb = new Tone.Freeverb({
+ roomSize: 0.5,
+ dampening: 6000,
+}).connect(output)
+
+const nearReverb = new Tone.Freeverb({
+ roomSize: 0.2,
dampening: 12000,
}).connect(output)
@@ -44,16 +49,51 @@ class Hall {
class Speaker {
constructor(props){
- const z = props.length * (props.i + 0.5) / props.speakers + 3
- const reverb_z = props.length * (props.i + 0.5 + props.speakers - 4) / props.speakers
+ this.z = props.length * (props.i + 0.5) / props.speakers
+ this.x = 3
+
+ this.input = new Tone.Gain()
+
+ this.panLeft = new Tone.Panner3D()
+ this.panLeft.updatePosition({
+ position: { x: this.x, y: 0, z: this.z }
+ })
+ this.panRight = new Tone.Panner3D()
+ this.panRight.updatePosition({
+ position: { x: -this.x, y: 0, z: this.z }
+ })
+
+ this.dryOutput = new Tone.Gain ()
+ this.nearOutput = new Tone.Gain ()
+ this.farOutput = new Tone.Gain ()
+
+ this.panLeft.connect(this.dryOutput)
+ this.panLeft.connect(this.nearOutput)
+ this.panLeft.connect(this.farOutput)
+ this.panRight.connect(this.dryOutput)
+ this.panRight.connect(this.nearOutput)
+ this.panRight.connect(this.farOutput)
+
+ this.input.connect(this.dryOutput)
+ this.input.connect(this.nearOutput)
+ this.input.connect(this.farOutput)
+
+ this.dryOutput.connect(output)
+ this.nearOutput.connect(nearReverb)
+ this.farOutput.connect(farReverb)
+
+ reposition(props)
+ }
+ reposition(props){
+ const reverb_z = props.length * (1 + ((props.i + 0.5) / props.speakers))
const z_db = db_per_meter(z)
const reverb_db = db_per_meter(reverb_z)
this.z = z
this.pan = Math.atan(3/this.z)
- this.panLeft = new Tone.Panner(-this.pan)
- this.panRight = new Tone.Panner(-this.pan)
+ this.panLeft.pan.value = -this.pan
+ this.panRight.pan.value = this.pan
this.gain = db_to_percentage(z_db + 8)
this.reverbGain = db_to_percentage(reverb_db + 15)
@@ -61,20 +101,8 @@ class Speaker {
this.delay = z * SPEED_OF_SOUND
console.log(z, this.gain.toFixed(4), this.reverbGain.toFixed(4), this.pan)
- this.input = new Tone.Delay(this.delay)
- this.dryOutput = new Tone.Gain (this.gain)
- this.wetOutput = new Tone.Gain (this.reverbGain)
-
- this.panLeft.connect(this.dryOutput)
- this.panLeft.connect(this.wetOutput)
- this.panRight.connect(this.dryOutput)
- this.panRight.connect(this.wetOutput)
-
- this.input.connect(this.dryOutput)
- this.input.connect(this.wetOutput)
-
- this.dryOutput.connect(output)
- this.wetOutput.connect(reverb)
+ this.dryOutput.gain.value = this.gain
+ this.wetOutput.gain.value = this.reverbGain
}
}