Skip to content
Snippets Groups Projects
Commit d967c3e6 authored by Marshall Quander's avatar Marshall Quander
Browse files

Fix Safari incompatibility with audio feedback

parent 3ecb7340
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ AFRAME.registerComponent("networked-audio-analyser", {
const ctx = THREE.AudioContext.getContext();
this.analyser = ctx.createAnalyser();
this.analyser.fftSize = 32;
this.levels = new Float32Array(this.analyser.frequencyBinCount);
this.levels = new Uint8Array(this.analyser.frequencyBinCount);
event.detail.soundSource.connect(this.analyser);
});
},
......@@ -20,11 +20,12 @@ AFRAME.registerComponent("networked-audio-analyser", {
tick: function() {
if (!this.analyser) return;
this.analyser.getFloatTimeDomainData(this.levels);
// take care with compatibility, e.g. safari doesn't support getFloatTimeDomainData
this.analyser.getByteTimeDomainData(this.levels);
let sum = 0;
for (let i = 0; i < this.levels.length; i++) {
const amplitude = this.levels[i];
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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment