manual gain calculations attempt 1

This commit is contained in:
Aubrey 2024-12-23 04:23:55 -06:00
parent c76027bb84
commit e35e5ae2fe
No known key found for this signature in database

View file

@ -38,7 +38,7 @@ export class AudioManager {
panner.maxDistance = 2500; panner.maxDistance = 2500;
const gain = this.ac.createGain(); const gain = this.ac.createGain();
const dest = this.ac.createMediaStreamDestination(); const dest = this.ac.createMediaStreamDestination();
gain.connect(panner).connect(dest); gain.connect(dest); //.connect(panner)
let audio = document.createElement("audio"); let audio = document.createElement("audio");
audio.srcObject = dest.stream; audio.srcObject = dest.stream;
@ -76,10 +76,13 @@ export class PlayerAudio {
}); });
this.playerWatcher.subscribe(([[x, y, z], sameStage]) => { this.playerWatcher.subscribe(([[x, y, z], sameStage]) => {
this.panner.positionX.value = x; // this.panner.positionX.value = x;
this.panner.positionY.value = y; // this.panner.positionY.value = y;
this.panner.positionZ.value = z; // this.panner.positionZ.value = z;
this.gain.gain.value = +sameStage; 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;
}); });
} }