From e35e5ae2fe3e67f9a3bb2e398313bff9ffea1519 Mon Sep 17 00:00:00 2001 From: Aubrey Taylor Date: Mon, 23 Dec 2024 04:23:55 -0600 Subject: [PATCH] manual gain calculations attempt 1 --- src/lib/audio.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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; }); }