diff --git a/src/lib/audio.ts b/src/lib/audio.ts index 382d4a6..09fd687 100644 --- a/src/lib/audio.ts +++ b/src/lib/audio.ts @@ -38,7 +38,7 @@ export class AudioManager { panner.maxDistance = 2500; const gain = this.ac.createGain(); const dest = this.ac.createMediaStreamDestination(); - gain.connect(panner).connect(dest); + gain.connect(dest); //.connect(panner) let audio = document.createElement("audio"); audio.srcObject = dest.stream; @@ -76,10 +76,13 @@ export class PlayerAudio { }); this.playerWatcher.subscribe(([[x, y, z], sameStage]) => { - this.panner.positionX.value = x; - this.panner.positionY.value = y; - this.panner.positionZ.value = z; - this.gain.gain.value = +sameStage; + // this.panner.positionX.value = x; + // this.panner.positionY.value = y; + // this.panner.positionZ.value = z; + let magnitude = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)); + const max = 2500, min = 1500; + let scaledGain = 1 - (magnitude - min) / max; + this.gain.gain.value = scaledGain * +sameStage; }); }