From 00abae2a05dd72e5e7f7ddc34db080ff6abc2580 Mon Sep 17 00:00:00 2001 From: Marshall Quander <marshall@quander.me> Date: Mon, 30 Jul 2018 18:12:57 -0700 Subject: [PATCH] Reduce head jitteriness --- src/components/audio-feedback.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/audio-feedback.js b/src/components/audio-feedback.js index b50980b86..71798ba4e 100644 --- a/src/components/audio-feedback.js +++ b/src/components/audio-feedback.js @@ -8,6 +8,7 @@ AFRAME.registerComponent("networked-audio-analyser", { this.volume = 0; this.prevVolume = 0; this.smoothing = 0.3; + this.threshold = 0.01; this.el.addEventListener("sound-source-set", event => { const ctx = THREE.AudioContext.getContext(); this.analyser = ctx.createAnalyser(); @@ -28,7 +29,11 @@ AFRAME.registerComponent("networked-audio-analyser", { const amplitude = (this.levels[i] - 128) / 128; sum += amplitude * amplitude; } - this.volume = this.smoothing * Math.sqrt(sum / this.levels.length) + (1 - this.smoothing) * this.prevVolume; + let currVolume = Math.sqrt(sum / this.levels.length); + if (currVolume < this.threshold) { + currVolume = 0; + } + this.volume = this.smoothing * currVolume + (1 - this.smoothing) * this.prevVolume; this.prevVolume = this.volume; } }); -- GitLab